From cf856077956c9852a56e91199f4c7c4d710c01a5 Mon Sep 17 00:00:00 2001 From: Guido Tagliavini Ponce Date: Fri, 3 Jun 2022 11:16:49 -0700 Subject: [PATCH] Add support for FastLRUCache in db_bench. (#10096) Summary: db_bench can now run with FastLRUCache. Pull Request resolved: https://github.com/facebook/rocksdb/pull/10096 Test Plan: - Temporarily add an ``assert(false)`` in the execution path that sets up the FastLRUCache. Run ``make -j24 db_bench``. Then test the appropriate code is used by running ``./db_bench -cache_type=fast_lru_cache`` and checking that the assert is called. Repeat for LRUCache. - Verify that FastLRUCache (currently a clone of LRUCache) produces similar benchmark data than LRUCache, by comparing the outputs of ``./db_bench -benchmarks=fillseq,fillrandom,readseq,readrandom -cache_type=fast_lru_cache`` and ``./db_bench -benchmarks=fillseq,fillrandom,readseq,readrandom -cache_type=lru_cache``. Reviewed By: gitbw95 Differential Revision: D36898774 Pulled By: guidotag fbshipit-source-id: f9f6b6f6da124f88b21b3c8dee742fbb04eff773 --- tools/db_bench_tool.cc | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/tools/db_bench_tool.cc b/tools/db_bench_tool.cc index bfddabe57..377460258 100644 --- a/tools/db_bench_tool.cc +++ b/tools/db_bench_tool.cc @@ -37,6 +37,7 @@ #include #include +#include "cache/fast_lru_cache.h" #include "db/db_impl/db_impl.h" #include "db/malloc_stats.h" #include "db/version_set.h" @@ -567,8 +568,7 @@ DEFINE_double(cache_high_pri_pool_ratio, 0.0, "If > 0.0, we also enable " "cache_index_and_filter_blocks_with_high_priority."); -DEFINE_bool(use_clock_cache, false, - "Replace default LRU block cache with clock cache."); +DEFINE_string(cache_type, "lru_cache", "Type of block cache."); DEFINE_bool(use_compressed_secondary_cache, false, "Use the CompressedSecondaryCache as the secondary cache."); @@ -2936,7 +2936,7 @@ class Benchmark { if (capacity <= 0) { return nullptr; } - if (FLAGS_use_clock_cache) { + if (FLAGS_cache_type == "clock_cache") { auto cache = NewClockCache(static_cast(capacity), FLAGS_cache_numshardbits); if (!cache) { @@ -2944,7 +2944,10 @@ class Benchmark { exit(1); } return cache; - } else { + } else if (FLAGS_cache_type == "fast_lru_cache") { + return NewFastLRUCache(static_cast(capacity), + FLAGS_cache_numshardbits); + } else if (FLAGS_cache_type == "lru_cache") { LRUCacheOptions opts( static_cast(capacity), FLAGS_cache_numshardbits, false /*strict_capacity_limit*/, FLAGS_cache_high_pri_pool_ratio, @@ -2993,6 +2996,9 @@ class Benchmark { } return NewLRUCache(opts); + } else { + fprintf(stderr, "Cache type not supported."); + exit(1); } }