use of com.twitter.common.stats.ApproximateHistogram in project commons by twitter.
the class MetricsPrecisionDemo method main.
public static void main(String[] args) {
MetricsPrecisionDemo demo = new MetricsPrecisionDemo();
for (int n = 100; n <= 1000 * 1000; n *= 10) {
for (long mem = 4; mem < 16; mem += 2) {
Amount<Long, Data> maxMemory = Amount.of(mem, Data.KB);
System.out.println("\nnumber of elements:" + n + " maxMemory:" + maxMemory);
System.out.println("Real data");
demo.testHistogram(new ApproximateHistogram(maxMemory), new RealHistogram(), demo.getRealData(n));
System.out.println("Random data");
demo.testHistogram(new ApproximateHistogram(maxMemory), new RealHistogram(), demo.getRandomData(n, 100000, 200000));
}
}
}
use of com.twitter.common.stats.ApproximateHistogram in project commons by twitter.
the class ApproximateHistogramTest method testSimpleCase.
@Test
public void testSimpleCase() {
ApproximateHistogram hist = new ApproximateHistogram();
int n = 10;
initializeValues(hist, n, monotonic());
for (int i = 1; i <= n; i++) {
double q = i / 10.0;
assertEquals(i, hist.getQuantile(q), 1.0);
}
}
use of com.twitter.common.stats.ApproximateHistogram in project commons by twitter.
the class ApproximateHistogramTest method testHistogramWithEdgeCases.
@Test
public void testHistogramWithEdgeCases() {
ApproximateHistogram hist = new ApproximateHistogram();
hist.add(Long.MIN_VALUE);
assertEquals(Long.MIN_VALUE, hist.getQuantile(0.0));
assertEquals(Long.MIN_VALUE, hist.getQuantile(1.0));
hist.add(Long.MAX_VALUE);
assertEquals(Long.MIN_VALUE, hist.getQuantile(0.0));
assertEquals(Long.MAX_VALUE, hist.getQuantile(1.0));
}
use of com.twitter.common.stats.ApproximateHistogram in project commons by twitter.
the class ApproximateHistogramTest method testYetAnotherGetQuantiles.
@Test
public void testYetAnotherGetQuantiles() {
// this test originates from issue CSL-586
ApproximateHistogram hist = new ApproximateHistogram();
hist.add(0);
hist.add(4);
hist.add(9);
hist.add(8);
double[] quantiles = new double[] { 0.5, 0.9, 0.99 };
long[] expected = new long[] { 8, 9, 9 };
assertArrayEquals(hist.getQuantiles(quantiles), expected);
}
use of com.twitter.common.stats.ApproximateHistogram in project commons by twitter.
the class ApproximateHistogramTest method testMemConstraint.
@Test
public void testMemConstraint() {
ImmutableList.Builder<Amount<Long, Data>> builder = ImmutableList.builder();
builder.add(Amount.of(1L, Data.KB));
builder.add(Amount.of(4L, Data.KB));
builder.add(Amount.of(8L, Data.KB));
builder.add(Amount.of(16L, Data.KB));
builder.add(Amount.of(32L, Data.KB));
builder.add(Amount.of(64L, Data.KB));
builder.add(Amount.of(256L, Data.KB));
builder.add(Amount.of(1L, Data.MB));
builder.add(Amount.of(16L, Data.MB));
builder.add(Amount.of(32L, Data.MB));
List<Amount<Long, Data>> sizes = builder.build();
for (Amount<Long, Data> maxSize : sizes) {
ApproximateHistogram hist = new ApproximateHistogram(maxSize);
for (long i = 0; i < 1000 * 1000; i++) {
hist.add(i);
}
long size = ObjectSizeCalculator.getObjectSize(hist);
assertTrue(size < maxSize.as(Data.BYTES));
}
}
Aggregations