416DAT

Check-in [fe80663b77]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Added README, YCSB Client, and some graph generation files
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:fe80663b77c6fa033d5c708d6fdf6e8eaf486aa6
User & Date: jfang 2013-04-09 06:16:48
Context
2013-04-09
06:29
Added masterThroughput.html check-in: 4c2708d0ab user: jfang tags: trunk
06:25
Added webpage, couchClient.java, ruby scripts check-in: 713aa0ce75 user: jchezenko tags: trunk
06:16
Added README, YCSB Client, and some graph generation files check-in: fe80663b77 user: jfang tags: trunk
06:01
Adding MongoDbClient check-in: 30c89d9f2b user: ekrell tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Added Jenny/Client.java.



















































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
/**                                                                                                                                                                                
 * Copyright (c) 2010 Yahoo! Inc. All rights reserved.                                                                                                                             
 *                                                                                                                                                                                 
 * Licensed under the Apache License, Version 2.0 (the "License"); you                                                                                                             
 * may not use this file except in compliance with the License. You                                                                                                                
 * may obtain a copy of the License at                                                                                                                                             
 *                                                                                                                                                                                 
 * http://www.apache.org/licenses/LICENSE-2.0                                                                                                                                      
 *                                                                                                                                                                                 
 * Unless required by applicable law or agreed to in writing, software                                                                                                             
 * distributed under the License is distributed on an "AS IS" BASIS,                                                                                                               
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or                                                                                                                 
 * implied. See the License for the specific language governing                                                                                                                    
 * permissions and limitations under the License. See accompanying                                                                                                                 
 * LICENSE file.                                                                                                                                                                   
 */

package com.yahoo.ycsb;


import java.io.*;
import java.text.DecimalFormat;
import java.util.*;
import java.text.SimpleDateFormat;

import com.yahoo.ycsb.measurements.Measurements;
import com.yahoo.ycsb.measurements.exporter.MeasurementsExporter;
import com.yahoo.ycsb.measurements.exporter.TextMeasurementsExporter;

//import org.apache.log4j.BasicConfigurator;

/**
 * A thread to periodically show the status of the experiment, to reassure you that progress is being made.
 * 
 * @author cooperb
 *
 */
class StatusThread extends Thread
{
	Vector<Thread> _threads;
	String _label;
	boolean _standardstatus;
	Properties _prop;
	boolean _dotransactions;

	/**
	 * The interval for reporting status.
	 */
	public static final long sleeptime=10000;

	public StatusThread(Vector<Thread> threads, String label, boolean standardstatus, Properties prop, boolean dotransactions)
	{
		_threads=threads;
		_label=label;
		_standardstatus=standardstatus;
		_prop=prop;
		_dotransactions=dotransactions;
	}

	/**
	 * Run and periodically report status.
	 */
	public void run()
	{

		try
		{
			//get core properties
			String db = _prop.getProperty("db","com.yahoo.ycsb.BasicDB");
			String dbName = db.substring(db.lastIndexOf('.')+1);
			String recordCount = _prop.getProperty("recordcount");
			String opCount = _prop.getProperty("operationcount");
			String workloadPath = _prop.getProperty("workloadPath");
			String workloadName = workloadPath.substring(workloadPath.lastIndexOf('/'));
			String read = _prop.getProperty("readproportion","0.95");
			String update = _prop.getProperty("updateproportion","0.05");
			String insert = _prop.getProperty("insertproportion","0");
			String scan = _prop.getProperty("scanproportion","0");
			SimpleDateFormat sdfDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			Date tempTime = new Date();
			String time = sdfDate.format(tempTime);
			String hosts = _prop.getProperty("hosts");
			String numNodes = _prop.getProperty("numNodes");
			String threadcount = _prop.getProperty("threadcount","1");

			//create the folder/subfolders to write status output file to
			String projPath = "/var/www/416Project/";
			long unixTime = System.currentTimeMillis() / 1000L;
			String epoch = String.valueOf(unixTime);
			String loadOrRun = _dotransactions?"run":"load";
			String filename = projPath+workloadName+"/"+epoch+loadOrRun+dbName+"StatusLogs.dat";
			new File(projPath+workloadName).mkdir();
			new File(filename);

			//create a file writer to write properties/status
			FileWriter stream = new FileWriter(filename);
			BufferedWriter writer = new BufferedWriter(stream);

			//write properties first
			writer.write("db,"+dbName);
			writer.newLine();
			writer.flush();
			writer.write("recordcount,"+recordCount);
			writer.newLine();
			writer.flush();
			writer.write("operationcount,"+opCount);
			writer.newLine();
			writer.flush();	
			writer.write("readproportion,"+read);
			writer.newLine();
			writer.flush();
			writer.write("updateproportion,"+update);
			writer.newLine();
			writer.flush();
			writer.write("insertproportion,"+insert);
			writer.newLine();
			writer.flush();
			writer.write("scanproportion,"+scan);
			writer.newLine();
			writer.flush();
			writer.write("time,"+time);
			writer.newLine();
			writer.flush();
			writer.write("threadcount,"+threadcount);
			writer.newLine();
			writer.flush();
			writer.write("numNodes,"+numNodes);
			writer.newLine();
			writer.flush();
			writer.write("hosts,"+hosts);
			writer.newLine();
			writer.newLine();
			writer.flush();

			long st=System.currentTimeMillis();

			long lasten=st;
			long lasttotalops=0;
			
			boolean alldone;

			do 
			{
				alldone=true;

				int totalops=0;

			//terminate this thread when all the worker threads are done
				for (Thread t : _threads)
				{
					if (t.getState()!=Thread.State.TERMINATED)
					{
						alldone=false;
					}

					ClientThread ct=(ClientThread)t;
					totalops+=ct.getOpsDone();
				}

				long en=System.currentTimeMillis();

				long interval=en-st;
			//double throughput=1000.0*((double)totalops)/((double)interval);

				double curthroughput=1000.0*(((double)(totalops-lasttotalops))/((double)(en-lasten)));
				
				lasttotalops=totalops;
				lasten=en;
				
				DecimalFormat d = new DecimalFormat("#.##");

				String summary = Measurements.getMeasurements().getSummary();
				String statusNew = /*_label+" "+*/(double)interval/1000+" sec,"+totalops+" operations,"+summary;
				String status = /*_label+" "+*/(double)interval/1000+" sec,"+totalops+" operations,"+d.format(curthroughput)+" current ops/sec,"+summary;
				
				if (totalops==0)
				{
					System.err.println(statusNew);
					writer.write(statusNew,0,statusNew.length());
					writer.newLine();
					writer.flush();
				}
				else
				{
					System.err.println(status);
					writer.write(status,0,status.length());
					writer.newLine();
					writer.flush();
				}

				if (_standardstatus)
				{
					if (totalops==0)
					{
						System.out.println(statusNew);
						writer.write(statusNew,0,statusNew.length());
						writer.newLine();
						writer.flush();
					}
					else
					{
						System.out.println(status);
						writer.write(status,0,status.length());
						writer.newLine();
						writer.flush();
					}
				}

				try
				{
					sleep(sleeptime);
				}
				catch (InterruptedException e)
				{
				//do nothing
				}

			}
			while (!alldone);
			writer.close();
		}
		catch ( Exception e )
		{
			System.err.println("Error: " + e.getMessage());
		}
	}
}

/**
 * A thread for executing transactions or data inserts to the database.
 * 
 * @author cooperb
 *
 */
class ClientThread extends Thread
{
	DB _db;
	boolean _dotransactions;
	Workload _workload;
	int _opcount;
	double _target;

	int _opsdone;
	int _threadid;
	int _threadcount;
	Object _workloadstate;
	Properties _props;


	/**
	 * Constructor.
	 * 
	 * @param db the DB implementation to use
	 * @param dotransactions true to do transactions, false to insert data
	 * @param workload the workload to use
	 * @param threadid the id of this thread 
	 * @param threadcount the total number of threads 
	 * @param props the properties defining the experiment
	 * @param opcount the number of operations (transactions or inserts) to do
	 * @param targetperthreadperms target number of operations per thread per ms
	 */
	public ClientThread(DB db, boolean dotransactions, Workload workload, int threadid, int threadcount, Properties props, int opcount, double targetperthreadperms)
	{
		//TODO: consider removing threadcount and threadid
		_db=db;
		_dotransactions=dotransactions;
		_workload=workload;
		_opcount=opcount;
		_opsdone=0;
		_target=targetperthreadperms;
		_threadid=threadid;
		_threadcount=threadcount;
		_props=props;
		//System.out.println("Interval = "+interval);
	}

	public int getOpsDone()
	{
		return _opsdone;
	}

	public void run()
	{
		try
		{
			_db.init();
		}
		catch (DBException e)
		{
			e.printStackTrace();
			e.printStackTrace(System.out);
			return;
		}

		try
		{
			_workloadstate=_workload.initThread(_props,_threadid,_threadcount);
		}
		catch (WorkloadException e)
		{
			e.printStackTrace();
			e.printStackTrace(System.out);
			return;
		}

		//spread the thread operations out so they don't all hit the DB at the same time
		try
		{
		   //GH issue 4 - throws exception if _target>1 because random.nextInt argument must be >0
		   //and the sleep() doesn't make sense for granularities < 1 ms anyway
		   if ( (_target>0) && (_target<=1.0) ) 
		   {
		      sleep(Utils.random().nextInt((int)(1.0/_target)));
		   }
		}
		catch (InterruptedException e)
		{
		  // do nothing.
		}
		
		try
		{
			if (_dotransactions)
			{
				long st=System.currentTimeMillis();

				while (((_opcount == 0) || (_opsdone < _opcount)) && !_workload.isStopRequested())
				{

					if (!_workload.doTransaction(_db,_workloadstate))
					{
						break;
					}

					_opsdone++;

					//throttle the operations
					if (_target>0)
					{
						//this is more accurate than other throttling approaches we have tried,
						//like sleeping for (1/target throughput)-operation latency,
						//because it smooths timing inaccuracies (from sleep() taking an int, 
						//current time in millis) over many operations
						while (System.currentTimeMillis()-st<((double)_opsdone)/_target)
						{
							try
							{
								sleep(1);
							}
							catch (InterruptedException e)
							{
							  // do nothing.
							}

						}
					}
				}
			}
			else
			{
				long st=System.currentTimeMillis();

				while (((_opcount == 0) || (_opsdone < _opcount)) && !_workload.isStopRequested())
				{

					if (!_workload.doInsert(_db,_workloadstate))
					{
						break;
					}

					_opsdone++;

					//throttle the operations
					if (_target>0)
					{
						//this is more accurate than other throttling approaches we have tried,
						//like sleeping for (1/target throughput)-operation latency,
						//because it smooths timing inaccuracies (from sleep() taking an int, 
						//current time in millis) over many operations
						while (System.currentTimeMillis()-st<((double)_opsdone)/_target)
						{
							try 
							{
								sleep(1);
							}
							catch (InterruptedException e)
							{
							  // do nothing.
							}
						}
					}
				}
			}
		}
		catch (Exception e)
		{
			e.printStackTrace();
			e.printStackTrace(System.out);
			System.exit(0);
		}

		try
		{
			_db.cleanup();
		}
		catch (DBException e)
		{
			e.printStackTrace();
			e.printStackTrace(System.out);
			return;
		}
	}
}

/**
 * Main class for executing YCSB.
 */
public class Client
{

	public static final String OPERATION_COUNT_PROPERTY="operationcount";

	public static final String RECORD_COUNT_PROPERTY="recordcount";

	public static final String WORKLOAD_PROPERTY="workload";

	public static final String NUMNODES_PROPERTY="numNodes";
	
	/**
	 * Indicates how many inserts to do, if less than recordcount. Useful for partitioning
	 * the load among multiple servers, if the client is the bottleneck. Additionally, workloads
	 * should support the "insertstart" property, which tells them which record to start at.
	 */
	public static final String INSERT_COUNT_PROPERTY="insertcount";
	
	/**
   * The maximum amount of time (in seconds) for which the benchmark will be run.
   */
  public static final String MAX_EXECUTION_TIME = "maxexecutiontime";

	public static void usageMessage()
	{
		System.out.println("Usage: java com.yahoo.ycsb.Client [options]");
		System.out.println("Options:");
		System.out.println("  -threads n: execute using n threads (default: 1) - can also be specified as the \n" +
				"              \"threadcount\" property using -p");
		System.out.println("  -target n: attempt to do n operations per second (default: unlimited) - can also\n" +
				"             be specified as the \"target\" property using -p");
		System.out.println("  -load:  run the loading phase of the workload");
		System.out.println("  -t:  run the transactions phase of the workload (default)");
		System.out.println("  -db dbname: specify the name of the DB to use (default: com.yahoo.ycsb.BasicDB) - \n" +
				"              can also be specified as the \"db\" property using -p");
		System.out.println("  -P propertyfile: load properties from the given file. Multiple files can");
		System.out.println("                   be specified, and will be processed in the order specified");
		System.out.println("  -p name=value:  specify a property to be passed to the DB and workloads;");
		System.out.println("                  multiple properties can be specified, and override any");
		System.out.println("                  values in the propertyfile");
		System.out.println("  -s:  show status during run (default: no status)");
		System.out.println("  -l label:  use label for status (e.g. to label one experiment out of a whole batch)");
		System.out.println("");
		System.out.println("Required properties:");
		System.out.println("  "+WORKLOAD_PROPERTY+": the name of the workload class to use (e.g. com.yahoo.ycsb.workloads.CoreWorkload)");
		System.out.println("");
		System.out.println("To run the transaction phase from multiple servers, start a separate client on each.");
		System.out.println("To run the load phase from multiple servers, start a separate client on each; additionally,");
		System.out.println("use the \"insertcount\" and \"insertstart\" properties to divide up the records to be inserted");
	}

	public static boolean checkRequiredProperties(Properties props)
	{
		if (props.getProperty(WORKLOAD_PROPERTY)==null)
		{
			System.out.println("Missing property: "+WORKLOAD_PROPERTY);
			return false;
		}

		if (props.getProperty(NUMNODES_PROPERTY)==null)
		{
			System.err.println("Please specify numNodes property!!!");
			return false;
		}

		return true;
	}


	/**
	 * Exports the measurements to either sysout or a file using the exporter
	 * loaded from conf.
	 * @throws IOException Either failed to write to output stream or failed to close it.
	 */
	private static void exportMeasurements(Properties props, int opcount, long runtime)
			throws IOException
	{
		MeasurementsExporter exporter = null;
		try
		{
			// if no destination file is provided the results will be written to stdout
			OutputStream out;
			String exportFile = props.getProperty("exportfile");
			if (exportFile == null)
			{
				out = System.out;
			} else
			{
				out = new FileOutputStream(exportFile);
			}

			// if no exporter is provided the default text one will be used
			String exporterStr = props.getProperty("exporter", "com.yahoo.ycsb.measurements.exporter.TextMeasurementsExporter");
			try
			{
				exporter = (MeasurementsExporter) Class.forName(exporterStr).getConstructor(OutputStream.class).newInstance(out);
			} catch (Exception e)
			{
				System.err.println("Could not find exporter " + exporterStr
						+ ", will use default text reporter.");
				e.printStackTrace();
				exporter = new TextMeasurementsExporter(out);
			}

			exporter.write("OVERALL", "RunTime(ms)", runtime);
			double throughput = 1000.0 * ((double) opcount) / ((double) runtime);
			exporter.write("OVERALL", "Throughput(ops/sec)", throughput);

			Measurements.getMeasurements().exportMeasurements(exporter);
		} finally
		{
			if (exporter != null)
			{
				exporter.close();
			}
		}
	}
	
	@SuppressWarnings("unchecked")
	public static void main(String[] args)
	{
		String dbname;
		Properties props=new Properties();
		Properties fileprops=new Properties();
		boolean dotransactions=true;
		int threadcount=1;
		int target=0;
		boolean status=false;
		String label="";

		//parse arguments
		int argindex=0;

		if (args.length==0)
		{
			usageMessage();
			System.exit(0);
		}

		while (args[argindex].startsWith("-"))
		{
			if (args[argindex].compareTo("-threads")==0)
			{
				argindex++;
				if (argindex>=args.length)
				{
					usageMessage();
					System.exit(0);
				}
				int tcount=Integer.parseInt(args[argindex]);
				props.setProperty("threadcount", tcount+"");
				argindex++;
			}
			else if (args[argindex].compareTo("-target")==0)
			{
				argindex++;
				if (argindex>=args.length)
				{
					usageMessage();
					System.exit(0);
				}
				int ttarget=Integer.parseInt(args[argindex]);
				props.setProperty("target", ttarget+"");
				argindex++;
			}
			else if (args[argindex].compareTo("-load")==0)
			{
				dotransactions=false;
				argindex++;
			}
			else if (args[argindex].compareTo("-t")==0)
			{
				dotransactions=true;
				argindex++;
			}
			else if (args[argindex].compareTo("-s")==0)
			{
				status=true;
				argindex++;
			}
			else if (args[argindex].compareTo("-db")==0)
			{
				argindex++;
				if (argindex>=args.length)
				{
					usageMessage();
					System.exit(0);
				}
				props.setProperty("db",args[argindex]);
				argindex++;
			}
			else if (args[argindex].compareTo("-l")==0)
			{
				argindex++;
				if (argindex>=args.length)
				{
					usageMessage();
					System.exit(0);
				}
				label=args[argindex];
				argindex++;
			}
			else if (args[argindex].compareTo("-P")==0)
			{
				argindex++;
				if (argindex>=args.length)
				{
					usageMessage();
					System.exit(0);
				}
				String propfile=args[argindex];
				argindex++;

				//Add workload filename proeprty
				if (propfile.contains("workload"))
				{
					props.setProperty("workloadPath",propfile);
				}

				Properties myfileprops=new Properties();
				try
				{
					myfileprops.load(new FileInputStream(propfile));
				}
				catch (IOException e)
				{
					System.out.println(e.getMessage());
					System.exit(0);
				}

				//Issue #5 - remove call to stringPropertyNames to make compilable under Java 1.5
				for (Enumeration e=myfileprops.propertyNames(); e.hasMoreElements(); )
				{
				   String prop=(String)e.nextElement();
				   
				   fileprops.setProperty(prop,myfileprops.getProperty(prop));
				}

			}
			else if (args[argindex].compareTo("-p")==0)
			{
				argindex++;
				if (argindex>=args.length)
				{
					usageMessage();
					System.exit(0);
				}
				int eq=args[argindex].indexOf('=');
				if (eq<0)
				{
					usageMessage();
					System.exit(0);
				}

				String name=args[argindex].substring(0,eq);
				String value=args[argindex].substring(eq+1);
				props.put(name,value);
				//System.out.println("["+name+"]=["+value+"]");
				argindex++;
			}
			else
			{
				System.out.println("Unknown option "+args[argindex]);
				usageMessage();
				System.exit(0);
			}

			if (argindex>=args.length)
			{
				break;
			}
		}

		if (argindex!=args.length)
		{
			usageMessage();
			System.exit(0);
		}

		//set up logging
		//BasicConfigurator.configure();

		//overwrite file properties with properties from the command line

		//Issue #5 - remove call to stringPropertyNames to make compilable under Java 1.5
		for (Enumeration e=props.propertyNames(); e.hasMoreElements(); )
		{
		   String prop=(String)e.nextElement();
		   
		   fileprops.setProperty(prop,props.getProperty(prop));
		}

		props=fileprops;

		if (!checkRequiredProperties(props))
		{
			System.exit(0);
		}
		
		long maxExecutionTime = Integer.parseInt(props.getProperty(MAX_EXECUTION_TIME, "0"));

		//get number of threads, target and db
		threadcount=Integer.parseInt(props.getProperty("threadcount","1"));
		dbname=props.getProperty("db","com.yahoo.ycsb.BasicDB");
		target=Integer.parseInt(props.getProperty("target","0"));

		System.err.println("number of threads used: " + threadcount);
		
		//compute the target throughput
		double targetperthreadperms=-1;
		if (target>0)
		{
			double targetperthread=((double)target)/((double)threadcount);
			targetperthreadperms=targetperthread/1000.0;
		}	 

		System.out.println("YCSB Client 0.1");
		System.out.print("Command line:");
		for (int i=0; i<args.length; i++)
		{
			System.out.print(" "+args[i]);
		}
		System.out.println();
		System.err.println("Loading workload...");
		
		//show a warning message that creating the workload is taking a while
		//but only do so if it is taking longer than 2 seconds 
		//(showing the message right away if the setup wasn't taking very long was confusing people)
		Thread warningthread=new Thread() 
		{
			public void run()
			{
				try
				{
					sleep(2000);
				}
				catch (InterruptedException e)
				{
					return;
				}
				System.err.println(" (might take a few minutes for large data sets)");
			}
		};

		warningthread.start();
		
		//set up measurements
		Measurements.setProperties(props);
		
		//load the workload
		ClassLoader classLoader = Client.class.getClassLoader();

		Workload workload=null;

		try 
		{
			Class workloadclass = classLoader.loadClass(props.getProperty(WORKLOAD_PROPERTY));

			workload=(Workload)workloadclass.newInstance();
		}
		catch (Exception e) 
		{  
			e.printStackTrace();
			e.printStackTrace(System.out);
			System.exit(0);
		}

		try
		{
			workload.init(props);
		}
		catch (WorkloadException e)
		{
			e.printStackTrace();
			e.printStackTrace(System.out);
			System.exit(0);
		}

		if (!status)
		{
			System.err.println("Please specify status flag -s");
			System.exit(0);
		}
		
		warningthread.interrupt();

		//run the workload

		System.err.println("Starting test.");

		int opcount;
		if (dotransactions)
		{
			opcount=Integer.parseInt(props.getProperty(OPERATION_COUNT_PROPERTY,"0"));
		}
		else
		{
			if (props.containsKey(INSERT_COUNT_PROPERTY))
			{
				opcount=Integer.parseInt(props.getProperty(INSERT_COUNT_PROPERTY,"0"));
			}
			else
			{
				opcount=Integer.parseInt(props.getProperty(RECORD_COUNT_PROPERTY,"0"));
			}
		}

		Vector<Thread> threads=new Vector<Thread>();

		for (int threadid=0; threadid<threadcount; threadid++)
		{
			DB db=null;
			try
			{
				db=DBFactory.newDB(dbname,props);
			}
			catch (UnknownDBException e)
			{
				System.out.println("Unknown DB "+dbname);
				System.exit(0);
			}

			Thread t=new ClientThread(db,dotransactions,workload,threadid,threadcount,props,opcount/threadcount,targetperthreadperms);

			threads.add(t);
			//t.start();
		}

		StatusThread statusthread=null;

		if (status)
		{
			boolean standardstatus=false;
			if (props.getProperty("measurementtype","").compareTo("timeseries")==0) 
			{
				standardstatus=true;
			}
			statusthread=new StatusThread(threads,label,standardstatus,props,dotransactions);
			statusthread.start();
		}

		long st=System.currentTimeMillis();

		for (Thread t : threads)
		{
			t.start();
		}
		
    Thread terminator = null;
    
    if (maxExecutionTime > 0 && dotransactions) {
      terminator = new TerminatorThread(maxExecutionTime, threads, workload);
      terminator.start();
    }
    
    int opsDone = 0;

		for (Thread t : threads)
		{
			try
			{
				t.join();
				opsDone += ((ClientThread)t).getOpsDone();
			}
			catch (InterruptedException e)
			{
			}
		}

		long en=System.currentTimeMillis();
		
		if (terminator != null && !terminator.isInterrupted()) {
      terminator.interrupt();
    }

		if (status)
		{
			statusthread.interrupt();
		}

		try
		{
			workload.cleanup();
		}
		catch (WorkloadException e)
		{
			e.printStackTrace();
			e.printStackTrace(System.out);
			System.exit(0);
		}

		try
		{
			exportMeasurements(props, opsDone, en - st);
		} catch (IOException e)
		{
			System.err.println("Could not export measurements, error: " + e.getMessage());
			e.printStackTrace();
			System.exit(-1);
		}

		System.exit(0);
	}
}

Added Jenny/README.txt.



































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
Hi Mike and/or Alan,

Included in this directory are some of the files I modified/added.

The cassandra.yaml files are configuration files for each node.

The Client.java is a modified YCSB client which outputs status log file to
designated folder /var/www/416Project/.../, which is then used for graph
generation. It also limit the running time of transaction phase with specified
time.

The genThroughputNode.rb and custom.js files are written by Jesse and I for
graph generation.

The init.txt files are stdout showing that nodes joined clusters successfully.

Thanks.

Added Jenny/custom.js.































































































































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
	//draw the throughput/number of nodes graph - Load
	function drawLoadThroughput() {
		var data = google.visualization.arrayToDataTable([
			['numNodes', 'Cassandra', 'MongoDB', 'Couchbase', 'Redis', 'OrientDB'],
			['1',		4161,	    1771,	3942,	    6422,	52],
			['5',		8053,	    1280,	5123,	    5998,	49]
		]);

		var options = {
			'title': 'Throughput Results - Load process',
			'hAxis': {title: "Shards"},
			'vAxis': {title: "Throughput(operations/sec)"},
			'pointSize':2
		};

		//Create and draw the chart.
		new google.visualization.LineChart(document.getElementById('chart_div_throughput')).draw(data, options);
	}

	//draw the throughput/number of nodes graph - Run A
	function drawRunAThroughput() {
		var data = google.visualization.arrayToDataTable([
			['numNodes', 'Cassandra', 'MongoDB', 'Couchbase', 'Redis', 'OrientDB'],
			['1',		2043,	    2341,	855,	    9614,	718],
			['5',		5201,	    1791,	833,	    9054,	364]
		]);

		var options = {
			'title': 'Throughput Results - Read-mostly Workload',
			'hAxis': {title: "Shards"},
			'vAxis': {title: "Throughput(operations/sec)"},
			'pointSize':2
		};

		//Create and draw the chart.
		new google.visualization.LineChart(document.getElementById('chart_div_throughputA')).draw(data, options);
	}

	//draw the throughput/number of nodes graph - Run D
	function drawRunDThroughput() {
		var data = google.visualization.arrayToDataTable([
			['numNodes', 'Cassandra', 'MongoDB',  'Redis', 'OrientDB'],
			['1',		2242,	    5084,	8728,	568],
			['5',		5591,	    2147,	9777,	399]
		]);

		var options = {
			'colors': ['#3366cc','#dc3912','#109618','#990099'],
			'title': 'Throughput Results - Read-latest Workload',
			'hAxis': {title: "Shards"},
			'vAxis': {title: "Throughput(operations/sec)"},
			'pointSize':2
		};

		//Create and draw the chart.
		new google.visualization.LineChart(document.getElementById('chart_div_throughputD')).draw(data, options);
	}

    //generates a data table
    function createDataTable(csv,graphLatency) {

      // Create the data table.
      var dataTable = new google.visualization.DataTable();

      dataTable.addColumn('number', 'ElapsedTime');
      if(graphLatency==false){
        dataTable.addColumn('number', 'TotalOps');
      } else {
        dataTable.addColumn('number', 'AverageLatency');
      }
      addLinesToDataTable(dataTable, csv, graphLatency);

      return dataTable;
    }

    //draws a chart

    function drawLineChart(dataTable,graphLatency) {
      // Set chart options
      var options;


          //'width': 1000,
          //'height': 800,
      if(graphLatency==false){
        options = {
          'title': 'Total Operation Performance',
          'hAxis': {title: "Elapsed Seconds"},
          'vAxis': {title: "Total Operations"},
          'pointSize':2
        };

      } else {
        options = {
          'title': 'Latency Performance',
          'hAxis': {title: "Elapsed Seconds"},
          'vAxis': {title: "Average Latency"},
          'pointSize':2,
          'colors' : ['#C00000' , '#FF00FF']
        };
      }

      // Instantiate and draw our chart, passing in some options.
      if(graphLatency==false){
        var chart = new google.visualization.LineChart(document.getElementById('chart_div_line'));
        chart.draw(dataTable, options);
      } else {
        var chart = new google.visualization.ScatterChart(document.getElementById('chart_div_scatter'));
        chart.draw(dataTable, options);        
      }
    }

    //add lines to a data table
    //expects 2 columns of integers

    function addLinesToDataTable(dataTable, csv, graphLatency) {
      var lines = csv.split("\n");
      for (var j = 0; j < lines.length; j++) {
        var line = lines[j];
        if (!line.match(/sec/)) {
          continue;
        }

        var rowObj = [];
        var values = line.split(',');
        var extractedVal;
        //0.458 sec: 35 operations; 118.81 current ops/sec; [INSERT AverageLatency(us)=8053.08] 
          //elapsed seconds
        extractedVal = extractElapsedSecondsInt(values[0]);
        console.log("The elapsed seconds are " + extractedVal + "\n");
        rowObj.push(extractedVal);

        if (graphLatency==false) {
          //graph total ops
          extractedVal = extractTotalOpsInt(values[1]);
          console.log("The total ops are " + extractedVal + "\n");
          rowObj.push(extractedVal);
        } else {//latency
          if(values.length!=4){
            //at the start of the status logging there is nothing recorded for latency
            continue;
          }
          extractedVal = extractLatencyInt(values[3]);
          console.log("The latency is  " + extractedVal + "\n");
          rowObj.push(extractedVal);
        }
        
        dataTable.addRow(rowObj);
      } // end add rows
      return dataTable;
    }
 
   function extractLatencyInt (val) {
      var averageLatencyInt = parseInt(val.trim().slice(27,-1));
      return averageLatencyInt;
    }

    function extractTotalOpsInt(val) {
      var totalOpsInt = parseInt(val.trim().slice(0, -11));
      return totalOpsInt;
    }

    function extractElapsedSecondsInt(val) {
      var elpSecInt = parseInt(val.trim().slice(0, -3));
      return elpSecInt;
    }

    function determineChartsToLoad() {
      var chartsURI = [];
      chartsURI.push(cassLoad100kStatus.dat);
    }

    function fetchDataDrawChart(graphLatency,file) {
	console.log("filename is " + file);
     $.ajax({
        url: file,
        cache: false
      }).done(function(csv) {
        var dataTable= createDataTable(csv,graphLatency);
        drawLineChart(dataTable,graphLatency);
	  if(graphLatency==true){
	  //    fetchDataDrawChart(false,file)
	  }
      });
    }

function drawCharts(file){
    console.log(file);
    fetchDataDrawChart(true,file);
    fetchDataDrawChart(false,file);
}

Added Jenny/genThroughputNode.rb.



























































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/ruby
require 'rubygems'
require 'nokogiri'

if(ARGV.length >5 || ARGV.length < 1)
  puts "Usage: ruby generateWebGraphs.rb cassandraTitle,c1.dat,c2.dat couchbaseTitele,cb1.dat,cb2.dat ..." 
  exit(1)
end

DataSample = Struct.new(:title, :file1, :file2)

@DataSamples= Array.new


ARGV.each do |a|

  @values=a.split(",")
  puts "splitting an argument: #{@values}"
  if(@values.length !=3)
    exit(1)
  end
  @DataSamples.push(DataSample.new(@values[0],@values[1],@values[2]))
end

@DataSamples.each do |samples|
  # expand the current path
  @data=File.expand_path(samples["value"]);
  if(!@data.match(/var\/www/))
    puts "The file path must be inside the /var/www/ domain... The .dat file you entered is:" + @data
    exit(1)
  end
end
# chop off the /var/www/ because we need a relative path
@truncatedDataPrefix=@data.slice(8..@data.length)

# replace teh .dat with a .html
@newHtml=@data.slice(0..-4) + "html";
@truncatedHtmlPrefix = @newHtml.slice(8..@newHtml.length)

@master='/var/www/416Project/masterChartWebpage.html'

@htmlFile = File.open(@master)
@doc = Nokogiri::XML(@htmlFile)
@htmlFile.close

#change title
@title = 'Specific Chart Title'
@doc.css("#chartTitle").first().content = @data
@doc.css("#hiddenUri").first()['value']= @truncatedDataPrefix

# @scripts = @doc.xpath("//script")
# @scripts.each do | s |
#   puts s.to_xml
# end

File.open(@newHtml,'w') do |file|
  file.write(@doc.to_xhtml)
end

@hosted="http://http://ec2-50-112-20-80.us-west-2.compute.amazonaws.com/" + @truncatedHtmlPrefix
puts "Generated a webpage hosted at " + @hosted