From 4e91f27c3a5d12a742a1c700bb802e40407bed73 Mon Sep 17 00:00:00 2001 From: Igor Canadi Date: Thu, 23 Jan 2014 16:11:55 -0800 Subject: [PATCH] Fix performance regression in statistics Summary: For some reason, D15099 caused a big performance regression: https://fburl.com/16059000 After digging a bit, I figured out that the reason was that std::atomic_uint_fast64_t was allocated in an array. When I switched from an array to vector, the QPS returned to the previous level. I'm not sure why this is happening, but this diff seems to fix the performance regression. Test Plan: I ran the regression script, observed the performance going back to normal Reviewers: tnovak, kailiu, haobo Reviewed By: kailiu CC: leveldb Differential Revision: https://reviews.facebook.net/D15375 --- util/statistics.cc | 8 +++----- util/statistics.h | 7 +++++-- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/util/statistics.cc b/util/statistics.cc index a850445ed..f86eb2c54 100644 --- a/util/statistics.cc +++ b/util/statistics.cc @@ -14,11 +14,9 @@ std::shared_ptr CreateDBStatistics() { return std::make_shared(); } -StatisticsImpl::StatisticsImpl() { - // Fill tickers_ with "zero". To ensure plasform indepedent, we used - // uint_fast64_t() instead literal `0` to represent zero. - std::fill(tickers_, tickers_ + TICKER_ENUM_MAX, uint_fast64_t()); -} +StatisticsImpl::StatisticsImpl() + : tickers_(TICKER_ENUM_MAX), + histograms_(HISTOGRAM_ENUM_MAX) {} StatisticsImpl::~StatisticsImpl() {} diff --git a/util/statistics.h b/util/statistics.h index 36456dddc..f598bdbf9 100644 --- a/util/statistics.h +++ b/util/statistics.h @@ -8,6 +8,9 @@ #include "util/histogram.h" #include "util/mutexlock.h" +#include +#include + #define UNLIKELY(val) (__builtin_expect((val), 0)) namespace rocksdb { @@ -25,8 +28,8 @@ class StatisticsImpl : public Statistics { HistogramData* const data); private: - std::atomic_uint_fast64_t tickers_[TICKER_ENUM_MAX]; - HistogramImpl histograms_[HISTOGRAM_ENUM_MAX]; + std::vector tickers_; + std::vector histograms_; }; // Utility functions