diff --git a/util/statistics.cc b/util/statistics.cc index f86eb2c54..4fc240018 100644 --- a/util/statistics.cc +++ b/util/statistics.cc @@ -14,25 +14,23 @@ std::shared_ptr CreateDBStatistics() { return std::make_shared(); } -StatisticsImpl::StatisticsImpl() - : tickers_(TICKER_ENUM_MAX), - histograms_(HISTOGRAM_ENUM_MAX) {} +StatisticsImpl::StatisticsImpl() {} StatisticsImpl::~StatisticsImpl() {} long StatisticsImpl::getTickerCount(Tickers tickerType) { assert(tickerType < TICKER_ENUM_MAX); - return tickers_[tickerType]; + return tickers_[tickerType].value; } void StatisticsImpl::setTickerCount(Tickers tickerType, uint64_t count) { assert(tickerType < TICKER_ENUM_MAX); - tickers_[tickerType] = count; + tickers_[tickerType].value = count; } void StatisticsImpl::recordTick(Tickers tickerType, uint64_t count) { assert(tickerType < TICKER_ENUM_MAX); - tickers_[tickerType] += count; + tickers_[tickerType].value += count; } void StatisticsImpl::measureTime(Histograms histogramType, uint64_t value) { diff --git a/util/statistics.h b/util/statistics.h index f598bdbf9..d8cb36e0a 100644 --- a/util/statistics.h +++ b/util/statistics.h @@ -28,8 +28,18 @@ class StatisticsImpl : public Statistics { HistogramData* const data); private: - std::vector tickers_; - std::vector histograms_; + struct Ticker { + Ticker() : value(uint_fast64_t()) {} + + std::atomic_uint_fast64_t value; + // Pad the structure to make it size of 64 bytes. A plain array of + // std::atomic_uint_fast64_t results in huge performance degradataion + // due to false sharing. + char padding[64 - sizeof(std::atomic_uint_fast64_t)]; + }; + + Ticker tickers_[TICKER_ENUM_MAX] __attribute__((aligned(64))); + HistogramImpl histograms_[HISTOGRAM_ENUM_MAX] __attribute__((aligned(64))); }; // Utility functions