From a8975b62455cb73a8e23ff6be709df1b97859d2d Mon Sep 17 00:00:00 2001 From: haoyuhuang Date: Thu, 27 Jun 2019 08:31:03 -0700 Subject: [PATCH] Block cache tracer: Do not populate block cache trace record when tracing is disabled. (#5510) Summary: This PR makes sure that trace record is not populated when tracing is disabled. Before this PR: DB path: [/data/mysql/rocks_regression_tests/OPTIONS-myrocks-40-33-10000000/2019-06-26-13-04-41/db] readwhilewriting : 9.803 micros/op 1550408 ops/sec; 107.9 MB/s (5000000 of 5000000 found) Microseconds per read: Count: 80000000 Average: 9.8045 StdDev: 12.64 Min: 1 Median: 7.5246 Max: 25343 Percentiles: P50: 7.52 P75: 12.10 P99: 37.44 P99.9: 75.07 P99.99: 133.60 After this PR: DB path: [/data/mysql/rocks_regression_tests/OPTIONS-myrocks-40-33-10000000/2019-06-26-14-08-21/db] readwhilewriting : 8.723 micros/op 1662882 ops/sec; 115.8 MB/s (5000000 of 5000000 found) Microseconds per read: Count: 80000000 Average: 8.7236 StdDev: 12.19 Min: 1 Median: 6.7262 Max: 25229 Percentiles: P50: 6.73 P75: 10.50 P99: 31.54 P99.9: 74.81 P99.99: 132.82 Pull Request resolved: https://github.com/facebook/rocksdb/pull/5510 Differential Revision: D16016428 Pulled By: HaoyuHuang fbshipit-source-id: 3b3d11e6accf207d18ec2545b802aa01ee65901f --- table/block_based/block_based_table_reader.cc | 13 ++++++++----- trace_replay/block_cache_tracer.h | 4 ++++ 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/table/block_based/block_based_table_reader.cc b/table/block_based/block_based_table_reader.cc index 5344625ec..e73b0c08c 100644 --- a/table/block_based/block_based_table_reader.cc +++ b/table/block_based/block_based_table_reader.cc @@ -1967,7 +1967,8 @@ CachableEntry BlockBasedTable::GetFilter( } } - if (block_cache_tracer_ && lookup_context) { + if (block_cache_tracer_ && block_cache_tracer_->is_tracing_enabled() && + lookup_context) { // Avoid making copy of block_key and cf_name when constructing the access // record. BlockCacheTraceRecord access_record( @@ -2048,7 +2049,8 @@ CachableEntry BlockBasedTable::GetUncompressionDict( } } } - if (block_cache_tracer_ && lookup_context) { + if (block_cache_tracer_ && block_cache_tracer_->is_tracing_enabled() && + lookup_context) { // Avoid making copy of block_key and cf_name when constructing the access // record. BlockCacheTraceRecord access_record( @@ -2273,7 +2275,8 @@ Status BlockBasedTable::MaybeReadBlockAndLoadToCache( } // Fill lookup_context. - if (block_cache_tracer_ && lookup_context) { + if (block_cache_tracer_ && block_cache_tracer_->is_tracing_enabled() && + lookup_context) { size_t usage = 0; uint64_t nkeys = 0; if (block_entry->GetValue()) { @@ -3167,7 +3170,7 @@ Status BlockBasedTable::Get(const ReadOptions& read_options, const Slice& key, s = biter.status(); } // Write the block cache access record. - if (block_cache_tracer_) { + if (block_cache_tracer_ && block_cache_tracer_->is_tracing_enabled()) { // Avoid making copy of block_key, cf_name, and referenced_key when // constructing the access record. BlockCacheTraceRecord access_record( @@ -3334,7 +3337,7 @@ void BlockBasedTable::MultiGet(const ReadOptions& read_options, s = biter.status(); } // Write the block cache access. - if (block_cache_tracer_) { + if (block_cache_tracer_ && block_cache_tracer_->is_tracing_enabled()) { // Avoid making copy of block_key, cf_name, and referenced_key when // constructing the access record. BlockCacheTraceRecord access_record( diff --git a/trace_replay/block_cache_tracer.h b/trace_replay/block_cache_tracer.h index e7f38db3c..e2ad933b9 100644 --- a/trace_replay/block_cache_tracer.h +++ b/trace_replay/block_cache_tracer.h @@ -197,6 +197,10 @@ class BlockCacheTracer { // Stop writing block cache accesses to the trace_writer. void EndTrace(); + bool is_tracing_enabled() const { + return writer_.load(std::memory_order_relaxed); + } + Status WriteBlockAccess(const BlockCacheTraceRecord& record, const Slice& block_key, const Slice& cf_name, const Slice& referenced_key);