use of com.codahale.metrics.Snapshot in project raml-module-builder by folio-org.
the class StatsTracker method calculateStatsFor.
public static JsonObject calculateStatsFor(String type) {
JsonObject j = new JsonObject();
Snapshot snap = METRICS.histogram(type).getSnapshot();
if (snap != null) {
j.put("entryCount", snap.size());
j.put("min", snap.getMin());
j.put("max", snap.getMax());
j.put("mean", snap.getMean());
j.put("median", snap.getMedian());
j.put("75th", snap.get75thPercentile());
j.put("95th", snap.get95thPercentile());
j.put("99th", snap.get99thPercentile());
j.put("stdDev", snap.getStdDev());
}
return j;
}
use of com.codahale.metrics.Snapshot in project cassandra by apache.
the class LongBTreeTest method testInsertions.
private static void testInsertions(int tests, int perTestCount, float testKeyRatio, int modificationBatchSize, boolean quickEquality) throws ExecutionException, InterruptedException {
int batchesPerTest = perTestCount / modificationBatchSize;
int testKeyRange = (int) (perTestCount * testKeyRatio);
long totalCount = (long) perTestCount * tests;
log("Performing %d tests of %d operations, with %.2f max size/key-range ratio in batches of ~%d ops", tests, perTestCount, 1 / testKeyRatio, modificationBatchSize);
// if we're not doing quick-equality, we can spam with garbage for all the checks we perform, so we'll split the work into smaller chunks
int chunkSize = quickEquality ? tests : (int) (100000 / Math.pow(perTestCount, 2));
for (int chunk = 0; chunk < tests; chunk += chunkSize) {
final List<ListenableFutureTask<List<ListenableFuture<?>>>> outer = new ArrayList<>();
for (int i = 0; i < chunkSize; i++) {
int maxRunLength = modificationBatchSize == 1 ? 1 : ThreadLocalRandom.current().nextInt(1, modificationBatchSize);
outer.add(doOneTestInsertions(testKeyRange, maxRunLength, modificationBatchSize, batchesPerTest, quickEquality));
}
final List<ListenableFuture<?>> inner = new ArrayList<>();
long complete = 0;
int reportInterval = Math.max(1000, (int) (totalCount / 10000));
long lastReportAt = 0;
for (ListenableFutureTask<List<ListenableFuture<?>>> f : outer) {
inner.addAll(f.get());
complete += perTestCount;
if (complete - lastReportAt >= reportInterval) {
long done = (chunk * perTestCount) + complete;
float ratio = done / (float) totalCount;
log("Completed %.1f%% (%d of %d operations)", ratio * 100, done, totalCount);
lastReportAt = complete;
}
}
Futures.allAsList(inner).get();
}
Snapshot snap = BTREE_TIMER.getSnapshot();
log("btree: %.2fns, %.2fns, %.2fns", snap.getMedian(), snap.get95thPercentile(), snap.get999thPercentile());
snap = TREE_TIMER.getSnapshot();
log("java: %.2fns, %.2fns, %.2fns", snap.getMedian(), snap.get95thPercentile(), snap.get999thPercentile());
log("Done");
}
use of com.codahale.metrics.Snapshot in project cassandra by apache.
the class ClientRequestSizeMetricsTest method checkMetrics.
private void checkMetrics(int numberOfRequests, long requestLength, long responseLength) {
Snapshot snapshot;
long expectedTotalBytesRead = numberOfRequests * requestLength;
assertEquals(expectedTotalBytesRead, ClientMessageSizeMetrics.bytesReceived.getCount());
long expectedTotalBytesWritten = numberOfRequests * responseLength;
assertEquals(expectedTotalBytesWritten, ClientMessageSizeMetrics.bytesSent.getCount());
// The request fit in one single frame so we know the new number of received frames
assertEquals(numberOfRequests, ClientMessageSizeMetrics.bytesReceivedPerRequest.getCount());
snapshot = ClientMessageSizeMetrics.bytesReceivedPerRequest.getSnapshot();
assertMin(snapshot, requestLength);
assertMax(snapshot, requestLength);
// The response fit in one single frame so we know the new number of received frames
assertEquals(numberOfRequests, ClientMessageSizeMetrics.bytesSentPerResponse.getCount());
snapshot = ClientMessageSizeMetrics.bytesSentPerResponse.getSnapshot();
assertMin(snapshot, responseLength);
assertMax(snapshot, responseLength);
}
use of com.codahale.metrics.Snapshot in project cassandra by apache.
the class DecayingEstimatedHistogramReservoirTest method testFindingCorrectBuckets.
@Test
public void testFindingCorrectBuckets() {
TestClock clock = new TestClock();
DecayingEstimatedHistogramReservoir histogram = new DecayingEstimatedHistogramReservoir(DecayingEstimatedHistogramReservoir.DEFAULT_ZERO_CONSIDERATION, 90, 1, clock);
histogram.update(23282687);
assertFalse(histogram.isOverflowed());
assertEquals(1, histogram.getSnapshot().getValues()[89]);
histogram.update(9);
assertEquals(1, histogram.getSnapshot().getValues()[8]);
histogram.update(21);
histogram.update(22);
Snapshot snapshot = histogram.getSnapshot();
assertEquals(2, snapshot.getValues()[13]);
assertEquals(6277304.5D, snapshot.getMean(), DOUBLE_ASSERT_DELTA);
}
use of com.codahale.metrics.Snapshot in project cassandra by apache.
the class DecayingEstimatedHistogramReservoirTest method testStriping.
@Test
public void testStriping() throws InterruptedException {
TestClock clock = new TestClock();
int nStripes = 4;
DecayingEstimatedHistogramReservoir model = new DecayingEstimatedHistogramReservoir(clock);
DecayingEstimatedHistogramReservoir test = new DecayingEstimatedHistogramReservoir(DecayingEstimatedHistogramReservoir.DEFAULT_ZERO_CONSIDERATION, DecayingEstimatedHistogramReservoir.DEFAULT_BUCKET_COUNT, nStripes, clock);
long seed = nanoTime();
System.out.println("DecayingEstimatedHistogramReservoirTest#testStriping.seed = " + seed);
Random valGen = new Random(seed);
ExecutorService executors = Executors.newFixedThreadPool(nStripes * 2);
for (int i = 0; i < 1_000_000; i++) {
long value = Math.abs(valGen.nextInt());
executors.submit(() -> {
model.update(value);
LockSupport.parkNanos(2);
test.update(value);
});
}
executors.shutdown();
Assert.assertTrue(executors.awaitTermination(1, TimeUnit.MINUTES));
Snapshot modelSnapshot = model.getSnapshot();
Snapshot testSnapshot = test.getSnapshot();
assertEquals(modelSnapshot.getMean(), testSnapshot.getMean(), DOUBLE_ASSERT_DELTA);
assertEquals(modelSnapshot.getMin(), testSnapshot.getMin(), DOUBLE_ASSERT_DELTA);
assertEquals(modelSnapshot.getMax(), testSnapshot.getMax(), DOUBLE_ASSERT_DELTA);
assertEquals(modelSnapshot.getMedian(), testSnapshot.getMedian(), DOUBLE_ASSERT_DELTA);
for (double i = 0.0; i < 1.0; i += 0.1) assertEquals(modelSnapshot.getValue(i), testSnapshot.getValue(i), DOUBLE_ASSERT_DELTA);
int stripedValues = 0;
for (int i = model.size(); i < model.size() * model.stripeCount(); i++) {
stripedValues += model.stripedBucketValue(i, true);
}
assertTrue("no striping found", stripedValues > 0);
}
Aggregations