Skip to content

Commit 53404d9

Browse files
author
Feng Zhu
committed
add_qps_info_in cache bench
Summary: print qps in summary Test Plan: ./cache_bench Reviewers: yhchiang, ljin, sdong, igor Reviewed By: igor Subscribers: leveldb Differential Revision: https://reviews.facebook.net/D23079
1 parent a52cecb commit 53404d9

File tree

1 file changed

+24
-4
lines changed

1 file changed

+24
-4
lines changed

util/cache_bench.cc

+24-4
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,15 @@ using GFLAGS::ParseCommandLineFlags;
2929

3030
static const uint32_t KB = 1024;
3131

32-
DEFINE_int32(threads, 10, "Number of concurrent threads to run.");
33-
DEFINE_int64(cache_size, 2 * KB * KB * KB,
32+
DEFINE_int32(threads, 16, "Number of concurrent threads to run.");
33+
DEFINE_int64(cache_size, 8 * KB * KB,
3434
"Number of bytes to use as a cache of uncompressed data.");
3535
DEFINE_int32(num_shard_bits, 4, "shard_bits.");
3636

37-
DEFINE_int64(max_key, 1 * KB* KB, "Max number of key to place in cache");
37+
DEFINE_int64(max_key, 1 * KB * KB * KB, "Max number of key to place in cache");
3838
DEFINE_uint64(ops_per_thread, 1200000, "Number of operations per thread.");
3939

40+
DEFINE_bool(populate_cache, false, "Populate cache before operations");
4041
DEFINE_int32(insert_percent, 40,
4142
"Ratio of insert to total workload (expressed as a percentage)");
4243
DEFINE_int32(lookup_percent, 50,
@@ -135,6 +136,18 @@ class CacheBench {
135136

136137
~CacheBench() {}
137138

139+
void PopulateCache() {
140+
Random rnd(1);
141+
for (int64_t i = 0; i < FLAGS_cache_size; i++) {
142+
uint64_t rand_key = rnd.Next() % FLAGS_max_key;
143+
// Cast uint64* to be char*, data would be copied to cache
144+
Slice key(reinterpret_cast<char*>(&rand_key), 8);
145+
// do insert
146+
auto handle = cache_->Insert(key, new char[10], 1, &deleter);
147+
cache_->Release(handle);
148+
}
149+
}
150+
138151
bool Run() {
139152
rocksdb::Env* env = rocksdb::Env::Default();
140153

@@ -164,7 +177,10 @@ class CacheBench {
164177

165178
// Record end time
166179
uint64_t end_time = env->NowMicros();
167-
fprintf(stdout, "Complete in %" PRIu64 "ms\n", end_time - start_time);
180+
double elapsed = static_cast<double>(end_time - start_time) * 1e-6;
181+
uint32_t qps = static_cast<uint32_t>(
182+
static_cast<double>(FLAGS_threads * FLAGS_ops_per_thread) / elapsed);
183+
fprintf(stdout, "Complete in %.3f s; QPS = %u\n", elapsed, qps);
168184
}
169185
return true;
170186
}
@@ -230,6 +246,7 @@ class CacheBench {
230246
printf("Cache size : %" PRIu64 "\n", FLAGS_cache_size);
231247
printf("Num shard bits : %d\n", FLAGS_num_shard_bits);
232248
printf("Max key : %" PRIu64 "\n", FLAGS_max_key);
249+
printf("Populate cache : %d\n", FLAGS_populate_cache);
233250
printf("Insert percentage : %d%%\n", FLAGS_insert_percent);
234251
printf("Lookup percentage : %d%%\n", FLAGS_lookup_percent);
235252
printf("Erase percentage : %d%%\n", FLAGS_erase_percent);
@@ -247,6 +264,9 @@ int main(int argc, char** argv) {
247264
}
248265

249266
rocksdb::CacheBench bench;
267+
if (FLAGS_populate_cache) {
268+
bench.PopulateCache();
269+
}
250270
if (bench.Run()) {
251271
return 0;
252272
} else {

0 commit comments

Comments
 (0)