Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CLIPPER-227] Fix EWMA behavior for meters #228

Merged
merged 4 commits into from
Jun 24, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions src/libclipper/src/metrics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ namespace clipper {
namespace metrics {

constexpr long MICROS_PER_SECOND = 1000000;
constexpr long CLOCKS_PER_MILLISECOND = CLOCKS_PER_SEC / MICROS_PER_SECOND;
constexpr double SECONDS_PER_MINUTE = 60;
constexpr double ONE_MINUTE = 1;
constexpr double FIVE_MINUTES = 5;
Expand Down Expand Up @@ -229,8 +228,11 @@ void RatioCounter::clear() {
}

long RealTimeClock::get_time_micros() const {
clock_t clocks = clock();
return static_cast<long>(clocks) * CLOCKS_PER_MILLISECOND;
long current_time_micros =
std::chrono::duration_cast<std::chrono::microseconds>(
std::chrono::system_clock::now().time_since_epoch())
.count();
return current_time_micros;
}

void PresetClock::set_time_micros(const long time_micros) {
Expand Down Expand Up @@ -300,6 +302,7 @@ Meter::Meter(std::string name, std::shared_ptr<MeterClock> clock)
m15_rate(ewma_tick_interval_seconds_, LoadAverage::FifteenMinute) {}

void Meter::mark(uint32_t num) {
tick_if_necessary();
count_.fetch_add(num, std::memory_order_relaxed);
m1_rate.mark_uncounted(num);
m5_rate.mark_uncounted(num);
Expand All @@ -308,7 +311,10 @@ void Meter::mark(uint32_t num) {

void Meter::tick_if_necessary() {
long curr_micros = clock_->get_time_micros();
long tick_interval_micros = ewma_tick_interval_seconds_ * MICROS_PER_SECOND;
auto tick_interval_seconds =
std::chrono::seconds(ewma_tick_interval_seconds_);
long tick_interval_micros =
std::chrono::microseconds(tick_interval_seconds).count();
long last_tick = last_ewma_tick_micros_.load(std::memory_order_seq_cst);
long time_since_last_tick = curr_micros - last_tick;

Expand Down Expand Up @@ -358,6 +364,7 @@ double Meter::get_five_minute_rate_seconds() {
}

double Meter::get_fifteen_minute_rate_seconds() {
tick_if_necessary();
return m15_rate.get_rate_seconds();
}

Expand Down