From 3901febe09ad4cac1619e2cb4876e40f3a220abd Mon Sep 17 00:00:00 2001 From: Dmitri Petrov Date: Mon, 11 Dec 2023 23:11:57 +0000 Subject: [PATCH] Expand PerfContext to add ss_file reads and serialized_reads. --- db/version_set.cc | 33 +++++++++++++++++++++++++++++++++ include/rocksdb/perf_context.h | 9 +++++++++ monitoring/perf_context.cc | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 75 insertions(+) diff --git a/db/version_set.cc b/db/version_set.cc index a6b772948eab..30b5d846146d 100644 --- a/db/version_set.cc +++ b/db/version_set.cc @@ -2521,9 +2521,19 @@ void Version::MultiGet(const ReadOptions& read_options, MultiGetRange* range, if (fp.GetHitFileLevel() == 0) { dump_stats_for_l0_file = true; } + // RocksDB-Cloud contribution begin + PERF_COUNTER_ADD(multiget_sst_file_read_count, 1); + // RocksDB-Cloud contribution end } if (s.ok()) { f = fp.GetNextFileInLevel(); + // RocksDB-Cloud contribution begin + if (f) { + // We have another file to read. This implies that the read on + // this file was blocked (or serialized) behind the previous read. + PERF_COUNTER_ADD(multiget_sst_serialized_file_read_count, 1); + } + // RocksDB-Cloud contribution end } #if USE_COROUTINES } else { @@ -2567,6 +2577,9 @@ void Version::MultiGet(const ReadOptions& read_options, MultiGetRange* range, if (mget_tasks.size() > 0) { RecordTick(db_statistics_, MULTIGET_COROUTINE_COUNT, mget_tasks.size()); + // RocksDB-Cloud contribution begin + PERF_COUNTER_ADD(multiget_sst_file_read_count, mget_tasks.size()); + // RocksDB-Cloud contribution end // Collect all results so far std::vector statuses = folly::coro::blockingWait( folly::coro::collectAllRange(std::move(mget_tasks)) @@ -2582,6 +2595,13 @@ void Version::MultiGet(const ReadOptions& read_options, MultiGetRange* range, if (s.ok() && fp.KeyMaySpanNextFile()) { f = fp.GetNextFileInLevel(); + // RocksDB-Cloud contribution begin + if (f) { + // We couldn't read all the files in this level 'in one go'. + // Record the number of files that were waiting. + PERF_COUNTER_ADD(multiget_sst_serialized_file_read_count, 1); + } + // RocksDB-Cloud contribution end } } #endif // USE_COROUTINES @@ -2763,6 +2783,9 @@ Status Version::ProcessBatch( table_handle, std::get<0>(stat->second), std::get<1>(stat->second), std::get<2>(stat->second)); + // RocksDB-Cloud contribution begin + PERF_COUNTER_ADD(multiget_sst_file_read_count, mget_iter.size()); + // RocksDB-Cloud contribution end } else { mget_tasks.emplace_back(MultiGetFromSSTCoroutine( read_options, file_range, fp.GetHitFileLevel(), skip_filters, @@ -2853,6 +2876,9 @@ Status Version::MultiGetAsync( if (mget_tasks.size() > 0) { assert(waiting.size()); RecordTick(db_statistics_, MULTIGET_COROUTINE_COUNT, mget_tasks.size()); + // RocksDB-Cloud contribution begin + PERF_COUNTER_ADD(multiget_sst_file_read_count, mget_tasks.size()); + // RocksDB-Cloud contribution end // Collect all results so far std::vector statuses = folly::coro::blockingWait( folly::coro::collectAllRange(std::move(mget_tasks)) @@ -2879,6 +2905,13 @@ Status Version::MultiGetAsync( // and no need to prepare the next level. if (!fp.GetHitFile() && !fp.GetRange().empty()) { fp.PrepareNextLevelForSearch(); + } else { + // RocksDB-Cloud contribution begin + // We still need to read files in the current level despite running + // some rounds of coroutine parallel reads. Record the fact that + // file reads were serialized. + PERF_COUNTER_ADD(multiget_sst_serialized_file_read_count, 1); + // RocksDB-Cloud contribution end } } to_process.swap(waiting); diff --git a/include/rocksdb/perf_context.h b/include/rocksdb/perf_context.h index cd1dd99f06d5..6eb08eafdb96 100644 --- a/include/rocksdb/perf_context.h +++ b/include/rocksdb/perf_context.h @@ -80,6 +80,15 @@ 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 + + // RocksDB-Cloud contribution begin + + // Total number of files read in MultiGet operations + uint64_t multiget_sst_file_read_count; + // Number of times file reads were serialized behind other reads + uint64_t multiget_sst_serialized_file_read_count; + + // RocksDB-Cloud contribution end uint64_t secondary_cache_hit_count; // total number of secondary cache hits // total number of real handles inserted into secondary cache diff --git a/monitoring/perf_context.cc b/monitoring/perf_context.cc index 9068ede01119..9a760d2881fe 100644 --- a/monitoring/perf_context.cc +++ b/monitoring/perf_context.cc @@ -43,6 +43,13 @@ 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; + + // RocksDB-Cloud contribution begin + multiget_sst_file_read_count = other.multiget_sst_file_read_count; + multiget_sst_serialized_file_read_count = + other.multiget_sst_serialized_file_read_count; + // RocksDB-Cloud contribution end + secondary_cache_hit_count = other.secondary_cache_hit_count; compressed_sec_cache_insert_real_count = other.compressed_sec_cache_insert_real_count; @@ -162,6 +169,13 @@ 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; + + // RocksDB-Cloud contribution begin + multiget_sst_file_read_count = other.multiget_sst_file_read_count; + multiget_sst_serialized_file_read_count = + other.multiget_sst_serialized_file_read_count; + // RocksDB-Cloud contribution end + secondary_cache_hit_count = other.secondary_cache_hit_count; compressed_sec_cache_insert_real_count = other.compressed_sec_cache_insert_real_count; @@ -283,6 +297,13 @@ 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; + + // RocksDB-Cloud contribution begin + multiget_sst_file_read_count = other.multiget_sst_file_read_count; + multiget_sst_serialized_file_read_count = + other.multiget_sst_serialized_file_read_count; + // RocksDB-Cloud contribution end + secondary_cache_hit_count = other.secondary_cache_hit_count; compressed_sec_cache_insert_real_count = other.compressed_sec_cache_insert_real_count; @@ -400,6 +421,12 @@ void PerfContext::Reset() { block_cache_filter_hit_count = 0; filter_block_read_count = 0; compression_dict_block_read_count = 0; + + // RocksDB-Cloud contribution begin + multiget_sst_file_read_count = 0; + multiget_sst_serialized_file_read_count = 0; + // RocksDB-Cloud contribution end + secondary_cache_hit_count = 0; compressed_sec_cache_insert_real_count = 0; compressed_sec_cache_insert_dummy_count = 0; @@ -536,6 +563,12 @@ 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); + + // RocksDB-Cloud contribution begin + PERF_CONTEXT_OUTPUT(multiget_sst_file_read_count); + PERF_CONTEXT_OUTPUT(multiget_sst_serialized_file_read_count); + // RocksDB-Cloud contribution end + PERF_CONTEXT_OUTPUT(secondary_cache_hit_count); PERF_CONTEXT_OUTPUT(compressed_sec_cache_insert_real_count); PERF_CONTEXT_OUTPUT(compressed_sec_cache_insert_dummy_count);