Add a new per level counter for block cache hit (#4796)

Summary:
Add a new per level counter for block cache hits, increase it by one on every successful attempt to get an entry from cache.
Pull Request resolved: https://github.com/facebook/rocksdb/pull/4796

Differential Revision: D13513688

Pulled By: zinoale

fbshipit-source-id: 104df038f1232e3356e162eb2d8ca138e34a8281
main
Alexander Zinoviev 6 years ago committed by Facebook Github Bot
parent e0be1bc4f1
commit 80bf8975fd
  1. 16
      db/perf_context_test.cc
  2. 3
      include/rocksdb/perf_context.h
  3. 4
      monitoring/perf_context.cc
  4. 13
      table/block_based_table_reader.cc

@ -696,6 +696,10 @@ TEST_F(PerfContextTest, PerfContextByLevelGetSet) {
PERF_COUNTER_BY_LEVEL_ADD(bloom_filter_useful, 1, 7); PERF_COUNTER_BY_LEVEL_ADD(bloom_filter_useful, 1, 7);
PERF_COUNTER_BY_LEVEL_ADD(bloom_filter_useful, 1, 7); PERF_COUNTER_BY_LEVEL_ADD(bloom_filter_useful, 1, 7);
PERF_COUNTER_BY_LEVEL_ADD(bloom_filter_full_true_positive, 1, 2); PERF_COUNTER_BY_LEVEL_ADD(bloom_filter_full_true_positive, 1, 2);
PERF_COUNTER_BY_LEVEL_ADD(block_cache_hit_count, 1, 0);
PERF_COUNTER_BY_LEVEL_ADD(block_cache_hit_count, 5, 2);
PERF_COUNTER_BY_LEVEL_ADD(block_cache_miss_count, 2, 3);
PERF_COUNTER_BY_LEVEL_ADD(block_cache_miss_count, 4, 1);
ASSERT_EQ( ASSERT_EQ(
0, (*(get_perf_context()->level_to_perf_context))[0].bloom_filter_useful); 0, (*(get_perf_context()->level_to_perf_context))[0].bloom_filter_useful);
ASSERT_EQ( ASSERT_EQ(
@ -706,6 +710,14 @@ TEST_F(PerfContextTest, PerfContextByLevelGetSet) {
.bloom_filter_full_positive); .bloom_filter_full_positive);
ASSERT_EQ(1, (*(get_perf_context()->level_to_perf_context))[2] ASSERT_EQ(1, (*(get_perf_context()->level_to_perf_context))[2]
.bloom_filter_full_true_positive); .bloom_filter_full_true_positive);
ASSERT_EQ(1, (*(get_perf_context()->level_to_perf_context))[0]
.block_cache_hit_count);
ASSERT_EQ(5, (*(get_perf_context()->level_to_perf_context))[2]
.block_cache_hit_count);
ASSERT_EQ(2, (*(get_perf_context()->level_to_perf_context))[3]
.block_cache_miss_count);
ASSERT_EQ(4, (*(get_perf_context()->level_to_perf_context))[1]
.block_cache_miss_count);
std::string zero_excluded = get_perf_context()->ToString(true); std::string zero_excluded = get_perf_context()->ToString(true);
ASSERT_NE(std::string::npos, ASSERT_NE(std::string::npos,
zero_excluded.find("bloom_filter_useful = 1@level5, 2@level7")); zero_excluded.find("bloom_filter_useful = 1@level5, 2@level7"));
@ -713,6 +725,10 @@ TEST_F(PerfContextTest, PerfContextByLevelGetSet) {
zero_excluded.find("bloom_filter_full_positive = 1@level0")); zero_excluded.find("bloom_filter_full_positive = 1@level0"));
ASSERT_NE(std::string::npos, ASSERT_NE(std::string::npos,
zero_excluded.find("bloom_filter_full_true_positive = 1@level2")); zero_excluded.find("bloom_filter_full_true_positive = 1@level2"));
ASSERT_NE(std::string::npos,
zero_excluded.find("block_cache_hit_count = 1@level0, 5@level2"));
ASSERT_NE(std::string::npos,
zero_excluded.find("block_cache_miss_count = 4@level1, 2@level3"));
} }
} // namespace rocksdb } // namespace rocksdb

@ -35,6 +35,9 @@ struct PerfContextByLevel {
// total nanos spent on reading data from SST files // total nanos spent on reading data from SST files
uint64_t get_from_table_nanos; uint64_t get_from_table_nanos;
uint64_t block_cache_hit_count = 0; // total number of block cache hits
uint64_t block_cache_miss_count = 0; // total number of block cache misses
void Reset(); // reset all performance counters to zero void Reset(); // reset all performance counters to zero
}; };

@ -144,6 +144,8 @@ void PerfContextByLevel::Reset() {
bloom_filter_useful = 0; bloom_filter_useful = 0;
bloom_filter_full_positive = 0; bloom_filter_full_positive = 0;
bloom_filter_full_true_positive = 0; bloom_filter_full_true_positive = 0;
block_cache_hit_count = 0;
block_cache_miss_count = 0;
#endif #endif
} }
@ -229,6 +231,8 @@ std::string PerfContext::ToString(bool exclude_zero_counters) const {
PERF_CONTEXT_BY_LEVEL_OUTPUT_ONE_COUNTER(bloom_filter_useful); PERF_CONTEXT_BY_LEVEL_OUTPUT_ONE_COUNTER(bloom_filter_useful);
PERF_CONTEXT_BY_LEVEL_OUTPUT_ONE_COUNTER(bloom_filter_full_positive); PERF_CONTEXT_BY_LEVEL_OUTPUT_ONE_COUNTER(bloom_filter_full_positive);
PERF_CONTEXT_BY_LEVEL_OUTPUT_ONE_COUNTER(bloom_filter_full_true_positive); PERF_CONTEXT_BY_LEVEL_OUTPUT_ONE_COUNTER(bloom_filter_full_true_positive);
PERF_CONTEXT_BY_LEVEL_OUTPUT_ONE_COUNTER(block_cache_hit_count);
PERF_CONTEXT_BY_LEVEL_OUTPUT_ONE_COUNTER(block_cache_miss_count);
return ss.str(); return ss.str();
#endif #endif
} }

@ -151,6 +151,7 @@ Slice GetCacheKeyFromOffset(const char* cache_key_prefix,
} }
Cache::Handle* GetEntryFromCache(Cache* block_cache, const Slice& key, Cache::Handle* GetEntryFromCache(Cache* block_cache, const Slice& key,
int level,
Tickers block_cache_miss_ticker, Tickers block_cache_miss_ticker,
Tickers block_cache_hit_ticker, Tickers block_cache_hit_ticker,
uint64_t* block_cache_miss_stats, uint64_t* block_cache_miss_stats,
@ -160,6 +161,8 @@ Cache::Handle* GetEntryFromCache(Cache* block_cache, const Slice& key,
auto cache_handle = block_cache->Lookup(key, statistics); auto cache_handle = block_cache->Lookup(key, statistics);
if (cache_handle != nullptr) { if (cache_handle != nullptr) {
PERF_COUNTER_ADD(block_cache_hit_count, 1); PERF_COUNTER_ADD(block_cache_hit_count, 1);
PERF_COUNTER_BY_LEVEL_ADD(block_cache_hit_count, 1,
static_cast<uint32_t>(level));
if (get_context != nullptr) { if (get_context != nullptr) {
// overall cache hit // overall cache hit
get_context->get_context_stats_.num_cache_hit++; get_context->get_context_stats_.num_cache_hit++;
@ -177,6 +180,8 @@ Cache::Handle* GetEntryFromCache(Cache* block_cache, const Slice& key,
RecordTick(statistics, block_cache_hit_ticker); RecordTick(statistics, block_cache_hit_ticker);
} }
} else { } else {
PERF_COUNTER_BY_LEVEL_ADD(block_cache_miss_count, 1,
static_cast<uint32_t>(level));
if (get_context != nullptr) { if (get_context != nullptr) {
// overall cache miss // overall cache miss
get_context->get_context_stats_.num_cache_miss++; get_context->get_context_stats_.num_cache_miss++;
@ -1284,7 +1289,7 @@ Status BlockBasedTable::GetDataBlockFromCache(
// Lookup uncompressed cache first // Lookup uncompressed cache first
if (block_cache != nullptr) { if (block_cache != nullptr) {
block->cache_handle = GetEntryFromCache( block->cache_handle = GetEntryFromCache(
block_cache, block_cache_key, block_cache, block_cache_key, rep->level,
is_index ? BLOCK_CACHE_INDEX_MISS : BLOCK_CACHE_DATA_MISS, is_index ? BLOCK_CACHE_INDEX_MISS : BLOCK_CACHE_DATA_MISS,
is_index ? BLOCK_CACHE_INDEX_HIT : BLOCK_CACHE_DATA_HIT, is_index ? BLOCK_CACHE_INDEX_HIT : BLOCK_CACHE_DATA_HIT,
get_context get_context
@ -1613,7 +1618,8 @@ BlockBasedTable::CachableEntry<FilterBlockReader> BlockBasedTable::GetFilter(
Statistics* statistics = rep_->ioptions.statistics; Statistics* statistics = rep_->ioptions.statistics;
auto cache_handle = GetEntryFromCache( auto cache_handle = GetEntryFromCache(
block_cache, key, BLOCK_CACHE_FILTER_MISS, BLOCK_CACHE_FILTER_HIT, block_cache, key, rep_->level,
BLOCK_CACHE_FILTER_MISS, BLOCK_CACHE_FILTER_HIT,
get_context ? &get_context->get_context_stats_.num_cache_filter_miss get_context ? &get_context->get_context_stats_.num_cache_filter_miss
: nullptr, : nullptr,
get_context ? &get_context->get_context_stats_.num_cache_filter_hit get_context ? &get_context->get_context_stats_.num_cache_filter_hit
@ -1696,7 +1702,8 @@ InternalIteratorBase<BlockHandle>* BlockBasedTable::NewIndexIterator(
rep_->dummy_index_reader_offset, cache_key); rep_->dummy_index_reader_offset, cache_key);
Statistics* statistics = rep_->ioptions.statistics; Statistics* statistics = rep_->ioptions.statistics;
auto cache_handle = GetEntryFromCache( auto cache_handle = GetEntryFromCache(
block_cache, key, BLOCK_CACHE_INDEX_MISS, BLOCK_CACHE_INDEX_HIT, block_cache, key, rep_->level,
BLOCK_CACHE_INDEX_MISS, BLOCK_CACHE_INDEX_HIT,
get_context ? &get_context->get_context_stats_.num_cache_index_miss get_context ? &get_context->get_context_stats_.num_cache_index_miss
: nullptr, : nullptr,
get_context ? &get_context->get_context_stats_.num_cache_index_hit get_context ? &get_context->get_context_stats_.num_cache_index_hit

Loading…
Cancel
Save