use of com.twitter.common.stats.WindowedStatistics in project commons by twitter.
the class WindowedStatsTest method testStatsCorrectness.
@Test
public void testStatsCorrectness() {
FakeClock clock = new FakeClock();
Statistics reference = new Statistics();
WindowedStatistics ws = new WindowedStatistics(window, slices, clock);
for (int i = 0; i < 1000; i++) {
reference.accumulate(i);
ws.accumulate(i);
}
clock.advance(Amount.of(1 + sliceDuration, Time.NANOSECONDS));
ws.refresh();
assertEquals(reference.max(), ws.max());
assertEquals(reference.min(), ws.min());
assertEquals(reference.populationSize(), ws.populationSize());
assertEquals(reference.sum(), ws.sum());
assertEquals(reference.range(), ws.range());
assertEquals(reference.mean(), ws.mean(), 0.01);
assertEquals(reference.variance(), ws.variance(), 0.01);
assertEquals(reference.standardDeviation(), ws.standardDeviation(), 0.01);
for (int i = 0; i < 1000; i++) {
long x = i + 500;
reference.accumulate(x);
ws.accumulate(x);
}
clock.advance(Amount.of(sliceDuration, Time.NANOSECONDS));
ws.refresh();
assertEquals(reference.max(), ws.max());
assertEquals(reference.min(), ws.min());
assertEquals(reference.populationSize(), ws.populationSize());
assertEquals(reference.sum(), ws.sum());
assertEquals(reference.range(), ws.range());
assertEquals(reference.mean(), ws.mean(), 0.01);
assertEquals(reference.variance(), ws.variance(), 0.01);
assertEquals(reference.standardDeviation(), ws.standardDeviation(), 0.01);
for (int i = 0; i < 1000; i++) {
long x = i * i;
reference.accumulate(x);
ws.accumulate(x);
}
clock.advance(Amount.of(sliceDuration, Time.NANOSECONDS));
ws.refresh();
assertEquals(reference.max(), ws.max());
assertEquals(reference.min(), ws.min());
assertEquals(reference.populationSize(), ws.populationSize());
assertEquals(reference.sum(), ws.sum());
assertEquals(reference.range(), ws.range());
assertEquals(reference.mean(), ws.mean(), 0.01);
assertEquals(reference.variance(), ws.variance(), 0.01);
assertEquals(reference.standardDeviation(), ws.standardDeviation(), 0.01);
}
use of com.twitter.common.stats.WindowedStatistics in project commons by twitter.
the class MetricsInsertionBench method setUp.
@Override
protected void setUp() {
metrics = Metrics.createDetached();
counter = metrics.createCounter("counter");
h = metrics.createHistogram("histogram");
wh = new WindowedApproxHistogram();
ws = new WindowedStatistics();
}
use of com.twitter.common.stats.WindowedStatistics in project commons by twitter.
the class MetricsQueryBench method setUp.
@Override
protected void setUp() {
metrics = Metrics.createDetached();
FakeClock clock = new FakeClock();
Amount<Long, Time> window = WindowedApproxHistogram.DEFAULT_WINDOW;
int slices = WindowedApproxHistogram.DEFAULT_SLICES;
Amount<Long, Time> delta = Amount.of(window.as(Time.MILLISECONDS) / N, Time.MILLISECONDS);
Amount<Long, Data> maxMem = WindowedApproxHistogram.DEFAULT_MAX_MEMORY;
for (int i = 0; i < 10; i++) {
metrics.createCounter("counter-" + i).increment();
HistogramInterface h = new Histogram("hist-" + i, window, slices, maxMem, null, Histogram.DEFAULT_QUANTILES, clock, metrics);
for (int j = 0; j < N; j++) {
h.add(j);
clock.advance(delta);
}
}
// Initialize Histograms and fill them with values (in every buckets for windowed ones)
hist = new Histogram("hist", window, slices, maxMem, null, Histogram.DEFAULT_QUANTILES, clock);
approxHist = new WindowedApproxHistogram(window, slices, maxMem, clock);
winStats = new WindowedStatistics(window, slices, clock);
for (int j = 0; j < N; j++) {
hist.add(j);
approxHist.add(j);
winStats.accumulate(j);
clock.advance(delta);
}
}
use of com.twitter.common.stats.WindowedStatistics in project commons by twitter.
the class WindowedStatsTest method testAddNewValueToFullWS.
@Test
public void testAddNewValueToFullWS() {
FakeClock clock = new FakeClock();
WindowedStatistics ws = new WindowedStatistics(window, slices, clock);
// AAAAA
// BBBBB
// CCCCC
// DDDDD
// | | | |
//---------------------------------> t
// t=0 t=1 t=2 t=3
// t=0 fill {D}
long n = 1000L;
for (int i = 0; i < n; i++) {
ws.accumulate(i);
}
// read {A,B,C}, which should be empty
assertEmpty(ws);
clock.advance(Amount.of(1 + sliceDuration, Time.NANOSECONDS));
ws.refresh();
// t=1, read {B,C,D} which shouldn't be empty
assertEquals(n - 1L, ws.max());
assertEquals(0L, ws.min());
assertEquals(n, ws.populationSize());
assertEquals(n * (n - 1) / 2, ws.sum());
assertEquals((n - 1) / 2.0, ws.mean(), 0.01);
clock.advance(Amount.of(1 + sliceDuration, Time.NANOSECONDS));
ws.refresh();
// t=2, read {C,D,A} which shouldn't be empty as well
assertEquals(n - 1L, ws.max());
assertEquals(0L, ws.min());
assertEquals(n, ws.populationSize());
assertEquals(n * (n - 1) / 2, ws.sum());
assertEquals((n - 1) / 2.0, ws.mean(), 0.01);
clock.advance(Amount.of(1 + sliceDuration, Time.NANOSECONDS));
ws.refresh();
// t=3, read {D,A,B} which shouldn't be empty as well
assertEquals(n - 1L, ws.max());
assertEquals(0L, ws.min());
assertEquals(n, ws.populationSize());
assertEquals(n * (n - 1) / 2, ws.sum());
assertEquals((n - 1) / 2.0, ws.mean(), 0.01);
clock.advance(Amount.of(1 + sliceDuration, Time.NANOSECONDS));
ws.refresh();
// t=4, read {A,B,C} which must be empty (cleaned by the Windowed class)
assertEmpty(ws);
}
use of com.twitter.common.stats.WindowedStatistics in project commons by twitter.
the class WindowedStatsTest method testWindowStats.
@Test
public void testWindowStats() {
FakeClock clock = new FakeClock();
WindowedStatistics ws = new WindowedStatistics(window, slices, clock);
ws.accumulate(1L);
assertEmpty(ws);
clock.advance(Amount.of(1 + sliceDuration, Time.NANOSECONDS));
ws.refresh();
assertEquals(1L, ws.max());
assertEquals(1L, ws.min());
assertEquals(1L, ws.populationSize());
assertEquals(1L, ws.sum());
assertEquals(1.0, ws.mean(), 0.01);
assertEquals(0.0, ws.standardDeviation(), 0.01);
clock.advance(Amount.of(slices * sliceDuration, Time.NANOSECONDS));
ws.refresh();
assertEmpty(ws);
}
Aggregations