Skip to content

Commit

Permalink
Add a new stats level to exclude tickers (facebook#7329)
Browse files Browse the repository at this point in the history
Summary:
Currently, application may pass a statistics object to db but later
wants to reduce stats tracking overhead by setting stats level to
kExceptHistogramOrTimers (the current lowest level). Tickers will still
be incremented, causing up to 1% CPU. We can add a new lowest stats
level `kExceptTickers` to disable ticker incrementing as well, thus
reducing CPU cycles spent on tickers.

Test Plan (devserver):
```
make check
make clean
DEBUG_LEVEL=0 make db_bench
./db_bench -perf_level=1 -stats_level=0 -statistics -benchmarks=fillseq,readrandom -duration=120
```

Measure CPU util (%) before and after change:
CPU util by rocksdb::RecordTick: 1.1 vs (<0.1)

Pull Request resolved: facebook#7329

Reviewed By: pdillinger

Differential Revision: D23434014

Pulled By: riversand963

fbshipit-source-id: 72ff0f02a192ac476d4b0044b9f37fd4a22ff0d4
  • Loading branch information
riversand963 authored and facebook-github-bot committed Sep 5, 2020
1 parent 27aa443 commit ab202e8
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 5 deletions.
13 changes: 13 additions & 0 deletions db/db_statistics_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,19 @@ TEST_F(DBStatisticsTest, ResetStats) {
}
}

TEST_F(DBStatisticsTest, ExcludeTickers) {
Options options = CurrentOptions();
options.statistics = ROCKSDB_NAMESPACE::CreateDBStatistics();
DestroyAndReopen(options);
options.statistics->set_stats_level(StatsLevel::kExceptTickers);
ASSERT_OK(Put("foo", "value"));
ASSERT_EQ(0, options.statistics->getTickerCount(BYTES_WRITTEN));
options.statistics->set_stats_level(StatsLevel::kExceptHistogramOrTimers);
Reopen(options);
ASSERT_EQ("value", Get("foo"));
ASSERT_GT(options.statistics->getTickerCount(BYTES_READ), 0);
}

} // namespace ROCKSDB_NAMESPACE

int main(int argc, char** argv) {
Expand Down
4 changes: 4 additions & 0 deletions include/rocksdb/statistics.h
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,10 @@ struct HistogramData {
// Usage:
// options.statistics->set_stats_level(StatsLevel::kExceptTimeForMutex);
enum StatsLevel : uint8_t {
// Disable all metrics
kDisableAll,
// Disable tickers
kExceptTickers = kDisableAll,
// Disable timer stats, and skip histogram stats
kExceptHistogramOrTimers,
// Skip timer stats
Expand Down
16 changes: 11 additions & 5 deletions monitoring/statistics.cc
Original file line number Diff line number Diff line change
Expand Up @@ -329,11 +329,17 @@ uint64_t StatisticsImpl::getAndResetTickerCount(uint32_t tickerType) {
}

void StatisticsImpl::recordTick(uint32_t tickerType, uint64_t count) {
assert(tickerType < TICKER_ENUM_MAX);
per_core_stats_.Access()->tickers_[tickerType].fetch_add(
count, std::memory_order_relaxed);
if (stats_ && tickerType < TICKER_ENUM_MAX) {
stats_->recordTick(tickerType, count);
if (get_stats_level() <= StatsLevel::kExceptTickers) {
return;
}
if (tickerType < TICKER_ENUM_MAX) {
per_core_stats_.Access()->tickers_[tickerType].fetch_add(
count, std::memory_order_relaxed);
if (stats_) {
stats_->recordTick(tickerType, count);
}
} else {
assert(false);
}
}

Expand Down

0 comments on commit ab202e8

Please sign in to comment.