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
main
sdong 10 years ago
parent 284be570c8
commit 2884b100ba
  1. 15
      db/db_bench.cc

@ -2490,17 +2490,12 @@ class Benchmark {
static_cast<long double>(kBigInt) *
read_random_exp_range_;
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));
if (FLAGS_num > 256) {
// Put least signifant byte to highest significant so that key
// range is distributed.
key_rand = key_rand / 256 + FLAGS_num / 256 * (key_rand % 256);
if (key_rand >= FLAGS_num) {
key_rand = FLAGS_num - 1;
}
}
// Map to a different number to avoid locality.
const uint64_t kBigPrime = 0x5bd1e995;
// Overflow is like %(2^64). Will have little impact of results.
key_rand = static_cast<int64_t>((rand_num * kBigPrime) % FLAGS_num);
}
return key_rand;
}

Loading…
Cancel
Save