mirror of https://github.com/facebook/rocksdb.git
approximate histogram stats to save cpu
Summary: sounds like we're willing to tradeoff minor inaccuracy in stats for speed. start with histogram stats. ticker stats will be harder (and, IMO, we shouldn't change them in this manner) as many test cases rely on them being exactly correct. Closes https://github.com/facebook/rocksdb/pull/2720 Differential Revision: D5607884 Pulled By: ajkr fbshipit-source-id: 1b754cda35ea6b252d1fdd5aa3cfb58866506372
This commit is contained in:
parent
3f5888430a
commit
5de98f2d50
|
@ -105,17 +105,26 @@ void HistogramStat::Add(uint64_t value) {
|
||||||
// by concurrent threads is tolerable.
|
// by concurrent threads is tolerable.
|
||||||
const size_t index = bucketMapper.IndexForValue(value);
|
const size_t index = bucketMapper.IndexForValue(value);
|
||||||
assert(index < num_buckets_);
|
assert(index < num_buckets_);
|
||||||
buckets_[index].fetch_add(1, std::memory_order_relaxed);
|
buckets_[index].store(buckets_[index].load(std::memory_order_relaxed) + 1,
|
||||||
|
std::memory_order_relaxed);
|
||||||
|
|
||||||
uint64_t old_min = min();
|
uint64_t old_min = min();
|
||||||
while (value < old_min && !min_.compare_exchange_weak(old_min, value)) {}
|
if (value < old_min) {
|
||||||
|
min_.store(value, std::memory_order_relaxed);
|
||||||
|
}
|
||||||
|
|
||||||
uint64_t old_max = max();
|
uint64_t old_max = max();
|
||||||
while (value > old_max && !max_.compare_exchange_weak(old_max, value)) {}
|
if (value > old_max) {
|
||||||
|
max_.store(value, std::memory_order_relaxed);
|
||||||
|
}
|
||||||
|
|
||||||
num_.fetch_add(1, std::memory_order_relaxed);
|
num_.store(num_.load(std::memory_order_relaxed) + 1,
|
||||||
sum_.fetch_add(value, std::memory_order_relaxed);
|
std::memory_order_relaxed);
|
||||||
sum_squares_.fetch_add(value * value, std::memory_order_relaxed);
|
sum_.store(sum_.load(std::memory_order_relaxed) + value,
|
||||||
|
std::memory_order_relaxed);
|
||||||
|
sum_squares_.store(
|
||||||
|
sum_squares_.load(std::memory_order_relaxed) + value * value,
|
||||||
|
std::memory_order_relaxed);
|
||||||
}
|
}
|
||||||
|
|
||||||
void HistogramStat::Merge(const HistogramStat& other) {
|
void HistogramStat::Merge(const HistogramStat& other) {
|
||||||
|
|
Loading…
Reference in New Issue