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
This commit is contained in:
Igor Canadi 2014-01-23 16:11:55 -08:00
parent d0458469c8
commit 4e91f27c3a
2 changed files with 8 additions and 7 deletions

View File

@ -14,11 +14,9 @@ std::shared_ptr<Statistics> CreateDBStatistics() {
return std::make_shared<StatisticsImpl>(); return std::make_shared<StatisticsImpl>();
} }
StatisticsImpl::StatisticsImpl() { StatisticsImpl::StatisticsImpl()
// Fill tickers_ with "zero". To ensure plasform indepedent, we used : tickers_(TICKER_ENUM_MAX),
// uint_fast64_t() instead literal `0` to represent zero. histograms_(HISTOGRAM_ENUM_MAX) {}
std::fill(tickers_, tickers_ + TICKER_ENUM_MAX, uint_fast64_t());
}
StatisticsImpl::~StatisticsImpl() {} StatisticsImpl::~StatisticsImpl() {}

View File

@ -8,6 +8,9 @@
#include "util/histogram.h" #include "util/histogram.h"
#include "util/mutexlock.h" #include "util/mutexlock.h"
#include <vector>
#include <atomic>
#define UNLIKELY(val) (__builtin_expect((val), 0)) #define UNLIKELY(val) (__builtin_expect((val), 0))
namespace rocksdb { namespace rocksdb {
@ -25,8 +28,8 @@ class StatisticsImpl : public Statistics {
HistogramData* const data); HistogramData* const data);
private: private:
std::atomic_uint_fast64_t tickers_[TICKER_ENUM_MAX]; std::vector<std::atomic_uint_fast64_t> tickers_;
HistogramImpl histograms_[HISTOGRAM_ENUM_MAX]; std::vector<HistogramImpl> histograms_;
}; };
// Utility functions // Utility functions