@@ -162,6 +162,15 @@ enum DBState {
162
162
EXISTING
163
163
}
164
164
165
+ enum CompressionType {
166
+ NONE ,
167
+ SNAPPY ,
168
+ ZLIB ,
169
+ BZIP2 ,
170
+ LZ4 ,
171
+ LZ4HC
172
+ }
173
+
165
174
static {
166
175
System .loadLibrary ("rocksdbjni" );
167
176
}
@@ -435,7 +444,6 @@ public DbBenchmark(Map<Flag, Object> flags) throws Exception {
435
444
databaseDir_ = (String ) flags .get (Flag .db );
436
445
writesPerSeconds_ = (Integer ) flags .get (Flag .writes_per_second );
437
446
cacheSize_ = (Long ) flags .get (Flag .cache_size );
438
- gen_ = new RandomGenerator (randSeed_ , compressionRatio_ );
439
447
memtable_ = (String ) flags .get (Flag .memtablerep );
440
448
maxWriteBufferNumber_ = (Integer ) flags .get (Flag .max_write_buffer_number );
441
449
prefixSize_ = (Integer ) flags .get (Flag .prefix_size );
@@ -446,6 +454,28 @@ public DbBenchmark(Map<Flag, Object> flags) throws Exception {
446
454
finishLock_ = new Object ();
447
455
// options.setPrefixSize((Integer)flags_.get(Flag.prefix_size));
448
456
// options.setKeysPerPrefix((Long)flags_.get(Flag.keys_per_prefix));
457
+ compressionType_ = (String ) flags .get (Flag .compression_type );
458
+ compression_ = CompressionType .NONE ;
459
+ try {
460
+ if (compressionType_ .equals ("snappy" )) {
461
+ System .loadLibrary ("snappy" );
462
+ } else if (compressionType_ .equals ("zlib" )) {
463
+ System .loadLibrary ("zlib" );
464
+ } else if (compressionType_ .equals ("bzip2" )) {
465
+ System .loadLibrary ("bzip2" );
466
+ } else if (compressionType_ .equals ("lz4" )) {
467
+ System .loadLibrary ("lz4" );
468
+ } else if (compressionType_ .equals ("lz4hc" )) {
469
+ System .loadLibrary ("lz4hc" );
470
+ }
471
+ } catch (UnsatisfiedLinkError e ) {
472
+ System .err .format ("Unable to load %s library:%s%n" +
473
+ "No compression is used.%n" ,
474
+ compressionType_ , e .toString ());
475
+ compressionType_ = "none" ;
476
+ compressionRatio_ = 1.0 ;
477
+ }
478
+ gen_ = new RandomGenerator (randSeed_ , compressionRatio_ );
449
479
}
450
480
451
481
private void prepareReadOptions (ReadOptions options ) {
@@ -462,6 +492,8 @@ private void prepareOptions(Options options) {
462
492
options .setCacheSize (cacheSize_ );
463
493
if (!useExisting_ ) {
464
494
options .setCreateIfMissing (true );
495
+ } else {
496
+ options .setCreateIfMissing (false );
465
497
}
466
498
if (memtable_ .equals ("skip_list" )) {
467
499
options .setMemTableConfig (new SkipListMemTableConfig ());
@@ -488,6 +520,8 @@ private void prepareOptions(Options options) {
488
520
options .setTableFormatConfig (
489
521
new PlainTableConfig ().setKeySize (keySize_ ));
490
522
}
523
+ options .setWriteBufferSize (
524
+ (Long )flags_ .get (Flag .write_buffer_size ));
491
525
options .setMaxWriteBufferNumber (
492
526
(Integer )flags_ .get (Flag .max_write_buffer_number ));
493
527
options .setMaxBackgroundCompactions (
@@ -513,7 +547,7 @@ private void prepareOptions(Options options) {
513
547
options .setDisableSeekCompaction (
514
548
(Boolean )flags_ .get (Flag .disable_seek_compaction ));
515
549
options .setDeleteObsoleteFilesPeriodMicros (
516
- (Long )flags_ .get (Flag .delete_obsolete_files_period_micros ));
550
+ (Integer )flags_ .get (Flag .delete_obsolete_files_period_micros ));
517
551
options .setTableCacheNumshardbits (
518
552
(Integer )flags_ .get (Flag .table_cache_numshardbits ));
519
553
options .setAllowMmapReads (
@@ -640,12 +674,12 @@ private void run() throws RocksDBException {
640
674
} else if (benchmark .equals ("readseq" )) {
641
675
for (int t = 0 ; t < threadNum_ ; ++t ) {
642
676
tasks .add (new ReadSequentialTask (
643
- currentTaskId ++, randSeed_ , reads_ , num_ ));
677
+ currentTaskId ++, randSeed_ , reads_ / threadNum_ , num_ ));
644
678
}
645
679
} else if (benchmark .equals ("readrandom" )) {
646
680
for (int t = 0 ; t < threadNum_ ; ++t ) {
647
681
tasks .add (new ReadRandomTask (
648
- currentTaskId ++, randSeed_ , reads_ , num_ ));
682
+ currentTaskId ++, randSeed_ , reads_ / threadNum_ , num_ ));
649
683
}
650
684
} else if (benchmark .equals ("readwhilewriting" )) {
651
685
WriteTask writeTask = new WriteRandomTask (
@@ -717,12 +751,12 @@ private void printHeader(Options options) {
717
751
(int ) (valueSize_ * compressionRatio_ + 0.5 ));
718
752
System .out .printf ("Entries: %d\n " , num_ );
719
753
System .out .printf ("RawSize: %.1f MB (estimated)\n " ,
720
- ((kKeySize + valueSize_ ) * num_ ) / 1048576.0 );
754
+ ((double )( kKeySize + valueSize_ ) * num_ ) / SizeUnit . MB );
721
755
System .out .printf ("FileSize: %.1f MB (estimated)\n " ,
722
- (((kKeySize + valueSize_ * compressionRatio_ ) * num_ )
723
- / 1048576.0 ));
756
+ (((kKeySize + valueSize_ * compressionRatio_ ) * num_ ) / SizeUnit .MB ));
724
757
System .out .format ("Memtable Factory: %s%n" , options .memTableFactoryName ());
725
758
System .out .format ("Prefix: %d bytes%n" , prefixSize_ );
759
+ System .out .format ("Compression: %s%n" , compressionType_ );
726
760
printWarnings ();
727
761
System .out .printf ("------------------------------------------------\n " );
728
762
}
@@ -769,7 +803,7 @@ private void stop(
769
803
770
804
System .out .printf (
771
805
"%-16s : %11.5f micros/op; %6.1f MB/s; %d / %d task(s) finished.\n " ,
772
- benchmark , elapsedSeconds * 1e6 / stats .done_ ,
806
+ benchmark , ( double ) elapsedSeconds / stats .done_ * 1e6 ,
773
807
(stats .bytes_ / 1048576.0 ) / elapsedSeconds ,
774
808
taskFinishedCount , concurrentThreads );
775
809
}
@@ -932,7 +966,7 @@ private enum Flag {
932
966
return Integer .parseInt (value );
933
967
}
934
968
},
935
- write_buffer_size (4 << 20 ,
969
+ write_buffer_size (4 * SizeUnit . MB ,
936
970
"Number of bytes to buffer in memtable before compacting\n " +
937
971
"\t (initialized to default value by 'main'.)" ) {
938
972
@ Override public Object parseValue (String value ) {
@@ -1275,11 +1309,17 @@ private enum Flag {
1275
1309
return Boolean .parseBoolean (value );
1276
1310
}
1277
1311
},
1278
- delete_obsolete_files_period_micros (0L ,"Option to delete\n " +
1312
+ delete_obsolete_files_period_micros (0 ,"Option to delete\n " +
1279
1313
"\t obsolete files periodically. 0 means that obsolete files are\n " +
1280
1314
"\t deleted after every compaction run." ) {
1281
1315
@ Override public Object parseValue (String value ) {
1282
- return Long .parseLong (value );
1316
+ return Integer .parseInt (value );
1317
+ }
1318
+ },
1319
+ compression_type ("snappy" ,
1320
+ "Algorithm used to compress the database." ) {
1321
+ @ Override public Object parseValue (String value ) {
1322
+ return value ;
1283
1323
}
1284
1324
},
1285
1325
compression_level (-1 ,
@@ -1512,7 +1552,7 @@ void setFinished(boolean flag) {
1512
1552
final long cacheSize_ ;
1513
1553
final boolean useExisting_ ;
1514
1554
final String databaseDir_ ;
1515
- final double compressionRatio_ ;
1555
+ double compressionRatio_ ;
1516
1556
RandomGenerator gen_ ;
1517
1557
long startTime_ ;
1518
1558
@@ -1532,4 +1572,6 @@ void setFinished(boolean flag) {
1532
1572
// as the scope of a static member equals to the scope of the problem,
1533
1573
// we let its c++ pointer to be disposed in its finalizer.
1534
1574
static Options defaultOptions_ = new Options ();
1575
+ String compressionType_ ;
1576
+ CompressionType compression_ ;
1535
1577
}
0 commit comments