improve-histogram-performance: remove valueIndexMap_ (#8625)
Summary: `valueIndexMap_` in histogram is redundant and search in `valueIndexMap_` is slower than search in `bucketValues_`. this PR delete `valueIndexMap_` and search in `bucketValues_` by `std::lower_bound` Pull Request resolved: https://github.com/facebook/rocksdb/pull/8625 Reviewed By: zhichao-cao Differential Revision: D31613386 Pulled By: ajkr fbshipit-source-id: d7415d724f5c8f41f80cbe82afd7467cfad6f009
This commit is contained in:
parent
c246c9c6e2
commit
97b30dee5b
@ -10,6 +10,8 @@
|
|||||||
#include "monitoring/histogram.h"
|
#include "monitoring/histogram.h"
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <cinttypes>
|
#include <cinttypes>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
@ -23,7 +25,6 @@ HistogramBucketMapper::HistogramBucketMapper() {
|
|||||||
// If you change this, you also need to change
|
// If you change this, you also need to change
|
||||||
// size of array buckets_ in HistogramImpl
|
// size of array buckets_ in HistogramImpl
|
||||||
bucketValues_ = {1, 2};
|
bucketValues_ = {1, 2};
|
||||||
valueIndexMap_ = {{1, 0}, {2, 1}};
|
|
||||||
double bucket_val = static_cast<double>(bucketValues_.back());
|
double bucket_val = static_cast<double>(bucketValues_.back());
|
||||||
while ((bucket_val = 1.5 * bucket_val) <= static_cast<double>(port::kMaxUint64)) {
|
while ((bucket_val = 1.5 * bucket_val) <= static_cast<double>(port::kMaxUint64)) {
|
||||||
bucketValues_.push_back(static_cast<uint64_t>(bucket_val));
|
bucketValues_.push_back(static_cast<uint64_t>(bucket_val));
|
||||||
@ -35,26 +36,18 @@ HistogramBucketMapper::HistogramBucketMapper() {
|
|||||||
pow_of_ten *= 10;
|
pow_of_ten *= 10;
|
||||||
}
|
}
|
||||||
bucketValues_.back() *= pow_of_ten;
|
bucketValues_.back() *= pow_of_ten;
|
||||||
valueIndexMap_[bucketValues_.back()] = bucketValues_.size() - 1;
|
|
||||||
}
|
}
|
||||||
maxBucketValue_ = bucketValues_.back();
|
maxBucketValue_ = bucketValues_.back();
|
||||||
minBucketValue_ = bucketValues_.front();
|
minBucketValue_ = bucketValues_.front();
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t HistogramBucketMapper::IndexForValue(const uint64_t value) const {
|
size_t HistogramBucketMapper::IndexForValue(const uint64_t value) const {
|
||||||
if (value >= maxBucketValue_) {
|
auto beg = bucketValues_.begin();
|
||||||
return bucketValues_.size() - 1;
|
auto end = bucketValues_.end();
|
||||||
} else if ( value >= minBucketValue_ ) {
|
if (value >= maxBucketValue_)
|
||||||
std::map<uint64_t, uint64_t>::const_iterator lowerBound =
|
return end - beg - 1; // bucketValues_.size() - 1
|
||||||
valueIndexMap_.lower_bound(value);
|
else
|
||||||
if (lowerBound != valueIndexMap_.end()) {
|
return std::lower_bound(beg, end, value) - beg;
|
||||||
return static_cast<size_t>(lowerBound->second);
|
|
||||||
} else {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
@ -48,7 +48,6 @@ class HistogramBucketMapper {
|
|||||||
std::vector<uint64_t> bucketValues_;
|
std::vector<uint64_t> bucketValues_;
|
||||||
uint64_t maxBucketValue_;
|
uint64_t maxBucketValue_;
|
||||||
uint64_t minBucketValue_;
|
uint64_t minBucketValue_;
|
||||||
std::map<uint64_t, uint64_t> valueIndexMap_;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct HistogramStat {
|
struct HistogramStat {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user