use of io.dropwizard.metrics.ExponentiallyDecayingReservoir in project light-4j by networknt.
the class ExponentiallyDecayingReservoirTest method spotLift.
@Test
public void spotLift() {
final ManualClock clock = new ManualClock();
final ExponentiallyDecayingReservoir reservoir = new ExponentiallyDecayingReservoir(1000, 0.015, clock);
final int valuesRatePerMinute = 10;
final int valuesIntervalMillis = (int) (TimeUnit.MINUTES.toMillis(1) / valuesRatePerMinute);
// mode 1: steady regime for 120 minutes
for (int i = 0; i < 120 * valuesRatePerMinute; i++) {
reservoir.update(177);
clock.addMillis(valuesIntervalMillis);
}
// switching to mode 2: 10 minutes more with the same rate, but larger value
for (int i = 0; i < 10 * valuesRatePerMinute; i++) {
reservoir.update(9999);
clock.addMillis(valuesIntervalMillis);
}
// expect that quantiles should be more about mode 2 after 10 minutes
assertThat(reservoir.getSnapshot().getMedian()).isEqualTo(9999);
}
use of io.dropwizard.metrics.ExponentiallyDecayingReservoir in project light-4j by networknt.
the class ExponentiallyDecayingReservoirTest method spotFall.
@Test
public void spotFall() {
final ManualClock clock = new ManualClock();
final ExponentiallyDecayingReservoir reservoir = new ExponentiallyDecayingReservoir(1000, 0.015, clock);
final int valuesRatePerMinute = 10;
final int valuesIntervalMillis = (int) (TimeUnit.MINUTES.toMillis(1) / valuesRatePerMinute);
// mode 1: steady regime for 120 minutes
for (int i = 0; i < 120 * valuesRatePerMinute; i++) {
reservoir.update(9998);
clock.addMillis(valuesIntervalMillis);
}
// switching to mode 2: 10 minutes more with the same rate, but smaller value
for (int i = 0; i < 10 * valuesRatePerMinute; i++) {
reservoir.update(178);
clock.addMillis(valuesIntervalMillis);
}
// expect that quantiles should be more about mode 2 after 10 minutes
assertThat(reservoir.getSnapshot().get95thPercentile()).isEqualTo(178);
}
use of io.dropwizard.metrics.ExponentiallyDecayingReservoir in project light-4j by networknt.
the class ExponentiallyDecayingReservoirTest method aReservoirOf100OutOf1000Elements.
@Test
public void aReservoirOf100OutOf1000Elements() throws Exception {
final ExponentiallyDecayingReservoir reservoir = new ExponentiallyDecayingReservoir(100, 0.99);
for (int i = 0; i < 1000; i++) {
reservoir.update(i);
}
assertThat(reservoir.size()).isEqualTo(100);
final Snapshot snapshot = reservoir.getSnapshot();
assertThat(snapshot.size()).isEqualTo(100);
assertAllValuesBetween(reservoir, 0, 1000);
}
use of io.dropwizard.metrics.ExponentiallyDecayingReservoir in project light-4j by networknt.
the class ExponentiallyDecayingReservoirTest method quantiliesShouldBeBasedOnWeights.
@Test
public void quantiliesShouldBeBasedOnWeights() {
final ManualClock clock = new ManualClock();
final ExponentiallyDecayingReservoir reservoir = new ExponentiallyDecayingReservoir(1000, 0.015, clock);
for (int i = 0; i < 40; i++) {
reservoir.update(177);
}
clock.addSeconds(120);
for (int i = 0; i < 10; i++) {
reservoir.update(9999);
}
assertThat(reservoir.getSnapshot().size()).isEqualTo(50);
// the first added 40 items (177) have weights 1
// the next added 10 items (9999) have weights ~6
// so, it's 40 vs 60 distribution, not 40 vs 10
assertThat(reservoir.getSnapshot().getMedian()).isEqualTo(9999);
assertThat(reservoir.getSnapshot().get75thPercentile()).isEqualTo(9999);
}
use of io.dropwizard.metrics.ExponentiallyDecayingReservoir in project light-4j by networknt.
the class ExponentiallyDecayingReservoirTest method aHeavilyBiasedReservoirOf100OutOf1000Elements.
@Test
public void aHeavilyBiasedReservoirOf100OutOf1000Elements() throws Exception {
final ExponentiallyDecayingReservoir reservoir = new ExponentiallyDecayingReservoir(1000, 0.01);
for (int i = 0; i < 100; i++) {
reservoir.update(i);
}
assertThat(reservoir.size()).isEqualTo(100);
final Snapshot snapshot = reservoir.getSnapshot();
assertThat(snapshot.size()).isEqualTo(100);
assertAllValuesBetween(reservoir, 0, 100);
}
Aggregations