From eb99e080760bf86a9fd2b725df2fdeb1dd4df884 Mon Sep 17 00:00:00 2001 From: Guido Tagliavini Ponce Date: Fri, 3 Jun 2022 13:40:09 -0700 Subject: [PATCH] Add support for FastLRUCache in cache_bench (#10095) Summary: cache_bench can now run with FastLRUCache. Pull Request resolved: https://github.com/facebook/rocksdb/pull/10095 Test Plan: - Temporarily add an ``assert(false)`` in the execution path that sets up the FastLRUCache. Run ``make -j24 cache_bench``. Then test the appropriate code is used by running ``./cache_bench -cache_type=fast_lru_cache`` and checking that the assert is called. Repeat for LRUCache. - Verify that FastLRUCache (currently a clone of LRUCache) has similar latency distribution than LRUCache, by comparing the outputs of ``./cache_bench -cache_type=fast_lru_cache`` and ``./cache_bench -cache_type=lru_cache``. Reviewed By: pdillinger Differential Revision: D36875834 Pulled By: guidotag fbshipit-source-id: eb2ad0bb32c2717a258a6ac66ed736e06f826cd8 --- cache/cache_bench_tool.cc | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/cache/cache_bench_tool.cc b/cache/cache_bench_tool.cc index cd9fac3d9..4f739be2a 100644 --- a/cache/cache_bench_tool.cc +++ b/cache/cache_bench_tool.cc @@ -12,6 +12,7 @@ #include #include +#include "cache/fast_lru_cache.h" #include "db/db_impl/db_impl.h" #include "monitoring/histogram.h" #include "port/port.h" @@ -76,7 +77,7 @@ DEFINE_string(secondary_cache_uri, "", static class std::shared_ptr secondary_cache; #endif // ROCKSDB_LITE -DEFINE_bool(use_clock_cache, false, ""); +DEFINE_string(cache_type, "lru_cache", "Type of block cache."); // ## BEGIN stress_cache_key sub-tool options ## // See class StressCacheKey below. @@ -279,13 +280,15 @@ class CacheBench { if (max_key > (static_cast(1) << max_log_)) max_log_++; } - if (FLAGS_use_clock_cache) { + if (FLAGS_cache_type == "clock_cache") { cache_ = NewClockCache(FLAGS_cache_size, FLAGS_num_shard_bits); if (!cache_) { fprintf(stderr, "Clock cache not supported.\n"); exit(1); } - } else { + } else if (FLAGS_cache_type == "fast_lru_cache") { + cache_ = NewFastLRUCache(FLAGS_cache_size, FLAGS_num_shard_bits); + } else if (FLAGS_cache_type == "lru_cache") { LRUCacheOptions opts(FLAGS_cache_size, FLAGS_num_shard_bits, false, 0.5); #ifndef ROCKSDB_LITE if (!FLAGS_secondary_cache_uri.empty()) { @@ -303,6 +306,9 @@ class CacheBench { #endif // ROCKSDB_LITE cache_ = NewLRUCache(opts); + } else { + fprintf(stderr, "Cache type not supported."); + exit(1); } }