]> git-server-git.apps.pok.os.sepia.ceph.com Git - rocksdb.git/commitdiff
Add a PerfContext counter for secondary cache hits (#8685)
authoranand76 <anand76@devvm4702.ftw0.facebook.com>
Fri, 20 Aug 2021 22:16:33 +0000 (15:16 -0700)
committerFacebook GitHub Bot <facebook-github-bot@users.noreply.github.com>
Fri, 20 Aug 2021 22:17:30 +0000 (15:17 -0700)
Summary:
Add a PerfContext counter.

Pull Request resolved: https://github.com/facebook/rocksdb/pull/8685

Reviewed By: zhichao-cao

Differential Revision: D30453957

Pulled By: anand1976

fbshipit-source-id: 42888a3ced240e1c44446d52d3b04adfb01f5665

HISTORY.md
cache/lru_cache.cc
cache/lru_cache_test.cc
include/rocksdb/perf_context.h
monitoring/perf_context.cc

index a424099e39638f2e50496fab7ff7e39f2c8c826a..b1c9ffb7d30fa05fefea5c4b1f8a8cea742a2bf3 100644 (file)
@@ -9,6 +9,7 @@
 * Fixed a bug affecting the batched `MultiGet` API when used with keys spanning multiple column families and `sorted_input == false`.
 * Fixed a potential incorrect result in opt mode and assertion failures caused by releasing snapshot(s) during compaction.
 * Fixed passing of BlobFileCompletionCallback to Compaction job and Atomic flush job which was default paramter (nullptr). BlobFileCompletitionCallback is internal callback that manages addition of blob files to SSTFileManager.
+* Fixed MultiGet not updating the block_read_count and block_read_byte PerfContext counters
 
 ### New Features
 * Made the EventListener extend the Customizable class.
@@ -20,6 +21,7 @@
 * Fast forward option in Trace replay changed to double type to allow replaying at a lower speed, by settings the value between 0 and 1. This option can be set via `ReplayOptions` in `Replayer::Replay()`, or via `--trace_replay_fast_forward` in db_bench.
 * Add property `LiveSstFilesSizeAtTemperature` to retrieve sst file size at different temperature.
 * Added a stat rocksdb.secondary.cache.hits
+* Added a PerfContext counter secondary_cache_hit_count
 * The integrated BlobDB implementation now supports the tickers `BLOB_DB_BLOB_FILE_BYTES_READ`, `BLOB_DB_GC_NUM_KEYS_RELOCATED`, and `BLOB_DB_GC_BYTES_RELOCATED`, as well as the histograms `BLOB_DB_COMPRESSION_MICROS` and `BLOB_DB_DECOMPRESSION_MICROS`.
 
 ## Public API change
index 710a155c4c74c7d66532cb3435c956cf36d59225..689242ca90c732f94208c56f448105429f23587e 100644 (file)
@@ -13,6 +13,7 @@
 #include <cstdint>
 #include <cstdio>
 
+#include "monitoring/perf_context_imp.h"
 #include "monitoring/statistics.h"
 #include "util/mutexlock.h"
 
@@ -473,6 +474,7 @@ Cache::Handle* LRUCacheShard::Lookup(
           e->Free();
           e = nullptr;
         } else {
+          PERF_COUNTER_ADD(secondary_cache_hit_count, 1);
           RecordTick(stats, SECONDARY_CACHE_HITS);
         }
       } else {
@@ -481,6 +483,7 @@ Cache::Handle* LRUCacheShard::Lookup(
         e->SetIncomplete(true);
         // This may be slightly inaccurate, if the lookup eventually fails.
         // But the probability is very low.
+        PERF_COUNTER_ADD(secondary_cache_hit_count, 1);
         RecordTick(stats, SECONDARY_CACHE_HITS);
       }
     }
index 74409421c61e389e91c8ca9b2a1b76ec0a45a716..e840273bd31aa3dadd54faa964cc41f14aa69f87 100644 (file)
@@ -481,6 +481,7 @@ TEST_F(LRUSecondaryCacheTest, BasicTest) {
   ASSERT_OK(cache->Insert("k2", item2, &LRUSecondaryCacheTest::helper_,
                           str2.length()));
 
+  get_perf_context()->Reset();
   Cache::Handle* handle;
   handle =
       cache->Lookup("k2", &LRUSecondaryCacheTest::helper_, test_item_creator,
@@ -497,6 +498,8 @@ TEST_F(LRUSecondaryCacheTest, BasicTest) {
   ASSERT_EQ(secondary_cache->num_lookups(), 1u);
   ASSERT_EQ(stats->getTickerCount(SECONDARY_CACHE_HITS),
             secondary_cache->num_lookups());
+  PerfContext perf_ctx = *get_perf_context();
+  ASSERT_EQ(perf_ctx.secondary_cache_hit_count, secondary_cache->num_lookups());
 
   cache.reset();
   secondary_cache.reset();
index 699f57344f198b0ebcd977672fc8e7ebe75c5a78..f3058416e0daa7ae38ea33a4ec472872bc38987b 100644 (file)
@@ -74,6 +74,9 @@ struct PerfContext {
   uint64_t filter_block_read_count;       // total number of filter block reads
   uint64_t compression_dict_block_read_count;  // total number of compression
                                                // dictionary block reads
+
+  uint64_t secondary_cache_hit_count;  // total number of secondary cache hits
+
   uint64_t block_checksum_time;    // total nanos spent on block checksum
   uint64_t block_decompress_time;  // total nanos spent on block decompression
 
index d45d84fb6e33bc4baf6c7c54b82dade7cb6a8471..9e56f1018867e312f38a1118197f71dcbc96a162 100644 (file)
@@ -47,6 +47,7 @@ PerfContext::PerfContext(const PerfContext& other) {
   block_cache_filter_hit_count = other.block_cache_filter_hit_count;
   filter_block_read_count = other.filter_block_read_count;
   compression_dict_block_read_count = other.compression_dict_block_read_count;
+  secondary_cache_hit_count = other.secondary_cache_hit_count;
   block_checksum_time = other.block_checksum_time;
   block_decompress_time = other.block_decompress_time;
   get_read_bytes = other.get_read_bytes;
@@ -144,6 +145,7 @@ PerfContext::PerfContext(PerfContext&& other) noexcept {
   block_cache_filter_hit_count = other.block_cache_filter_hit_count;
   filter_block_read_count = other.filter_block_read_count;
   compression_dict_block_read_count = other.compression_dict_block_read_count;
+  secondary_cache_hit_count = other.secondary_cache_hit_count;
   block_checksum_time = other.block_checksum_time;
   block_decompress_time = other.block_decompress_time;
   get_read_bytes = other.get_read_bytes;
@@ -243,6 +245,7 @@ PerfContext& PerfContext::operator=(const PerfContext& other) {
   block_cache_filter_hit_count = other.block_cache_filter_hit_count;
   filter_block_read_count = other.filter_block_read_count;
   compression_dict_block_read_count = other.compression_dict_block_read_count;
+  secondary_cache_hit_count = other.secondary_cache_hit_count;
   block_checksum_time = other.block_checksum_time;
   block_decompress_time = other.block_decompress_time;
   get_read_bytes = other.get_read_bytes;
@@ -339,6 +342,7 @@ void PerfContext::Reset() {
   block_cache_filter_hit_count = 0;
   filter_block_read_count = 0;
   compression_dict_block_read_count = 0;
+  secondary_cache_hit_count = 0;
   block_checksum_time = 0;
   block_decompress_time = 0;
   get_read_bytes = 0;
@@ -459,6 +463,7 @@ std::string PerfContext::ToString(bool exclude_zero_counters) const {
   PERF_CONTEXT_OUTPUT(block_cache_filter_hit_count);
   PERF_CONTEXT_OUTPUT(filter_block_read_count);
   PERF_CONTEXT_OUTPUT(compression_dict_block_read_count);
+  PERF_CONTEXT_OUTPUT(secondary_cache_hit_count);
   PERF_CONTEXT_OUTPUT(block_checksum_time);
   PERF_CONTEXT_OUTPUT(block_decompress_time);
   PERF_CONTEXT_OUTPUT(get_read_bytes);