@ -571,36 +571,34 @@ static void DBGet(benchmark::State& state) {
options . table_factory . reset ( NewBlockBasedTableFactory ( table_options ) ) ;
options . table_factory . reset ( NewBlockBasedTableFactory ( table_options ) ) ;
auto rnd = Random ( 301 + state . thread_index ( ) ) ;
auto rnd = Random ( 301 + state . thread_index ( ) ) ;
KeyGenerator kg ( & rnd , key_num ) ;
if ( state . thread_index ( ) = = 0 ) {
if ( state . thread_index ( ) = = 0 ) {
KeyGenerator kg_seq ( key_num /* max_key */ ) ;
SetupDB ( state , options , & db , " DBGet " ) ;
SetupDB ( state , options , & db , " DBGet " ) ;
// load db
// Load all valid keys into DB. That way, iterations in `!negative_query`
// runs can always find the key even though it is generated from a random
// number.
auto wo = WriteOptions ( ) ;
auto wo = WriteOptions ( ) ;
wo . disableWAL = true ;
wo . disableWAL = true ;
for ( uint64_t i = 0 ; i < key_num ; i + + ) {
for ( uint64_t i = 0 ; i < key_num ; i + + ) {
Status s = db - > Put ( wo , kg . Next ( ) ,
Status s = db - > Put ( wo , kg_seq . Next ( ) ,
rnd . RandomString ( static_cast < int > ( per_key_size ) ) ) ;
rnd . RandomString ( static_cast < int > ( per_key_size ) ) ) ;
if ( ! s . ok ( ) ) {
if ( ! s . ok ( ) ) {
state . SkipWithError ( s . ToString ( ) . c_str ( ) ) ;
state . SkipWithError ( s . ToString ( ) . c_str ( ) ) ;
}
}
}
}
FlushOptions fo ;
// Compact whole DB into one level, so each iteration will consider the same
Status s = db - > Flush ( fo ) ;
// number of files (one).
Status s = db - > CompactRange ( CompactRangeOptions ( ) , nullptr /* begin */ ,
nullptr /* end */ ) ;
if ( ! s . ok ( ) ) {
if ( ! s . ok ( ) ) {
state . SkipWithError ( s . ToString ( ) . c_str ( ) ) ;
state . SkipWithError ( s . ToString ( ) . c_str ( ) ) ;
}
}
auto db_full = static_cast_with_check < DBImpl > ( db . get ( ) ) ;
s = db_full - > WaitForCompact ( WaitForCompactOptions ( ) ) ;
if ( ! s . ok ( ) ) {
state . SkipWithError ( s . ToString ( ) . c_str ( ) ) ;
return ;
}
}
}
KeyGenerator kg_rnd ( & rnd , key_num /* max_key */ ) ;
auto ro = ReadOptions ( ) ;
auto ro = ReadOptions ( ) ;
if ( mmap ) {
if ( mmap ) {
ro . verify_checksums = false ;
ro . verify_checksums = false ;
@ -609,7 +607,7 @@ static void DBGet(benchmark::State& state) {
if ( negative_query ) {
if ( negative_query ) {
for ( auto _ : state ) {
for ( auto _ : state ) {
std : : string val ;
std : : string val ;
Status s = db - > Get ( ro , kg . NextNonExist ( ) , & val ) ;
Status s = db - > Get ( ro , kg_rnd . NextNonExist ( ) , & val ) ;
if ( s . IsNotFound ( ) ) {
if ( s . IsNotFound ( ) ) {
not_found + + ;
not_found + + ;
}
}
@ -617,7 +615,7 @@ static void DBGet(benchmark::State& state) {
} else {
} else {
for ( auto _ : state ) {
for ( auto _ : state ) {
std : : string val ;
std : : string val ;
Status s = db - > Get ( ro , kg . Next ( ) , & val ) ;
Status s = db - > Get ( ro , kg_rnd . Next ( ) , & val ) ;
if ( s . IsNotFound ( ) ) {
if ( s . IsNotFound ( ) ) {
not_found + + ;
not_found + + ;
}
}
@ -636,7 +634,7 @@ static void DBGet(benchmark::State& state) {
state . counters [ " get_p99 " ] = histogram_data . percentile99 * std : : milli : : den ;
state . counters [ " get_p99 " ] = histogram_data . percentile99 * std : : milli : : den ;
}
}
TeardownDB ( state , db , options , kg ) ;
TeardownDB ( state , db , options , kg_rnd ) ;
}
}
}
}
@ -662,9 +660,8 @@ static void DBGetArguments(benchmark::internal::Benchmark* b) {
" negative_query " , " enable_filter " , " mmap " } ) ;
" negative_query " , " enable_filter " , " mmap " } ) ;
}
}
static constexpr uint64_t kDBGetNum = 1l < < 20 ;
BENCHMARK ( DBGet ) - > Threads ( 1 ) - > Apply ( DBGetArguments ) ;
BENCHMARK ( DBGet ) - > Threads ( 1 ) - > Iterations ( kDBGetNum ) - > Apply ( DBGetArguments ) ;
BENCHMARK ( DBGet ) - > Threads ( 8 ) - > Apply ( DBGetArguments ) ;
BENCHMARK ( DBGet ) - > Threads ( 8 ) - > Iterations ( kDBGetNum / 8 ) - > Apply ( DBGetArguments ) ;
static void SimpleGetWithPerfContext ( benchmark : : State & state ) {
static void SimpleGetWithPerfContext ( benchmark : : State & state ) {
// setup DB
// setup DB