@ -159,6 +159,9 @@ static int FLAGS_level0_stop_writes_trigger = 12;
// Number of files in level-0 that will slow down writes.
// Number of files in level-0 that will slow down writes.
static int FLAGS_level0_slowdown_writes_trigger = 8 ;
static int FLAGS_level0_slowdown_writes_trigger = 8 ;
// Number of files in level-0 when compactions start
static int FLAGS_level0_file_num_compaction_trigger = 4 ;
// Ratio of reads to writes (expressed as a percentage)
// Ratio of reads to writes (expressed as a percentage)
// for the ReadRandomWriteRandom workload. The default
// for the ReadRandomWriteRandom workload. The default
// setting is 9 gets for every 1 put.
// setting is 9 gets for every 1 put.
@ -299,7 +302,7 @@ class Stats {
void SetId ( int id ) { id_ = id ; }
void SetId ( int id ) { id_ = id ; }
void FinishedSingleOp ( ) {
void FinishedSingleOp ( DB * db ) {
if ( FLAGS_histogram ) {
if ( FLAGS_histogram ) {
double now = FLAGS_env - > NowMicros ( ) ;
double now = FLAGS_env - > NowMicros ( ) ;
double micros = now - last_op_finish_ ;
double micros = now - last_op_finish_ ;
@ -326,12 +329,17 @@ class Stats {
} else {
} else {
double now = FLAGS_env - > NowMicros ( ) ;
double now = FLAGS_env - > NowMicros ( ) ;
fprintf ( stderr ,
fprintf ( stderr ,
" ... thread %d: %ld ops in %.6f seconds and %.2f ops/sec \n " ,
" ... thread %d: ( %ld,%ld) ops (interval,total) in %.6f seconds and %.2f ops/sec \n " ,
id_ ,
id_ ,
done_ - last_report_done_ ,
done_ - last_report_done_ , done_ ,
( now - last_report_finish_ ) / 1000000.0 ,
( now - last_report_finish_ ) / 1000000.0 ,
( done_ - last_report_done_ ) /
( done_ - last_report_done_ ) /
( ( now - last_report_finish_ ) / 1000000.0 ) ) ;
( ( now - last_report_finish_ ) / 1000000.0 ) ) ;
std : : string stats ;
if ( db & & db - > GetProperty ( " leveldb.stats " , & stats ) )
fprintf ( stderr , stats . c_str ( ) ) ;
fflush ( stderr ) ;
fflush ( stderr ) ;
next_report_ + = FLAGS_stats_interval ;
next_report_ + = FLAGS_stats_interval ;
last_report_finish_ = now ;
last_report_finish_ = now ;
@ -794,7 +802,7 @@ class Benchmark {
uint32_t crc = 0 ;
uint32_t crc = 0 ;
while ( bytes < 500 * 1048576 ) {
while ( bytes < 500 * 1048576 ) {
crc = crc32c : : Value ( data . data ( ) , size ) ;
crc = crc32c : : Value ( data . data ( ) , size ) ;
thread - > stats . FinishedSingleOp ( ) ;
thread - > stats . FinishedSingleOp ( NULL ) ;
bytes + = size ;
bytes + = size ;
}
}
// Print so result is not dead
// Print so result is not dead
@ -815,7 +823,7 @@ class Benchmark {
ptr = ap . Acquire_Load ( ) ;
ptr = ap . Acquire_Load ( ) ;
}
}
count + + ;
count + + ;
thread - > stats . FinishedSingleOp ( ) ;
thread - > stats . FinishedSingleOp ( NULL ) ;
}
}
if ( ptr = = NULL ) exit ( 1 ) ; // Disable unused variable warning.
if ( ptr = = NULL ) exit ( 1 ) ; // Disable unused variable warning.
}
}
@ -831,7 +839,7 @@ class Benchmark {
ok = port : : Snappy_Compress ( input . data ( ) , input . size ( ) , & compressed ) ;
ok = port : : Snappy_Compress ( input . data ( ) , input . size ( ) , & compressed ) ;
produced + = compressed . size ( ) ;
produced + = compressed . size ( ) ;
bytes + = input . size ( ) ;
bytes + = input . size ( ) ;
thread - > stats . FinishedSingleOp ( ) ;
thread - > stats . FinishedSingleOp ( NULL ) ;
}
}
if ( ! ok ) {
if ( ! ok ) {
@ -856,7 +864,7 @@ class Benchmark {
ok = port : : Snappy_Uncompress ( compressed . data ( ) , compressed . size ( ) ,
ok = port : : Snappy_Uncompress ( compressed . data ( ) , compressed . size ( ) ,
uncompressed ) ;
uncompressed ) ;
bytes + = input . size ( ) ;
bytes + = input . size ( ) ;
thread - > stats . FinishedSingleOp ( ) ;
thread - > stats . FinishedSingleOp ( NULL ) ;
}
}
delete [ ] uncompressed ;
delete [ ] uncompressed ;
@ -887,6 +895,8 @@ class Benchmark {
options . max_bytes_for_level_multiplier =
options . max_bytes_for_level_multiplier =
FLAGS_max_bytes_for_level_multiplier ;
FLAGS_max_bytes_for_level_multiplier ;
options . level0_stop_writes_trigger = FLAGS_level0_stop_writes_trigger ;
options . level0_stop_writes_trigger = FLAGS_level0_stop_writes_trigger ;
options . level0_file_num_compaction_trigger =
FLAGS_level0_file_num_compaction_trigger ;
options . level0_slowdown_writes_trigger =
options . level0_slowdown_writes_trigger =
FLAGS_level0_slowdown_writes_trigger ;
FLAGS_level0_slowdown_writes_trigger ;
options . compression = FLAGS_compression_type ;
options . compression = FLAGS_compression_type ;
@ -927,7 +937,7 @@ class Benchmark {
snprintf ( key , sizeof ( key ) , " %016d " , k ) ;
snprintf ( key , sizeof ( key ) , " %016d " , k ) ;
batch . Put ( key , gen . Generate ( value_size_ ) ) ;
batch . Put ( key , gen . Generate ( value_size_ ) ) ;
bytes + = value_size_ + strlen ( key ) ;
bytes + = value_size_ + strlen ( key ) ;
thread - > stats . FinishedSingleOp ( ) ;
thread - > stats . FinishedSingleOp ( db_ ) ;
}
}
s = db_ - > Write ( write_options_ , & batch ) ;
s = db_ - > Write ( write_options_ , & batch ) ;
if ( ! s . ok ( ) ) {
if ( ! s . ok ( ) ) {
@ -944,7 +954,7 @@ class Benchmark {
int64_t bytes = 0 ;
int64_t bytes = 0 ;
for ( iter - > SeekToFirst ( ) ; i < reads_ & & iter - > Valid ( ) ; iter - > Next ( ) ) {
for ( iter - > SeekToFirst ( ) ; i < reads_ & & iter - > Valid ( ) ; iter - > Next ( ) ) {
bytes + = iter - > key ( ) . size ( ) + iter - > value ( ) . size ( ) ;
bytes + = iter - > key ( ) . size ( ) + iter - > value ( ) . size ( ) ;
thread - > stats . FinishedSingleOp ( ) ;
thread - > stats . FinishedSingleOp ( db_ ) ;
+ + i ;
+ + i ;
}
}
delete iter ;
delete iter ;
@ -957,7 +967,7 @@ class Benchmark {
int64_t bytes = 0 ;
int64_t bytes = 0 ;
for ( iter - > SeekToLast ( ) ; i < reads_ & & iter - > Valid ( ) ; iter - > Prev ( ) ) {
for ( iter - > SeekToLast ( ) ; i < reads_ & & iter - > Valid ( ) ; iter - > Prev ( ) ) {
bytes + = iter - > key ( ) . size ( ) + iter - > value ( ) . size ( ) ;
bytes + = iter - > key ( ) . size ( ) + iter - > value ( ) . size ( ) ;
thread - > stats . FinishedSingleOp ( ) ;
thread - > stats . FinishedSingleOp ( db_ ) ;
+ + i ;
+ + i ;
}
}
delete iter ;
delete iter ;
@ -975,7 +985,7 @@ class Benchmark {
if ( db_ - > Get ( options , key , & value ) . ok ( ) ) {
if ( db_ - > Get ( options , key , & value ) . ok ( ) ) {
found + + ;
found + + ;
}
}
thread - > stats . FinishedSingleOp ( ) ;
thread - > stats . FinishedSingleOp ( db_ ) ;
}
}
char msg [ 100 ] ;
char msg [ 100 ] ;
snprintf ( msg , sizeof ( msg ) , " (%ld of %ld found) " , found , num_ ) ;
snprintf ( msg , sizeof ( msg ) , " (%ld of %ld found) " , found , num_ ) ;
@ -990,7 +1000,7 @@ class Benchmark {
const int k = thread - > rand . Next ( ) % FLAGS_num ;
const int k = thread - > rand . Next ( ) % FLAGS_num ;
snprintf ( key , sizeof ( key ) , " %016d. " , k ) ;
snprintf ( key , sizeof ( key ) , " %016d. " , k ) ;
db_ - > Get ( options , key , & value ) ;
db_ - > Get ( options , key , & value ) ;
thread - > stats . FinishedSingleOp ( ) ;
thread - > stats . FinishedSingleOp ( db_ ) ;
}
}
}
}
@ -1003,7 +1013,7 @@ class Benchmark {
const int k = thread - > rand . Next ( ) % range ;
const int k = thread - > rand . Next ( ) % range ;
snprintf ( key , sizeof ( key ) , " %016d " , k ) ;
snprintf ( key , sizeof ( key ) , " %016d " , k ) ;
db_ - > Get ( options , key , & value ) ;
db_ - > Get ( options , key , & value ) ;
thread - > stats . FinishedSingleOp ( ) ;
thread - > stats . FinishedSingleOp ( db_ ) ;
}
}
}
}
@ -1019,7 +1029,7 @@ class Benchmark {
iter - > Seek ( key ) ;
iter - > Seek ( key ) ;
if ( iter - > Valid ( ) & & iter - > key ( ) = = key ) found + + ;
if ( iter - > Valid ( ) & & iter - > key ( ) = = key ) found + + ;
delete iter ;
delete iter ;
thread - > stats . FinishedSingleOp ( ) ;
thread - > stats . FinishedSingleOp ( db_ ) ;
}
}
char msg [ 100 ] ;
char msg [ 100 ] ;
snprintf ( msg , sizeof ( msg ) , " (%ld of %ld found) " , found , num_ ) ;
snprintf ( msg , sizeof ( msg ) , " (%ld of %ld found) " , found , num_ ) ;
@ -1037,7 +1047,7 @@ class Benchmark {
char key [ 100 ] ;
char key [ 100 ] ;
snprintf ( key , sizeof ( key ) , " %016d " , k ) ;
snprintf ( key , sizeof ( key ) , " %016d " , k ) ;
batch . Delete ( key ) ;
batch . Delete ( key ) ;
thread - > stats . FinishedSingleOp ( ) ;
thread - > stats . FinishedSingleOp ( db_ ) ;
}
}
s = db_ - > Write ( write_options_ , & batch ) ;
s = db_ - > Write ( write_options_ , & batch ) ;
if ( ! s . ok ( ) ) {
if ( ! s . ok ( ) ) {
@ -1126,7 +1136,7 @@ class Benchmark {
put_weight - - ;
put_weight - - ;
writes_done + + ;
writes_done + + ;
}
}
thread - > stats . FinishedSingleOp ( ) ;
thread - > stats . FinishedSingleOp ( db_ ) ;
}
}
char msg [ 100 ] ;
char msg [ 100 ] ;
snprintf ( msg , sizeof ( msg ) , " ( reads:%ld writes:%ld total:%ld ) " ,
snprintf ( msg , sizeof ( msg ) , " ( reads:%ld writes:%ld total:%ld ) " ,
@ -1281,6 +1291,9 @@ int main(int argc, char** argv) {
} else if ( sscanf ( argv [ i ] , " --level0_slowdown_writes_trigger=%d%c " ,
} else if ( sscanf ( argv [ i ] , " --level0_slowdown_writes_trigger=%d%c " ,
& n , & junk ) = = 1 ) {
& n , & junk ) = = 1 ) {
FLAGS_level0_slowdown_writes_trigger = n ;
FLAGS_level0_slowdown_writes_trigger = n ;
} else if ( sscanf ( argv [ i ] , " --level0_file_num_compaction_trigger=%d%c " ,
& n , & junk ) = = 1 ) {
FLAGS_level0_file_num_compaction_trigger = n ;
} else if ( strncmp ( argv [ i ] , " --compression_type= " , 19 ) = = 0 ) {
} else if ( strncmp ( argv [ i ] , " --compression_type= " , 19 ) = = 0 ) {
const char * ctype = argv [ i ] + 19 ;
const char * ctype = argv [ i ] + 19 ;
if ( ! strcasecmp ( ctype , " none " ) )
if ( ! strcasecmp ( ctype , " none " ) )