/
Benchmark.java
736 lines (652 loc) · 30.8 KB
/
Benchmark.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
/*
* Copyright 2010 LinkedIn, Inc
*
* 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.
*/
package voldemort.performance.benchmark;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.StringReader;
import java.util.List;
import java.util.Vector;
import java.util.concurrent.TimeUnit;
import joptsimple.OptionParser;
import joptsimple.OptionSet;
import voldemort.ServerTestUtils;
import voldemort.StaticStoreClientFactory;
import voldemort.VoldemortException;
import voldemort.client.AbstractStoreClientFactory;
import voldemort.client.ClientConfig;
import voldemort.client.SocketStoreClientFactory;
import voldemort.client.StoreClient;
import voldemort.client.StoreClientFactory;
import voldemort.client.ViewStoreClient;
import voldemort.serialization.IdentitySerializer;
import voldemort.serialization.Serializer;
import voldemort.serialization.SerializerDefinition;
import voldemort.serialization.StringSerializer;
import voldemort.serialization.json.JsonTypeSerializer;
import voldemort.store.StorageConfiguration;
import voldemort.store.StorageEngine;
import voldemort.store.Store;
import voldemort.store.StoreDefinition;
import voldemort.store.bdb.BdbStorageConfiguration;
import voldemort.store.memory.InMemoryStorageConfiguration;
import voldemort.store.metadata.MetadataStore;
import voldemort.store.mysql.MysqlStorageConfiguration;
import voldemort.store.serialized.SerializingStore;
import voldemort.store.views.ViewStorageEngine;
import voldemort.utils.ByteArray;
import voldemort.utils.CmdUtils;
import voldemort.utils.Props;
import voldemort.utils.Time;
import voldemort.utils.Utils;
import voldemort.xml.StoreDefinitionsMapper;
public class Benchmark {
private static final int MAX_WORKERS = 8;
/**
* Constants for the benchmark file
*/
public static final String PROP_FILE = "prop-file";
public static final String THREADS = "threads";
public static final String ITERATIONS = "iterations";
public static final String STORAGE_ENGINE_TYPE = "storage-engine";
public static final String INTERVAL = "interval";
public static final String KEY_TYPE = "keyType";
public static final String STRING_KEY_TYPE = "string";
public static final String JSONINT_KEY_TYPE = "json-int";
public static final String JSONSTRING_KEY_TYPE = "json-string";
public static final String IDENTITY_KEY_TYPE = "identity";
public static final String HANDSHAKE = "handshake";
public static final String URL = "url";
public static final String PERCENT_CACHED = "percent-cached";
public static final String VALUE_SIZE = "value-size";
public static final String IGNORE_NULLS = "ignore-nulls";
public static final String REQUEST_FILE = "request-file";
public static final String START_KEY_INDEX = "start-key-index";
public static final String READS = "r";
public static final String WRITES = "w";
public static final String DELETES = "d";
public static final String MIXED = "m";
public static final String RECORD_SELECTION = "record-selection";
public static final String ZIPFIAN_RECORD_SELECTION = "zipfian";
public static final String LATEST_RECORD_SELECTION = "latest";
public static final String FILE_RECORD_SELECTION = "file";
public static final String UNIFORM_RECORD_SELECTION = "uniform";
public static final String TARGET_THROUGHPUT = "target-throughput";
public static final String HELP = "help";
public static final String STORE_NAME = "store-name";
public static final String RECORD_COUNT = "record-count";
public static final String OPS_COUNT = "ops-count";
public static final String METRIC_TYPE = "metric-type";
public static final String HISTOGRAM_METRIC_TYPE = "histogram";
public static final String SUMMARY_METRIC_TYPE = "summary";
public static final String VERBOSE = "v";
public static final String VERIFY = "verify";
private static final String DUMMY_DB = "benchmark_db";
public static final String STORE_TYPE = "view";
public static final String VIEW_CLASS = "voldemort.store.views.UpperCaseView";
public static final String HAS_TRANSFORMS = "true";
private StoreClient<Object, Object> storeClient;
private ViewStoreClient<Object, Object, Object> viewStoreClient;
private StoreClientFactory factory;
private int numThreads;
private int numIterations;
private int targetThroughput;
private double perThreadThroughputPerMs;
private int recordCount, opsCount;
private Workload workLoad;
private int statusIntervalSec;
private boolean storeInitialized = false;
private boolean verbose = false;
private boolean verifyRead = false;
private boolean ignoreNulls = false;
private String keyType;
private boolean isView = false;
class StatusThread extends Thread {
private Vector<Thread> threads;
private int intervalSec;
private long startTime;
public StatusThread(Vector<Thread> threads, int intervalSec, long startTime) {
this.threads = threads;
this.intervalSec = intervalSec;
this.startTime = startTime;
}
@Override
public void run() {
boolean testComplete = true;
int totalOps = 0, prevTotalOps = 0;
do {
testComplete = true;
totalOps = 0;
for(Thread thread: this.threads) {
if(thread.getState() != Thread.State.TERMINATED) {
testComplete = false;
}
totalOps += ((ClientThread) thread).getOpsDone();
}
if(totalOps != 0 && totalOps != prevTotalOps) {
System.out.println("[status]\tThroughput(ops/sec): "
+ Time.MS_PER_SECOND
* ((double) totalOps / (double) (System.currentTimeMillis() - startTime))
+ "\tOperations: " + totalOps);
}
prevTotalOps = totalOps;
try {
sleep(intervalSec * Time.MS_PER_SECOND);
} catch(InterruptedException e) {}
} while(!testComplete);
}
}
class ClientThread extends Thread {
private DbWrapper db;
private boolean runBenchmark;
private boolean verbose;
private Workload workLoad;
private int opsCount;
private double targetThroughputPerMs;
private int opsDone;
public ClientThread(DbWrapper db,
boolean runBenchmark,
Workload workLoad,
int opsCount,
double targetThroughputPerMs,
boolean verbose) {
this.db = db;
this.runBenchmark = runBenchmark;
this.workLoad = workLoad;
this.opsCount = opsCount;
this.opsDone = 0;
this.targetThroughputPerMs = targetThroughputPerMs;
this.verbose = verbose;
}
public int getOpsDone() {
return this.opsDone;
}
public void run() {
long startTime = System.currentTimeMillis();
while(opsDone < this.opsCount) {
if(runBenchmark) {
if(!workLoad.doTransaction(this.db)) {
break;
}
} else {
if(!workLoad.doWrite(this.db)) {
break;
}
}
opsDone++;
if(targetThroughputPerMs > 0) {
while(System.currentTimeMillis() - startTime < ((double) opsDone)
/ targetThroughputPerMs) {
try {
sleep(1);
} catch(InterruptedException e) {}
}
}
}
}
}
private StoreDefinition getStoreDefinition(AbstractStoreClientFactory factory, String storeName) {
String storesXml = factory.bootstrapMetadataWithRetries(MetadataStore.STORES_KEY);
StoreDefinitionsMapper storeMapper = new StoreDefinitionsMapper();
List<StoreDefinition> storeDefinitionList = storeMapper.readStoreList(new StringReader(storesXml));
StoreDefinition storeDef = null;
for(StoreDefinition storeDefinition: storeDefinitionList) {
if(storeName.equals(storeDefinition.getName())) {
storeDef = storeDefinition;
}
}
return storeDef;
}
private Object getTempKey(String keyType) {
if(keyType.compareTo(STRING_KEY_TYPE) == 0 || keyType.compareTo(JSONSTRING_KEY_TYPE) == 0) {
return "" + 0;
} else if(keyType.compareTo(JSONINT_KEY_TYPE) == 0) {
return 0;
} else {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
bos.write(0);
return bos.toByteArray();
}
}
public String findKeyType(StoreDefinition storeDefinition) throws Exception {
SerializerDefinition serializerDefinition = storeDefinition.getKeySerializer();
if(serializerDefinition != null) {
if("string".equals(serializerDefinition.getName())) {
return Benchmark.STRING_KEY_TYPE;
} else if("json".equals(serializerDefinition.getName())) {
if(serializerDefinition.getCurrentSchemaInfo().contains("int")) {
return Benchmark.JSONINT_KEY_TYPE;
} else if(serializerDefinition.getCurrentSchemaInfo().contains("string")) {
return Benchmark.JSONSTRING_KEY_TYPE;
}
} else if("identity".equals(serializerDefinition.getName())) {
return Benchmark.IDENTITY_KEY_TYPE;
}
}
throw new Exception("Can't determine key type for key serializer "
+ storeDefinition.getName());
}
public Serializer<?> findKeyType(String keyType) throws Exception {
if(keyType.compareTo(STRING_KEY_TYPE) == 0) {
return new StringSerializer();
} else if(keyType.compareTo(JSONINT_KEY_TYPE) == 0) {
return new JsonTypeSerializer("\"int32\"");
} else if(keyType.compareTo(JSONSTRING_KEY_TYPE) == 0) {
return new JsonTypeSerializer("\"string\"");
} else if(keyType.compareTo(IDENTITY_KEY_TYPE) == 0) {
return new IdentitySerializer();
}
throw new Exception("Can't determine for keyType = " + keyType);
}
public void initializeWorkload(Props workloadProps) throws Exception {
if(!this.storeInitialized) {
throw new VoldemortException("Store not initialized correctly");
}
// Calculate perThreadThroughputPerMs = default unlimited (-1)
this.targetThroughput = workloadProps.getInt(TARGET_THROUGHPUT, -1);
this.perThreadThroughputPerMs = -1;
if(targetThroughput > 0) {
double targetperthread = ((double) targetThroughput) / ((double) numThreads);
this.perThreadThroughputPerMs = targetperthread / 1000.0;
}
// Compulsory parameters
if(workloadProps.containsKey(RECORD_COUNT) && workloadProps.containsKey(OPS_COUNT)) {
this.recordCount = workloadProps.getInt(RECORD_COUNT);
this.opsCount = workloadProps.getInt(OPS_COUNT);
} else {
throw new VoldemortException("Missing compulsory parameters - " + RECORD_COUNT
+ " or " + OPS_COUNT);
}
// Initialize measurement
Metrics.setProperties(workloadProps);
Metrics.getInstance().reset();
// Initialize workload
this.workLoad = new Workload();
this.workLoad.init(workloadProps);
}
@SuppressWarnings("unchecked")
public void initializeStore(Props benchmarkProps) throws Exception {
this.numThreads = benchmarkProps.getInt(THREADS, MAX_WORKERS);
this.numIterations = benchmarkProps.getInt(ITERATIONS, 1);
this.statusIntervalSec = benchmarkProps.getInt(INTERVAL, 0);
this.verbose = benchmarkProps.getBoolean(VERBOSE, false);
this.verifyRead = benchmarkProps.getBoolean(VERIFY, false);
this.ignoreNulls = benchmarkProps.getBoolean(IGNORE_NULLS, false);
if(benchmarkProps.containsKey(URL)) {
// Remote benchmark
if(!benchmarkProps.containsKey(STORE_NAME)) {
throw new VoldemortException("Missing storename");
}
String socketUrl = benchmarkProps.getString(URL);
String storeName = benchmarkProps.getString(STORE_NAME);
String storeType = benchmarkProps.getString(STORE_TYPE);
boolean isView = false;
if(storeType.compareTo("view") == 0)
isView = true;
ClientConfig clientConfig = new ClientConfig().setMaxThreads(numThreads)
.setMaxTotalConnections(numThreads)
.setMaxConnectionsPerNode(numThreads)
.setBootstrapUrls(socketUrl)
.setConnectionTimeout(60,
TimeUnit.SECONDS)
.setSocketTimeout(60, TimeUnit.SECONDS)
.setFailureDetectorRequestLengthThreshold(TimeUnit.SECONDS.toMillis(60))
.setSocketBufferSize(4 * 1024);
SocketStoreClientFactory socketFactory = new SocketStoreClientFactory(clientConfig);
if(isView)
this.viewStoreClient = socketFactory.getViewStoreClient(storeName);
else
this.storeClient = socketFactory.getStoreClient(storeName);
StoreDefinition storeDef = getStoreDefinition(socketFactory, storeName);
this.keyType = findKeyType(storeDef);
benchmarkProps.put(Benchmark.KEY_TYPE, this.keyType);
this.factory = socketFactory;
// Send the store a value and then delete it
if(benchmarkProps.getBoolean(HANDSHAKE, false)) {
final Object key = getTempKey(this.keyType);
if(isView) {
this.viewStoreClient.delete(key);
this.viewStoreClient.put(key, "123");
this.viewStoreClient.delete(key);
} else {
this.storeClient.delete(key);
this.storeClient.put(key, "123");
this.storeClient.delete(key);
}
}
} else {
// Local benchmark
String storageEngineType = benchmarkProps.getString(STORAGE_ENGINE_TYPE);
this.keyType = benchmarkProps.getString(KEY_TYPE, STRING_KEY_TYPE);
Serializer serializer = findKeyType(this.keyType);
Store<Object, Object, Object> store = null;
StorageConfiguration conf = null;
if(storageEngineType.compareTo(BdbStorageConfiguration.TYPE_NAME) == 0) {
conf = new BdbStorageConfiguration(ServerTestUtils.getVoldemortConfig());
} else if(storageEngineType.compareTo(MysqlStorageConfiguration.TYPE_NAME) == 0) {
conf = new MysqlStorageConfiguration(ServerTestUtils.getVoldemortConfig());
} else if(storageEngineType.compareTo(InMemoryStorageConfiguration.TYPE_NAME) == 0) {
conf = new InMemoryStorageConfiguration(ServerTestUtils.getVoldemortConfig());
}
StorageEngine<ByteArray, byte[], byte[]> engine = conf.getStore(DUMMY_DB);
String storeType = benchmarkProps.getString(STORE_TYPE);
if(storeType.compareTo("view") == 0) {
engine = new ViewStorageEngine(STORE_NAME,
engine,
new StringSerializer(),
new StringSerializer(),
new StringSerializer(),
new StringSerializer(),
null,
BenchmarkViews.loadTransformation(benchmarkProps.getString(VIEW_CLASS)
.trim()));
isView = true;
}
store = SerializingStore.wrap(engine,
serializer,
new StringSerializer(),
new IdentitySerializer());
this.factory = new StaticStoreClientFactory(store);
if(storeType.compareTo("view") == 0)
this.viewStoreClient = factory.getViewStoreClient(store.getName());
else
this.storeClient = factory.getStoreClient(store.getName());
}
this.storeInitialized = true;
}
public void initialize(Props benchmarkProps) throws Exception {
if(!this.storeInitialized) {
initializeStore(benchmarkProps);
}
initializeWorkload(benchmarkProps);
}
public void warmUpAndRun() throws Exception {
if(this.recordCount > 0) {
runTests(false);
Metrics.getInstance().reset();
}
for(int index = 0; index < this.numIterations; index++) {
System.out.println("======================= iteration = " + index
+ " ======================================");
runTests(true);
Metrics.getInstance().reset();
}
}
@SuppressWarnings("cast")
public long runTests(boolean runBenchmark) throws Exception {
int localOpsCounts = 0;
String label = null;
if(runBenchmark) {
localOpsCounts = this.opsCount;
label = new String("benchmark");
} else {
localOpsCounts = this.recordCount;
label = new String("warmup");
}
Vector<Thread> threads = new Vector<Thread>();
DbWrapper db;
for(int index = 0; index < this.numThreads; index++) {
if(isView) {
db = new VoldemortViewWrapper(viewStoreClient, this.verifyRead, this.ignoreNulls);
} else {
db = new VoldemortWrapper(storeClient, this.verifyRead, this.ignoreNulls);
}
Thread clientThread = new ClientThread(db,
runBenchmark,
this.workLoad,
localOpsCounts / this.numThreads,
this.perThreadThroughputPerMs,
this.verbose);
threads.add(clientThread);
}
long startRunBenchmark = System.currentTimeMillis();
for(Thread currentThread: threads) {
currentThread.start();
}
StatusThread statusThread = null;
if(this.statusIntervalSec > 0) {
statusThread = new StatusThread(threads, this.statusIntervalSec, startRunBenchmark);
statusThread.start();
}
for(Thread currentThread: threads) {
try {
currentThread.join();
} catch(InterruptedException e) {
if(this.verbose)
e.printStackTrace();
}
}
long endRunBenchmark = System.currentTimeMillis();
if(this.statusIntervalSec > 0) {
statusThread.interrupt();
}
System.out.println("[" + label + "]\tRunTime(ms): " + (endRunBenchmark - startRunBenchmark));
double throughput = Time.MS_PER_SECOND * ((double) localOpsCounts)
/ ((double) (endRunBenchmark - startRunBenchmark));
System.out.println("[" + label + "]\tThroughput(ops/sec): " + throughput);
if(runBenchmark) {
Metrics.getInstance().printReport(System.out);
}
return (endRunBenchmark - startRunBenchmark);
}
public static void main(String args[]) throws IOException {
// Logger.getRootLogger().removeAllAppenders();
OptionParser parser = new OptionParser();
parser.accepts(READS, "execute read operations").withOptionalArg().ofType(Integer.class);
parser.accepts(WRITES, "execute write operations").withOptionalArg().ofType(Integer.class);
parser.accepts(DELETES, "execute delete operations")
.withOptionalArg()
.ofType(Integer.class);
parser.accepts(MIXED, "generate a mix of read and write requests")
.withOptionalArg()
.ofType(Integer.class);
parser.accepts(VERBOSE, "verbose");
parser.accepts(THREADS, "max number concurrent worker threads Default = 1")
.withRequiredArg()
.ofType(Integer.class);
parser.accepts(ITERATIONS, "number of times to repeat the test Default = 1")
.withRequiredArg()
.ofType(Integer.class);
parser.accepts(VERIFY, "verify values read");
parser.accepts(HANDSHAKE, "perform a handshake");
parser.accepts(PERCENT_CACHED,
"percentage of requests to come from previously requested keys; valid values are in range [0..100]; 0 means caching disabled Default = 0")
.withRequiredArg()
.ofType(Integer.class);
parser.accepts(START_KEY_INDEX, "starting point when using int keys. Default = 0")
.withRequiredArg()
.ofType(Integer.class);
parser.accepts(INTERVAL, "print requests on this interval Default = 0")
.withRequiredArg()
.ofType(Integer.class);
parser.accepts(IGNORE_NULLS, "ignore null values");
parser.accepts(PROP_FILE, "file containing all the properties").withRequiredArg();
parser.accepts(STORAGE_ENGINE_TYPE, "file containing all the properties Default = memory")
.withRequiredArg();
parser.accepts(KEY_TYPE, "which key type to support Default = string").withRequiredArg();
parser.accepts(REQUEST_FILE,
"execute specific requests in order. Overrides " + RECORD_SELECTION)
.withRequiredArg();
parser.accepts(VALUE_SIZE, "size in bytes for random value. Default = 1024")
.withRequiredArg()
.ofType(Integer.class);
parser.accepts(RECORD_SELECTION,
"how to select record [zipfian | latest | uniform <default>]")
.withRequiredArg();
parser.accepts(TARGET_THROUGHPUT, "fix the throughput")
.withRequiredArg()
.ofType(Integer.class);
parser.accepts(RECORD_COUNT, "number of records inserted during warmup phase")
.withRequiredArg()
.ofType(Integer.class);
parser.accepts(OPS_COUNT, "number of operations to do")
.withRequiredArg()
.ofType(Integer.class);
parser.accepts(URL, "url on which to run remote tests").withRequiredArg();
parser.accepts(STORE_NAME, "store name on the remote URL").withRequiredArg();
parser.accepts(METRIC_TYPE, "type of metric [histogram | summary]").withRequiredArg();
parser.accepts(HELP);
OptionSet options = parser.parse(args);
if(options.has(HELP)) {
parser.printHelpOn(System.out);
System.exit(0);
}
Props mainProps = null;
if(options.has(PROP_FILE)) {
String propFileDestination = (String) options.valueOf(PROP_FILE);
File propertyFile = new File(propFileDestination);
if(!propertyFile.exists()) {
printUsage(parser, "Property file does not exist");
}
try {
mainProps = new Props(propertyFile);
} catch(Exception e) {
printUsage(parser, "Unable to parse the property file");
}
} else {
mainProps = new Props();
// Backward compatibility with RemoteTests
List<String> nonOptions = options.nonOptionArguments();
if(nonOptions.size() != 3 && nonOptions.size() != 0) {
printUsage(parser, "Incorrect options");
}
if(nonOptions.size() == 3) {
mainProps.put(URL, nonOptions.get(0));
mainProps.put(STORE_NAME, nonOptions.get(1));
mainProps.put(OPS_COUNT, Integer.parseInt(nonOptions.get(2)));
} else {
// Parse Ops_count
if(!options.has(OPS_COUNT)) {
printUsage(parser, "Missing " + OPS_COUNT);
}
mainProps.put(OPS_COUNT, (Integer) options.valueOf(OPS_COUNT));
if(options.has(URL)) {
mainProps.put(URL, (String) options.valueOf(URL));
if(options.has(HANDSHAKE)) {
mainProps.put(HANDSHAKE, "true");
} else {
mainProps.put(HANDSHAKE, "false");
}
if(options.has(STORE_NAME)) {
mainProps.put(STORE_NAME, (String) options.valueOf(STORE_NAME));
} else {
printUsage(parser, "Missing store name");
}
} else {
mainProps.put(KEY_TYPE, CmdUtils.valueOf(options, KEY_TYPE, STRING_KEY_TYPE));
mainProps.put(STORAGE_ENGINE_TYPE,
CmdUtils.valueOf(options,
STORAGE_ENGINE_TYPE,
InMemoryStorageConfiguration.TYPE_NAME));
}
}
// Parse Record_Count
if(options.has(RECORD_COUNT)) {
mainProps.put(RECORD_COUNT, (Integer) options.valueOf(RECORD_COUNT));
} else {
mainProps.put(RECORD_COUNT, 0);
}
mainProps.put(RECORD_SELECTION, CmdUtils.valueOf(options,
RECORD_SELECTION,
UNIFORM_RECORD_SELECTION));
if(options.has(REQUEST_FILE)) {
mainProps.put(REQUEST_FILE, (String) options.valueOf(REQUEST_FILE));
// Override existing RECORD_SELECTION setting
mainProps.put(RECORD_SELECTION, FILE_RECORD_SELECTION);
}
if(options.has(VERBOSE)) {
mainProps.put(VERBOSE, "true");
} else {
mainProps.put(VERBOSE, "false");
}
if(options.has(VERIFY)) {
mainProps.put(VERIFY, "true");
} else {
mainProps.put(VERIFY, "false");
}
if(options.has(IGNORE_NULLS)) {
mainProps.put(IGNORE_NULLS, "true");
} else {
mainProps.put(IGNORE_NULLS, "false");
}
mainProps.put(START_KEY_INDEX, CmdUtils.valueOf(options, START_KEY_INDEX, 0));
mainProps.put(VALUE_SIZE, CmdUtils.valueOf(options, VALUE_SIZE, 1024));
mainProps.put(ITERATIONS, CmdUtils.valueOf(options, ITERATIONS, 1));
mainProps.put(THREADS, CmdUtils.valueOf(options, THREADS, MAX_WORKERS));
mainProps.put(PERCENT_CACHED, CmdUtils.valueOf(options, PERCENT_CACHED, 0));
mainProps.put(INTERVAL, CmdUtils.valueOf(options, INTERVAL, 0));
mainProps.put(TARGET_THROUGHPUT, CmdUtils.valueOf(options, TARGET_THROUGHPUT, -1));
mainProps.put(METRIC_TYPE, CmdUtils.valueOf(options, METRIC_TYPE, SUMMARY_METRIC_TYPE));
String ops = "";
ops += checkOpsRatio(options, mainProps, READS);
ops += checkOpsRatio(options, mainProps, WRITES);
ops += checkOpsRatio(options, mainProps, DELETES);
ops += checkOpsRatio(options, mainProps, MIXED);
if(ops.compareTo("") != 0) {
int contrib = 100 / ops.length();
// Even approximate number close to 100 works
if(ops.contains(READS))
mainProps.put(READS, contrib);
else
mainProps.put(READS, 0);
if(ops.contains(WRITES))
mainProps.put(WRITES, contrib);
else
mainProps.put(WRITES, 0);
if(ops.contains(DELETES))
mainProps.put(DELETES, contrib);
else
mainProps.put(DELETES, 0);
if(ops.contains(MIXED))
mainProps.put(MIXED, contrib);
else
mainProps.put(MIXED, 0);
}
}
// Start the benchmark
Benchmark benchmark = null;
try {
benchmark = new Benchmark();
benchmark.initialize(mainProps);
benchmark.warmUpAndRun();
benchmark.close();
} catch(Exception e) {
if(options.has(VERBOSE)) {
e.printStackTrace();
}
parser.printHelpOn(System.err);
System.exit(-1);
}
}
public void close() {
this.factory.close();
}
private static void printUsage(OptionParser parser, String errorCommand) throws IOException {
parser.printHelpOn(System.err);
Utils.croak("Usage: $VOLDEMORT_HOME/bin/run-class.sh " + Benchmark.class.getName()
+ " [options] bootstrapUrl storeName num-requests\n " + errorCommand);
}
private static String checkOpsRatio(OptionSet options,
Props returnProps,
String currentOperation) {
if(options.has(currentOperation) && options.valueOf(currentOperation) == null) {
return currentOperation;
} else {
returnProps.put(currentOperation, CmdUtils.valueOf(options, currentOperation, 0));
return "";
}
}
}