Skip to content

Commit

Permalink
Use StepCounter instead of BasicCounter
Browse files Browse the repository at this point in the history
StepCounter has more overhead, but the
normalization and sampling of BasicCounter
can lead to rate variations when aggregating
across many counters. Example of from
counters that should all be the same:

atlas_2014_22_10_15_42_01_951.log.gz

  1.618458   ReciprocalRank
  1.545702   Rank
  1.672844   RankFraction
  1.763815   BinaryDiscountedCumulativeGain

atlas_2014_22_10_15_42_57_012.log.gz

  1.284395   ReciprocalRank
  1.248162   Rank
  1.248178   RankFraction
  1.356733   BinaryDiscountedCumulativeGain

atlas_2014_22_10_15_43_52_066.log.gz

  2.111525   ReciprocalRank
  1.856574   Rank
  1.983977   RankFraction
  2.220634   BinaryDiscountedCumulativeGain

atlas_2014_22_10_15_44_47_197.log.gz

  1.832837   ReciprocalRank
  1.742114   Rank
  1.760254   RankFraction
  1.941755   BinaryDiscountedCumulativeGain

atlas_2014_22_10_15_45_42_452.log.gz

  2.210017   ReciprocalRank
  2.064924   Rank
  2.264092   RankFraction
  2.336758   BinaryDiscountedCumulativeGain
  • Loading branch information
brharrington committed Oct 22, 2014
1 parent c3d0d12 commit cb48f8b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,20 @@

import java.util.Collections;
import java.util.List;
import java.util.concurrent.atomic.AtomicLong;

/** Counter implementation for the servo registry. */
class ServoCounter implements Counter, ServoMeter {

private final Clock clock;
private final com.netflix.servo.monitor.BasicCounter impl;
private final com.netflix.servo.monitor.StepCounter impl;
private final AtomicLong count;

/** Create a new instance. */
ServoCounter(Clock clock, com.netflix.servo.monitor.BasicCounter impl) {
ServoCounter(Clock clock, com.netflix.servo.monitor.StepCounter impl) {
this.clock = clock;
this.impl = impl;
this.count = new AtomicLong(0L);
}

@Override public void addMonitors(List<Monitor<?>> monitors) {
Expand All @@ -50,19 +53,21 @@ class ServoCounter implements Counter, ServoMeter {

@Override public Iterable<Measurement> measure() {
long now = clock.wallTime();
long v = count();
double v = impl.getValue(0).doubleValue();
return Collections.singleton(new Measurement(id(), now, v));
}

@Override public void increment() {
impl.increment();
count.incrementAndGet();
}

@Override public void increment(long amount) {
impl.increment(amount);
count.addAndGet(amount);
}

@Override public long count() {
return impl.getValue(0).longValue();
return count.get();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ MonitorConfig toMonitorConfig(Id id) {

@Override protected Counter newCounter(Id id) {
MonitorConfig cfg = toMonitorConfig(id);
BasicCounter counter = new BasicCounter(cfg);
StepCounter counter = new StepCounter(cfg, new ServoClock(clock()));
return new ServoCounter(clock(), counter);
}

Expand Down

0 comments on commit cb48f8b

Please sign in to comment.