-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
remove percentile counter caching (#111)
A metrics reporting issue was observed where infrequent updates to percentile timers resulted in inconsistent reporting of metrics values. Unusual peaks and valleys were seen on the query side. Capturing measurement reporting from the spectatord process revealed that the base timer values were being reported in a consistent manner, but some of the percentile counters were missing. The percentile timer meters kept a local cache of the percentile counters, with shared pointer references to corresponding meters in the Registry. When the Registry expires meters, it does so based upon last update time, rather than the number of pointers still held. Thus, infrequently used percentile counters were removed from the Registry, but remained within the local percentile timer cache. The cached values would be updated, but this would not translate to the Registry, and there was no opportunity to recreate them. The fix is to remove the local percentile counter cache from the percentile timer meter, and rely on the Registry to keep track of all counters. If one is expired, it will then be recreated. This will add a little bit of overhead, but it should be minimal. The same applies to the percentile distribution summaries.
- Loading branch information
1 parent
b1fa055
commit 81c0cae
Showing
9 changed files
with
42 additions
and
121 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,63 +1,48 @@ | ||
#pragma once | ||
|
||
#include "detail/perc_policy.h" | ||
#include "id.h" | ||
#include "percentile_bucket_tags.inc" | ||
#include "percentile_buckets.h" | ||
#include "registry.h" | ||
#include "util.h" | ||
|
||
namespace spectator { | ||
|
||
template <typename policy> | ||
class percentile_timer { | ||
class PercentileTimer { | ||
public: | ||
percentile_timer(Registry* registry, Id id, absl::Duration min, | ||
absl::Duration max) noexcept | ||
PercentileTimer(Registry* registry, Id id, absl::Duration min, absl::Duration max) noexcept | ||
: registry_{registry}, | ||
id_{std::move(id)}, | ||
min_{min}, | ||
max_{max}, | ||
timer_{registry->GetTimer(id_)} { | ||
policy::init(registry_, id_, &counters_, detail::kTimerTags.begin()); | ||
timer_{registry->GetTimer(id_)} {} | ||
|
||
auto get_counter(size_t index, const std::string* perc_tags) -> std::shared_ptr<Counter> { | ||
using spectator::refs; | ||
auto counterId = id_.WithTags(refs().statistic(), refs().percentile(), refs().percentile(), | ||
intern_str(perc_tags[index])); | ||
return registry_->GetCounter(std::move(counterId)); | ||
} | ||
|
||
void Record(absl::Duration amount) noexcept { | ||
timer_->Record(amount); | ||
auto restricted = restrict(amount, min_, max_); | ||
auto index = PercentileBucketIndexOf(absl::ToInt64Nanoseconds(restricted)); | ||
auto c = policy::get_counter(registry_, id_, &counters_, index, | ||
detail::kTimerTags.begin()); | ||
auto c = get_counter(index, kTimerTags.begin()); | ||
c->Increment(); | ||
} | ||
|
||
void Record(std::chrono::nanoseconds amount) noexcept { | ||
Record(absl::FromChrono(amount)); | ||
} | ||
|
||
void Record(std::chrono::nanoseconds amount) noexcept { Record(absl::FromChrono(amount)); } | ||
auto MeterId() const noexcept -> const Id& { return id_; } | ||
auto Count() const noexcept -> int64_t { return timer_->Count(); } | ||
auto TotalTime() const noexcept -> int64_t { return timer_->TotalTime(); } | ||
auto Percentile(double p) const noexcept -> double { | ||
std::array<int64_t, PercentileBucketsLength()> counts{}; | ||
for (size_t i = 0; i < PercentileBucketsLength(); ++i) { | ||
auto& c = counters_.at(i); | ||
if (c) { | ||
counts.at(i) = c->Count(); | ||
} | ||
} | ||
auto v = spectator::Percentile(counts, p); | ||
return v / 1e9; | ||
}; | ||
|
||
private: | ||
Registry* registry_; | ||
Id id_; | ||
absl::Duration min_; | ||
absl::Duration max_; | ||
std::shared_ptr<Timer> timer_; | ||
mutable detail::counters_t counters_{}; | ||
}; | ||
|
||
using PercentileTimer = percentile_timer<detail::lazy_policy>; | ||
|
||
} // namespace spectator |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters