@@ -29,14 +29,15 @@ using GFLAGS::ParseCommandLineFlags;
29
29
30
30
static const uint32_t KB = 1024 ;
31
31
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,
34
34
" Number of bytes to use as a cache of uncompressed data." );
35
35
DEFINE_int32 (num_shard_bits, 4 , " shard_bits." );
36
36
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" );
38
38
DEFINE_uint64 (ops_per_thread, 1200000 , " Number of operations per thread." );
39
39
40
+ DEFINE_bool (populate_cache, false , " Populate cache before operations" );
40
41
DEFINE_int32 (insert_percent, 40 ,
41
42
" Ratio of insert to total workload (expressed as a percentage)" );
42
43
DEFINE_int32 (lookup_percent, 50 ,
@@ -135,6 +136,18 @@ class CacheBench {
135
136
136
137
~CacheBench () {}
137
138
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
+
138
151
bool Run () {
139
152
rocksdb::Env* env = rocksdb::Env::Default ();
140
153
@@ -164,7 +177,10 @@ class CacheBench {
164
177
165
178
// Record end time
166
179
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);
168
184
}
169
185
return true ;
170
186
}
@@ -230,6 +246,7 @@ class CacheBench {
230
246
printf (" Cache size : %" PRIu64 " \n " , FLAGS_cache_size);
231
247
printf (" Num shard bits : %d\n " , FLAGS_num_shard_bits);
232
248
printf (" Max key : %" PRIu64 " \n " , FLAGS_max_key);
249
+ printf (" Populate cache : %d\n " , FLAGS_populate_cache);
233
250
printf (" Insert percentage : %d%%\n " , FLAGS_insert_percent);
234
251
printf (" Lookup percentage : %d%%\n " , FLAGS_lookup_percent);
235
252
printf (" Erase percentage : %d%%\n " , FLAGS_erase_percent);
@@ -247,6 +264,9 @@ int main(int argc, char** argv) {
247
264
}
248
265
249
266
rocksdb::CacheBench bench;
267
+ if (FLAGS_populate_cache) {
268
+ bench.PopulateCache ();
269
+ }
250
270
if (bench.Run ()) {
251
271
return 0 ;
252
272
} else {
0 commit comments