Skip to content

Commit

Permalink
Add lean option to cache_bench (#10363)
Browse files Browse the repository at this point in the history
Summary:
Sometimes we may not want to include extra computation in our cache_bench experiments. Here we add a flag to avoid any extra work. We also moved the timer start after the key generation.

Pull Request resolved: #10363

Test Plan: Run cache_bench with and without the new flag and check that the appropriate code is being executed.

Reviewed By: pdillinger

Differential Revision: D37870416

Pulled By: guidotag

fbshipit-source-id: f853207b6643b9328e774251c3f679b1fd78a11a
  • Loading branch information
Guido Tagliavini Ponce authored and facebook-github-bot committed Jul 15, 2022
1 parent 00e68e7 commit a543773
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions cache/cache_bench_tool.cc
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ DEFINE_uint32(
DEFINE_uint32(gather_stats_entries_per_lock, 256,
"For Cache::ApplyToAllEntries");
DEFINE_bool(skewed, false, "If true, skew the key access distribution");

DEFINE_bool(lean, false,
"If true, no additional computation is performed besides cache "
"operations.");

#ifndef ROCKSDB_LITE
DEFINE_string(secondary_cache_uri, "",
"Full URI for creating a custom secondary cache object");
Expand Down Expand Up @@ -522,7 +527,6 @@ class CacheBench {
StopWatchNano timer(clock);

for (uint64_t i = 0; i < FLAGS_ops_per_thread; i++) {
timer.Start();
Slice key = gen.GetRand(thread->rnd, max_key_, max_log_);
uint64_t random_op = thread->rnd.Next();
Cache::CreateCallback create_cb = [](const void* buf, size_t size,
Expand All @@ -534,6 +538,8 @@ class CacheBench {
return Status::OK();
};

timer.Start();

if (random_op < lookup_insert_threshold_) {
if (handle) {
cache_->Release(handle);
Expand All @@ -543,9 +549,11 @@ class CacheBench {
handle = cache_->Lookup(key, &helper2, create_cb, Cache::Priority::LOW,
true);
if (handle) {
// do something with the data
result += NPHash64(static_cast<char*>(cache_->Value(handle)),
FLAGS_value_bytes);
if (!FLAGS_lean) {
// do something with the data
result += NPHash64(static_cast<char*>(cache_->Value(handle)),
FLAGS_value_bytes);
}
} else {
// do insert
Status s = cache_->Insert(key, createValue(thread->rnd), &helper2,
Expand All @@ -570,9 +578,11 @@ class CacheBench {
handle = cache_->Lookup(key, &helper2, create_cb, Cache::Priority::LOW,
true);
if (handle) {
// do something with the data
result += NPHash64(static_cast<char*>(cache_->Value(handle)),
FLAGS_value_bytes);
if (!FLAGS_lean) {
// do something with the data
result += NPHash64(static_cast<char*>(cache_->Value(handle)),
FLAGS_value_bytes);
}
}
} else if (random_op < erase_threshold_) {
// do erase
Expand Down

0 comments on commit a543773

Please sign in to comment.