Search in sources :

Example 11 with Snapshot

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;
}
Also used : Snapshot(com.codahale.metrics.Snapshot) JsonObject(io.vertx.core.json.JsonObject)

Example 12 with Snapshot

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");
}
Also used : Snapshot(com.codahale.metrics.Snapshot) ListenableFutureTask(com.google.common.util.concurrent.ListenableFutureTask) ListenableFuture(com.google.common.util.concurrent.ListenableFuture)

Example 13 with Snapshot

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);
}
Also used : EstimatedHistogramReservoirSnapshot(org.apache.cassandra.metrics.DecayingEstimatedHistogramReservoir.EstimatedHistogramReservoirSnapshot) Snapshot(com.codahale.metrics.Snapshot)

Example 14 with Snapshot

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);
}
Also used : Snapshot(com.codahale.metrics.Snapshot) Test(org.junit.Test)

Example 15 with Snapshot

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);
}
Also used : Snapshot(com.codahale.metrics.Snapshot) Random(java.util.Random) ExecutorService(java.util.concurrent.ExecutorService) Test(org.junit.Test)

Aggregations

Snapshot (com.codahale.metrics.Snapshot)57 Test (org.junit.Test)13 Histogram (com.codahale.metrics.Histogram)11 Timer (com.codahale.metrics.Timer)11 Map (java.util.Map)6 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)4 ConcurrentMap (java.util.concurrent.ConcurrentMap)4 HashMap (java.util.HashMap)3 SortedMap (java.util.SortedMap)3 MetricSnapshot (backtype.storm.generated.MetricSnapshot)2 JAverageSnapshot (com.alibaba.jstorm.common.metric.codahale.JAverageSnapshot)2 Counter (com.codahale.metrics.Counter)2 Gauge (com.codahale.metrics.Gauge)2 Meter (com.codahale.metrics.Meter)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 InOrder (org.mockito.InOrder)2 SlidingWindowReservoir (com.codahale.metrics.SlidingWindowReservoir)1 UniformReservoir (com.codahale.metrics.UniformReservoir)1 ResultSet (com.datastax.driver.core.ResultSet)1 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)1