From a1d7e487b32a548c5336067a656e9ae0dcceb4e6 Mon Sep 17 00:00:00 2001 From: Andrew Kryczka Date: Mon, 3 Apr 2017 11:10:34 -0700 Subject: [PATCH] Add L0 write-amp to compaction level stats Summary: Previously it always showed 0.0 for L0 write-amp because we were dividing by bytes read from non-output level. For L0, we should instead divide by bytes ingested to the DB. Note the numerator (bytes written to L0) includes flush bytes. Closes https://github.com/facebook/rocksdb/pull/2078 Differential Revision: D4816902 Pulled By: ajkr fbshipit-source-id: 7dca31a --- db/internal_stats.cc | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/db/internal_stats.cc b/db/internal_stats.cc index 747bc8ecf..d81b5bf6b 100644 --- a/db/internal_stats.cc +++ b/db/internal_stats.cc @@ -924,6 +924,9 @@ void InternalStats::DumpCFMapStats( int total_files = 0; int total_files_being_compacted = 0; double total_file_size = 0; + uint64_t flush_ingest = cf_stats_value_[BYTES_FLUSHED]; + uint64_t add_file_ingest = cf_stats_value_[BYTES_INGESTED_ADD_FILE]; + uint64_t curr_ingest = flush_ingest + add_file_ingest; for (int level = 0; level < number_levels_; level++) { int files = vstorage->NumLevelFiles(level); total_files += files; @@ -931,11 +934,17 @@ void InternalStats::DumpCFMapStats( if (comp_stats_[level].micros > 0 || files > 0) { compaction_stats_sum->Add(comp_stats_[level]); total_file_size += vstorage->NumLevelBytes(level); + uint64_t input_bytes; + if (level == 0) { + input_bytes = curr_ingest; + } else { + input_bytes = comp_stats_[level].bytes_read_non_output_levels; + } double w_amp = - (comp_stats_[level].bytes_read_non_output_levels == 0) + (input_bytes == 0) ? 0.0 : static_cast(comp_stats_[level].bytes_written) / - comp_stats_[level].bytes_read_non_output_levels; + input_bytes; std::map level_stats; PrepareLevelStats(&level_stats, files, files_being_compacted[level], static_cast(vstorage->NumLevelBytes(level)), @@ -943,9 +952,6 @@ void InternalStats::DumpCFMapStats( (*levels_stats)[level] = level_stats; } } - uint64_t flush_ingest = cf_stats_value_[BYTES_FLUSHED]; - uint64_t add_file_ingest = cf_stats_value_[BYTES_INGESTED_ADD_FILE]; - uint64_t curr_ingest = flush_ingest + add_file_ingest; // Cumulative summary double w_amp = compaction_stats_sum->bytes_written / static_cast(curr_ingest + 1);