db_bench: Better way to randomize repeated read keys in -read_random_exp_range
Summary: Use a better way to map from a key with locality to a random location. Now with the same -read_random_exp_range setting, hit rate drops, which it is expected. Test Plan: ./db_bench --benchmarks=readrandom -statistics -use_existing_db -cache_size=5000000 --read_random_exp_range=<multiple_values> Reviewers: MarkCallaghan, kradhakrishnan, igor Reviewed By: igor Subscribers: leveldb, dhruba Differential Revision: https://reviews.facebook.net/D34761
This commit is contained in:
parent
284be570c8
commit
2884b100ba
@ -2490,17 +2490,12 @@ class Benchmark {
|
|||||||
static_cast<long double>(kBigInt) *
|
static_cast<long double>(kBigInt) *
|
||||||
read_random_exp_range_;
|
read_random_exp_range_;
|
||||||
long double exp_ran = std::exp(order);
|
long double exp_ran = std::exp(order);
|
||||||
key_rand =
|
uint64_t rand_num =
|
||||||
static_cast<int64_t>(exp_ran * static_cast<long double>(FLAGS_num));
|
static_cast<int64_t>(exp_ran * static_cast<long double>(FLAGS_num));
|
||||||
|
// Map to a different number to avoid locality.
|
||||||
if (FLAGS_num > 256) {
|
const uint64_t kBigPrime = 0x5bd1e995;
|
||||||
// Put least signifant byte to highest significant so that key
|
// Overflow is like %(2^64). Will have little impact of results.
|
||||||
// range is distributed.
|
key_rand = static_cast<int64_t>((rand_num * kBigPrime) % FLAGS_num);
|
||||||
key_rand = key_rand / 256 + FLAGS_num / 256 * (key_rand % 256);
|
|
||||||
if (key_rand >= FLAGS_num) {
|
|
||||||
key_rand = FLAGS_num - 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return key_rand;
|
return key_rand;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user