Skip to content

Commit

Permalink
Just use histogram instead
Browse files Browse the repository at this point in the history
  • Loading branch information
archang19 committed Jan 18, 2025
1 parent a9eeec8 commit 97c42b2
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 46 deletions.
5 changes: 1 addition & 4 deletions db/db_impl/db_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -2430,7 +2430,7 @@ class DBImpl : public DB {
const std::vector<CompactionInputFiles>& inputs,
bool* sfm_bookkeeping, LogBuffer* log_buffer);

int GetNumberCompactionIterators(Compaction* c);
size_t GetNumberCompactionInputIterators(Compaction* c);

// Request compaction tasks token from compaction thread limiter.
// It always succeeds if force = true or limiter is disable.
Expand Down Expand Up @@ -2965,9 +2965,6 @@ class DBImpl : public DB {
// stores the number of compactions are currently running
int num_running_compactions_;

// stores the number of iterators required for currently running compactions
int num_running_compaction_iterators_;

// number of background memtable flush jobs, submitted to the HIGH pool
int bg_flush_scheduled_;

Expand Down
29 changes: 12 additions & 17 deletions db/db_impl/db_impl_compaction_flush.cc
Original file line number Diff line number Diff line change
Expand Up @@ -61,18 +61,14 @@ bool DBImpl::EnoughRoomForCompaction(
return enough_room;
}

int DBImpl::GetNumberCompactionIterators(Compaction* c) {
size_t DBImpl::GetNumberCompactionInputIterators(Compaction* c) {
assert(c);
int num_l0_files = 0;
int num_non_l0_levels = 0;
for (auto& each_level : *c->inputs()) {
if (each_level.level == 0) {
num_l0_files += each_level.files.size();
} else {
num_non_l0_levels++;
}
if (c->start_level() == 0) {
size_t num_l0_files = c->num_input_files(0);
size_t num_non_l0_levels = c->num_input_levels() - 1;
return num_l0_files + num_non_l0_levels;
}
return num_l0_files + num_non_l0_levels;
return c->num_input_levels();
}

bool DBImpl::RequestCompactionToken(ColumnFamilyData* cfd, bool force,
Expand Down Expand Up @@ -3424,9 +3420,6 @@ void DBImpl::BackgroundCallCompaction(PrepickedCompaction* prepicked_compaction,
InstrumentedMutexLock l(&mutex_);

num_running_compactions_++;
int num_compaction_iterators =
GetNumberCompactionIterators(prepicked_compaction->compaction);
num_running_compaction_iterators_ += num_compaction_iterators;

std::unique_ptr<std::list<uint64_t>::iterator>
pending_outputs_inserted_elem(new std::list<uint64_t>::iterator(
Expand Down Expand Up @@ -3501,8 +3494,6 @@ void DBImpl::BackgroundCallCompaction(PrepickedCompaction* prepicked_compaction,

assert(num_running_compactions_ > 0);
num_running_compactions_--;
assert(num_running_compaction_iterators_ >= num_compaction_iterators);
num_running_compaction_iterators_ -= num_compaction_iterators;

if (bg_thread_pri == Env::Priority::LOW) {
bg_compaction_scheduled_--;
Expand Down Expand Up @@ -3739,13 +3730,17 @@ Status DBImpl::BackgroundCompaction(bool* made_progress,
num_files += each_level.files.size();
}
RecordInHistogram(stats_, NUM_FILES_IN_SINGLE_COMPACTION, num_files);
size_t num_compaction_input_iterators =
GetNumberCompactionInputIterators(c.get());
RecordInHistogram(stats_, NUM_COMPACTION_INPUT_ITERATORS,
num_compaction_input_iterators);

// There are three things that can change compaction score:
// 1) When flush or compaction finish. This case is covered by
// InstallSuperVersionAndScheduleWork
// 2) When MutableCFOptions changes. This case is also covered by
// InstallSuperVersionAndScheduleWork, because this is when the new
// options take effect.
// InstallSuperVersionAndScheduleWork, because this is when the
// new options take effect.
// 3) When we Pick a new compaction, we "remove" those files being
// compacted from the calculation, which then influences compaction
// score. Here we check if we need the new compaction even without the
Expand Down
14 changes: 0 additions & 14 deletions db/internal_stats.cc
Original file line number Diff line number Diff line change
Expand Up @@ -301,8 +301,6 @@ static const std::string aggregated_table_properties =
static const std::string aggregated_table_properties_at_level =
aggregated_table_properties + "-at-level";
static const std::string num_running_compactions = "num-running-compactions";
static const std::string num_running_compaction_iterators =
"num-running-compaction-iterators";
static const std::string num_running_flushes = "num-running-flushes";
static const std::string actual_delayed_write_rate =
"actual-delayed-write-rate";
Expand Down Expand Up @@ -353,8 +351,6 @@ const std::string DB::Properties::kCompactionPending =
rocksdb_prefix + compaction_pending;
const std::string DB::Properties::kNumRunningCompactions =
rocksdb_prefix + num_running_compactions;
const std::string DB::Properties::kNumRunningCompactionIterators =
rocksdb_prefix + num_running_compaction_iterators;
const std::string DB::Properties::kNumRunningFlushes =
rocksdb_prefix + num_running_flushes;
const std::string DB::Properties::kBackgroundErrors =
Expand Down Expand Up @@ -584,9 +580,6 @@ const UnorderedMap<std::string, DBPropertyInfo>
{DB::Properties::kNumRunningCompactions,
{false, nullptr, &InternalStats::HandleNumRunningCompactions, nullptr,
nullptr}},
{DB::Properties::kNumRunningCompactionIterators,
{false, nullptr, &InternalStats::HandleNumRunningCompactionIterators,
nullptr, nullptr}},
{DB::Properties::kActualDelayedWriteRate,
{false, nullptr, &InternalStats::HandleActualDelayedWriteRate, nullptr,
nullptr}},
Expand Down Expand Up @@ -1272,13 +1265,6 @@ bool InternalStats::HandleNumRunningCompactions(uint64_t* value, DBImpl* db,
return true;
}

bool InternalStats::HandleNumRunningCompactionIterators(uint64_t* value,
DBImpl* db,
Version* /*version*/) {
*value = db->num_running_compaction_iterators_;
return true;
}

bool InternalStats::HandleBackgroundErrors(uint64_t* value, DBImpl* /*db*/,
Version* /*version*/) {
// Accumulated number of errors in background flushes or compactions.
Expand Down
2 changes: 0 additions & 2 deletions db/internal_stats.h
Original file line number Diff line number Diff line change
Expand Up @@ -847,8 +847,6 @@ class InternalStats {
bool HandleCompactionPending(uint64_t* value, DBImpl* db, Version* version);
bool HandleNumRunningCompactions(uint64_t* value, DBImpl* db,
Version* version);
bool HandleNumRunningCompactionIterators(uint64_t* value, DBImpl* db,
Version* version);
bool HandleBackgroundErrors(uint64_t* value, DBImpl* db, Version* version);
bool HandleCurSizeActiveMemTable(uint64_t* value, DBImpl* db,
Version* version);
Expand Down
4 changes: 0 additions & 4 deletions include/rocksdb/db.h
Original file line number Diff line number Diff line change
Expand Up @@ -1210,10 +1210,6 @@ class DB {
// running compactions.
static const std::string kNumRunningCompactions;

// "rocksdb.num-running-compaction-iterators" - returns the number of
// iterators required for currently running compactions.
static const std::string kNumRunningCompactionIterators;

// "rocksdb.background-errors" - returns accumulated number of background
// errors.
static const std::string kBackgroundErrors;
Expand Down
4 changes: 4 additions & 0 deletions include/rocksdb/statistics.h
Original file line number Diff line number Diff line change
Expand Up @@ -667,6 +667,10 @@ enum Histograms : uint32_t {
// system's prefetch) from the end of SST table during block based table open
TABLE_OPEN_PREFETCH_TAIL_READ_BYTES,

// Number of iterators needed to process compaction inputs
// Equal to number of L0 input files + number of non-L0 input levels
NUM_COMPACTION_INPUT_ITERATORS,

HISTOGRAM_ENUM_MAX
};

Expand Down
10 changes: 7 additions & 3 deletions java/rocksjni/portal.h
Original file line number Diff line number Diff line change
Expand Up @@ -5889,9 +5889,11 @@ class HistogramTypeJni {
return 0x3C;
case ROCKSDB_NAMESPACE::Histograms::TABLE_OPEN_PREFETCH_TAIL_READ_BYTES:
return 0x3D;
case ROCKSDB_NAMESPACE::Histograms::HISTOGRAM_ENUM_MAX:
// 0x3D for backwards compatibility on current minor version.
case ROCKSDB_NAMESPACE::Histograms::NUM_COMPACTION_INPUT_ITERATORS:
return 0x3E;
case ROCKSDB_NAMESPACE::Histograms::HISTOGRAM_ENUM_MAX:
// 0x3F for backwards compatibility on current minor version.
return 0x3F;
default:
// undefined/default
return 0x0;
Expand Down Expand Up @@ -6034,7 +6036,9 @@ class HistogramTypeJni {
return ROCKSDB_NAMESPACE::Histograms::
TABLE_OPEN_PREFETCH_TAIL_READ_BYTES;
case 0x3E:
// 0x1F for backwards compatibility on current minor version.
return ROCKSDB_NAMESPACE::Histograms::NUM_COMPACTION_INPUT_ITERATORS;
case 0x40:
// 0x40 for backwards compatibility on current minor version.
return ROCKSDB_NAMESPACE::Histograms::HISTOGRAM_ENUM_MAX;

default:
Expand Down
10 changes: 8 additions & 2 deletions java/src/main/java/org/rocksdb/HistogramType.java
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,14 @@ public enum HistogramType {
*/
TABLE_OPEN_PREFETCH_TAIL_READ_BYTES((byte) 0x3D),

// 0x3E for backwards compatibility on current minor version.
HISTOGRAM_ENUM_MAX((byte) 0x3E);
/**
* Number of iterators needed to process compaction inputs
* Equal to number of L0 input files + number of non-L0 input levels
*/
NUM_COMPACTION_INPUT_ITERATORS((byte) 0x3E),

// 0x3F for backwards compatibility on current minor version.
HISTOGRAM_ENUM_MAX((byte) 0x3F);

private final byte value;

Expand Down
1 change: 1 addition & 0 deletions monitoring/statistics.cc
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,7 @@ const std::vector<std::pair<Histograms, std::string>> HistogramsNameMap = {
{ASYNC_PREFETCH_ABORT_MICROS, "rocksdb.async.prefetch.abort.micros"},
{TABLE_OPEN_PREFETCH_TAIL_READ_BYTES,
"rocksdb.table.open.prefetch.tail.read.bytes"},
{NUM_COMPACTION_INPUT_ITERATORS, "rocksdb.num.compaction.iterators"},
};

std::shared_ptr<Statistics> CreateDBStatistics() {
Expand Down

0 comments on commit 97c42b2

Please sign in to comment.