From df22e2fb71be07d25448a01e1eef77f65506b429 Mon Sep 17 00:00:00 2001 From: Andres Noetzli Date: Tue, 15 Sep 2015 10:52:00 -0700 Subject: [PATCH] Relax memory order for faster tickers Summary: The default behavior for atomic operations is sequentially consistent ordering which is not needed for simple counters (see: http://en.cppreference.com/w/cpp/atomic/memory_order). Change the memory order to std::memory_order_relaxed for better performance. Test Plan: make clean all check Reviewers: rven, anthony, yhchiang, aekmekji, sdong, MarkCallaghan, igor Reviewed By: igor Subscribers: dhruba, leveldb Differential Revision: https://reviews.facebook.net/D46953 --- util/statistics.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/util/statistics.cc b/util/statistics.cc index f06589a17b1..8a7525c81ae 100644 --- a/util/statistics.cc +++ b/util/statistics.cc @@ -62,7 +62,7 @@ void StatisticsImpl::setTickerCount(uint32_t tickerType, uint64_t count) { tickerType < INTERNAL_TICKER_ENUM_MAX : tickerType < TICKER_ENUM_MAX); if (tickerType < TICKER_ENUM_MAX || enable_internal_stats_) { - tickers_[tickerType].value = count; + tickers_[tickerType].value.store(count, std::memory_order_relaxed); } if (stats_ && tickerType < TICKER_ENUM_MAX) { stats_->setTickerCount(tickerType, count); @@ -75,7 +75,7 @@ void StatisticsImpl::recordTick(uint32_t tickerType, uint64_t count) { tickerType < INTERNAL_TICKER_ENUM_MAX : tickerType < TICKER_ENUM_MAX); if (tickerType < TICKER_ENUM_MAX || enable_internal_stats_) { - tickers_[tickerType].value += count; + tickers_[tickerType].value.fetch_add(count, std::memory_order_relaxed); } if (stats_ && tickerType < TICKER_ENUM_MAX) { stats_->recordTick(tickerType, count);