Java Code Examples for org.HdrHistogram.Histogram#getTotalCount()

The following examples show how to use org.HdrHistogram.Histogram#getTotalCount() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OpenLoopClient.java    From grpc-nebula-java with Apache License 2.0 6 votes vote down vote up
private void printStats(Histogram histogram, long elapsedTime) {
  long latency50 = histogram.getValueAtPercentile(50);
  long latency90 = histogram.getValueAtPercentile(90);
  long latency95 = histogram.getValueAtPercentile(95);
  long latency99 = histogram.getValueAtPercentile(99);
  long latency999 = histogram.getValueAtPercentile(99.9);
  long latencyMax = histogram.getValueAtPercentile(100);
  long queriesPerSecond = histogram.getTotalCount() * 1000000000L / elapsedTime;

  StringBuilder values = new StringBuilder();
  values.append("Server Payload Size:            ").append(config.serverPayload).append('\n')
        .append("Client Payload Size:            ").append(config.clientPayload).append('\n')
        .append("50%ile Latency (in micros):     ").append(latency50).append('\n')
        .append("90%ile Latency (in micros):     ").append(latency90).append('\n')
        .append("95%ile Latency (in micros):     ").append(latency95).append('\n')
        .append("99%ile Latency (in micros):     ").append(latency99).append('\n')
        .append("99.9%ile Latency (in micros):   ").append(latency999).append('\n')
        .append("Maximum Latency (in micros):    ").append(latencyMax).append('\n')
        .append("Actual QPS:                     ").append(queriesPerSecond).append('\n')
        .append("Target QPS:                     ").append(config.targetQps).append('\n');
  System.out.println(values);
}
 
Example 2
Source File: AsyncClient.java    From grpc-nebula-java with Apache License 2.0 6 votes vote down vote up
private void printStats(Histogram histogram, long elapsedTime) {
  long latency50 = histogram.getValueAtPercentile(50);
  long latency90 = histogram.getValueAtPercentile(90);
  long latency95 = histogram.getValueAtPercentile(95);
  long latency99 = histogram.getValueAtPercentile(99);
  long latency999 = histogram.getValueAtPercentile(99.9);
  long latencyMax = histogram.getValueAtPercentile(100);
  long queriesPerSecond = histogram.getTotalCount() * 1000000000L / elapsedTime;

  StringBuilder values = new StringBuilder();
  values.append("Channels:                       ").append(config.channels).append('\n')
        .append("Outstanding RPCs per Channel:   ")
        .append(config.outstandingRpcsPerChannel).append('\n')
        .append("Server Payload Size:            ").append(config.serverPayload).append('\n')
        .append("Client Payload Size:            ").append(config.clientPayload).append('\n')
        .append("50%ile Latency (in micros):     ").append(latency50).append('\n')
        .append("90%ile Latency (in micros):     ").append(latency90).append('\n')
        .append("95%ile Latency (in micros):     ").append(latency95).append('\n')
        .append("99%ile Latency (in micros):     ").append(latency99).append('\n')
        .append("99.9%ile Latency (in micros):   ").append(latency999).append('\n')
        .append("Maximum Latency (in micros):    ").append(latencyMax).append('\n')
        .append("QPS:                            ").append(queriesPerSecond).append('\n');
  System.out.println(values);
}
 
Example 3
Source File: HistogramReporter.java    From perf-workshop with Apache License 2.0 6 votes vote down vote up
public void writeReport(final Histogram histogram, final PrintStream out,
                        final Set<ReportFormat> reportFormats,
                        final String histogramTitle) throws IOException
{
    if (histogram.getTotalCount() == 0L)
    {
        return;
    }
    for (final ReportFormat reportFormat : reportFormats)
    {
        switch (reportFormat)
        {
            case LONG:
                longReport(histogram, histogramTitle, out);
                break;
            case SHORT:
                shortReport(histogram, out);
                break;
            case DETAILED:
                encodedHistogram(histogram, histogramTitle, out, testLabel);
                break;
            default:
                throw new IllegalStateException("Unknown report format: " + reportFormat);
        }
    }
}
 
Example 4
Source File: OpenLoopClient.java    From grpc-java with Apache License 2.0 6 votes vote down vote up
private void printStats(Histogram histogram, long elapsedTime) {
  long latency50 = histogram.getValueAtPercentile(50);
  long latency90 = histogram.getValueAtPercentile(90);
  long latency95 = histogram.getValueAtPercentile(95);
  long latency99 = histogram.getValueAtPercentile(99);
  long latency999 = histogram.getValueAtPercentile(99.9);
  long latencyMax = histogram.getValueAtPercentile(100);
  long queriesPerSecond = histogram.getTotalCount() * 1000000000L / elapsedTime;

  StringBuilder values = new StringBuilder();
  values.append("Server Payload Size:            ").append(config.serverPayload).append('\n')
        .append("Client Payload Size:            ").append(config.clientPayload).append('\n')
        .append("50%ile Latency (in micros):     ").append(latency50).append('\n')
        .append("90%ile Latency (in micros):     ").append(latency90).append('\n')
        .append("95%ile Latency (in micros):     ").append(latency95).append('\n')
        .append("99%ile Latency (in micros):     ").append(latency99).append('\n')
        .append("99.9%ile Latency (in micros):   ").append(latency999).append('\n')
        .append("Maximum Latency (in micros):    ").append(latencyMax).append('\n')
        .append("Actual QPS:                     ").append(queriesPerSecond).append('\n')
        .append("Target QPS:                     ").append(config.targetQps).append('\n');
  System.out.println(values);
}
 
Example 5
Source File: AsyncClient.java    From grpc-java with Apache License 2.0 6 votes vote down vote up
private void printStats(Histogram histogram, long elapsedTime) {
  long latency50 = histogram.getValueAtPercentile(50);
  long latency90 = histogram.getValueAtPercentile(90);
  long latency95 = histogram.getValueAtPercentile(95);
  long latency99 = histogram.getValueAtPercentile(99);
  long latency999 = histogram.getValueAtPercentile(99.9);
  long latencyMax = histogram.getValueAtPercentile(100);
  long queriesPerSecond = histogram.getTotalCount() * 1000000000L / elapsedTime;

  StringBuilder values = new StringBuilder();
  values.append("Channels:                       ").append(config.channels).append('\n')
        .append("Outstanding RPCs per Channel:   ")
        .append(config.outstandingRpcsPerChannel).append('\n')
        .append("Server Payload Size:            ").append(config.serverPayload).append('\n')
        .append("Client Payload Size:            ").append(config.clientPayload).append('\n')
        .append("50%ile Latency (in micros):     ").append(latency50).append('\n')
        .append("90%ile Latency (in micros):     ").append(latency90).append('\n')
        .append("95%ile Latency (in micros):     ").append(latency95).append('\n')
        .append("99%ile Latency (in micros):     ").append(latency99).append('\n')
        .append("99.9%ile Latency (in micros):   ").append(latency999).append('\n')
        .append("Maximum Latency (in micros):    ").append(latencyMax).append('\n')
        .append("QPS:                            ").append(queriesPerSecond).append('\n');
  System.out.println(values);
}
 
Example 6
Source File: HistogramLogProcessor.java    From hazelcast-simulator with Apache License 2.0 6 votes vote down vote up
protected Object[] buildRegularHistogramStatistics(Histogram intervalHistogram, Histogram accumulatedRegularHistogram) {
    return new Object[]{((intervalHistogram.getEndTimeStamp() / 1000.0) - logReader.getStartTimeSec()),
            // values recorded during the last reporting interval
            intervalHistogram.getTotalCount(),
            intervalHistogram.getValueAtPercentile(50.0) / config.outputValueUnitRatio,
            intervalHistogram.getValueAtPercentile(90.0) / config.outputValueUnitRatio,
            intervalHistogram.getMaxValue() / config.outputValueUnitRatio,
            // values recorded from the beginning until now
            accumulatedRegularHistogram.getTotalCount(),
            accumulatedRegularHistogram.getValueAtPercentile(50.0) / config.outputValueUnitRatio,
            accumulatedRegularHistogram.getValueAtPercentile(90.0) / config.outputValueUnitRatio,
            accumulatedRegularHistogram.getValueAtPercentile(99.0) / config.outputValueUnitRatio,
            accumulatedRegularHistogram.getValueAtPercentile(99.9) / config.outputValueUnitRatio,
            accumulatedRegularHistogram.getValueAtPercentile(99.99) / config.outputValueUnitRatio,
            accumulatedRegularHistogram.getMaxValue() / config.outputValueUnitRatio};
}
 
Example 7
Source File: HistogramUtil.java    From rolling-metrics with Apache License 2.0 5 votes vote down vote up
public static Snapshot getSnapshot(Histogram histogram, Function<Histogram, Snapshot> snapshotTaker) {
    if (histogram.getTotalCount() > 0) {
        return snapshotTaker.apply(histogram);
    } else {
        return EmptySnapshot.INSTANCE;
    }
}
 
Example 8
Source File: NetworkLatencyMetricsCollector.java    From couchbase-jvm-core with Apache License 2.0 5 votes vote down vote up
@Override
protected NetworkLatencyMetricsEvent generateLatencyMetricsEvent(
    final Map<NetworkLatencyMetricsIdentifier, LatencyStats> latencyMetrics) {

    Map<NetworkLatencyMetricsIdentifier, LatencyMetric> sortedMetrics =
        new TreeMap<NetworkLatencyMetricsIdentifier, LatencyMetric>();


    for (Map.Entry<NetworkLatencyMetricsIdentifier, LatencyStats> entry : latencyMetrics.entrySet()) {
        Histogram histogram = entry.getValue().getIntervalHistogram();

        if (histogram.getTotalCount() == 0) {
            // no events have been found on this identifier in the last interval, so remove it and
            // do not include it in the output.
            remove(entry.getKey());
            continue;
        }

        Map<Double, Long> percentiles = new TreeMap<Double, Long>();
        for (double targetPercentile : targetPercentiles) {
            percentiles.put(targetPercentile, targetUnit.convert(
                histogram.getValueAtPercentile(targetPercentile), TimeUnit.NANOSECONDS)
            );
        }

        sortedMetrics.put(entry.getKey(), new LatencyMetric(
            targetUnit.convert(histogram.getMinValue(), TimeUnit.NANOSECONDS),
            targetUnit.convert(histogram.getMaxValue(), TimeUnit.NANOSECONDS),
            histogram.getTotalCount(),
            percentiles,
            targetUnit
        ));
    }

    return new NetworkLatencyMetricsEvent(sortedMetrics);
}
 
Example 9
Source File: WorkerLatencyWriterSanityTest.java    From maestro-java with Apache License 2.0 4 votes vote down vote up
@Test(timeout = 120_000L)
public void shouldWriteLatencies() throws IOException, InterruptedException {
    final int receivers = 10;
    final int events = 10;
    //there are 1 producer + 1 consumer each one emitting events
    final int totalEvents = events * receivers;
    final CountDownLatch eventsProcessed = new CountDownLatch(totalEvents);
    //use 1 capacity and wait until each message has been processed
    final DummyReceiverWorker[] dummyReceiverWorkers = new DummyReceiverWorker[receivers];
    final long globalStart = System.currentTimeMillis();
    final long fixedLatency = 100;
    for (int i = 0; i < receivers; i++) {
        dummyReceiverWorkers[i] = new DummyReceiverWorker();
        dummyReceiverWorkers[i].startedEpochMillis = globalStart;
    }
    final Thread roundRobinReceivers = new Thread(() -> {
        for (int i = 0; i < events; i++) {
            for (DummyReceiverWorker worker : dummyReceiverWorkers) {
                worker.recorder.recordValue(fixedLatency);
                eventsProcessed.countDown();
            }
        }
    });
    roundRobinReceivers.start();
    final File reportFolder = tempTestFolder.newFolder("report");
    final WorkerLatencyWriter latencyWriter = new WorkerLatencyWriter(reportFolder, Arrays.asList(dummyReceiverWorkers));
    final Thread writerThread = new Thread(latencyWriter);
    writerThread.setDaemon(true);
    writerThread.start();
    eventsProcessed.await();
    roundRobinReceivers.join();
    writerThread.interrupt();
    writerThread.join();
    final String latencyFileName = "receiverd-latency.hdr";
    final String[] reports = reportFolder.list((dir, name) -> name.equals(latencyFileName));
    Assert.assertArrayEquals(new String[]{latencyFileName}, reports);
    final File reportFile = new File(reportFolder, Objects.requireNonNull(reports)[0]);
    Assert.assertTrue(reportFile.length() > 0);
    final HistogramLogReader histogramLogReader = new HistogramLogReader(reportFile);
    int totalReports = 0;
    while (histogramLogReader.hasNext()) {
        final EncodableHistogram encodableHistogram = histogramLogReader.nextIntervalHistogram();
        if (encodableHistogram instanceof Histogram) {
            final Histogram histogram = (Histogram) encodableHistogram;
            final long totalCount = histogram.getTotalCount();
            Assert.assertEquals("Each histogram must contain the same number of recorded events of each receiver", events, totalCount);
            Assert.assertEquals("Min recorded value must be " + fixedLatency, fixedLatency, histogram.getMinValue());
            Assert.assertEquals("Max recorded value must be " + fixedLatency, fixedLatency, histogram.getMaxValue());
            Assert.assertEquals("Mean recorded value must be " + fixedLatency, (double) fixedLatency, histogram.getMean(), 0d);
        }
        totalReports++;
    }
    Assert.assertEquals("The histogram number must be the same of the receivers", receivers, totalReports);
}
 
Example 10
Source File: HistogramUtil.java    From rolling-metrics with Apache License 2.0 4 votes vote down vote up
public static void reset(Histogram histogram) {
    if (histogram.getTotalCount() > 0) {
        histogram.reset();
    }
}
 
Example 11
Source File: HistogramUtil.java    From rolling-metrics with Apache License 2.0 4 votes vote down vote up
public static void addSecondToFirst(Histogram first, Histogram second) {
    if (second.getTotalCount() > 0) {
        first.add(second);
    }
}
 
Example 12
Source File: SimulatorHistogramLogProcessor.java    From hazelcast-simulator with Apache License 2.0 4 votes vote down vote up
protected Object[] buildRegularHistogramStatistics(Histogram intervalHistogram, Histogram accumulatedHistogram) {
    double intervalThroughput = ((double) (intervalHistogram.getTotalCount())
            / (intervalHistogram.getEndTimeStamp() - intervalHistogram.getStartTimeStamp()));

    double totalThroughput = ((double) accumulatedHistogram.getTotalCount())
            / (accumulatedHistogram.getEndTimeStamp() - accumulatedHistogram.getStartTimeStamp());

    return new Object[]{
            ((intervalHistogram.getEndTimeStamp() / 1000.0) - logReader.getStartTimeSec()),
            (intervalHistogram.getEndTimeStamp() / 1000.0),
            // values recorded during the last reporting interval
            intervalHistogram.getTotalCount(),
            intervalHistogram.getValueAtPercentile(25.0) / config.outputValueUnitRatio,
            intervalHistogram.getValueAtPercentile(50.0) / config.outputValueUnitRatio,
            intervalHistogram.getValueAtPercentile(75.0) / config.outputValueUnitRatio,
            intervalHistogram.getValueAtPercentile(90.0) / config.outputValueUnitRatio,
            intervalHistogram.getValueAtPercentile(99.0) / config.outputValueUnitRatio,
            intervalHistogram.getValueAtPercentile(99.9) / config.outputValueUnitRatio,
            intervalHistogram.getValueAtPercentile(99.99) / config.outputValueUnitRatio,
            intervalHistogram.getValueAtPercentile(99.999) / config.outputValueUnitRatio,
            intervalHistogram.getMinValue() / config.outputValueUnitRatio,
            intervalHistogram.getMaxValue() / config.outputValueUnitRatio,
            intervalHistogram.getMean() / config.outputValueUnitRatio,
            intervalHistogram.getStdDeviation() / config.outputValueUnitRatio,
            intervalThroughput / config.outputValueUnitRatio,

            // values recorded from the beginning until now
            accumulatedHistogram.getTotalCount(),
            accumulatedHistogram.getValueAtPercentile(25.0) / config.outputValueUnitRatio,
            accumulatedHistogram.getValueAtPercentile(50.0) / config.outputValueUnitRatio,
            accumulatedHistogram.getValueAtPercentile(75.0) / config.outputValueUnitRatio,
            accumulatedHistogram.getValueAtPercentile(90.0) / config.outputValueUnitRatio,
            accumulatedHistogram.getValueAtPercentile(99.0) / config.outputValueUnitRatio,
            accumulatedHistogram.getValueAtPercentile(99.9) / config.outputValueUnitRatio,
            accumulatedHistogram.getValueAtPercentile(99.99) / config.outputValueUnitRatio,
            accumulatedHistogram.getValueAtPercentile(99.999) / config.outputValueUnitRatio,
            accumulatedHistogram.getMinValue() / config.outputValueUnitRatio,
            accumulatedHistogram.getMaxValue() / config.outputValueUnitRatio,
            accumulatedHistogram.getMean() / config.outputValueUnitRatio,
            accumulatedHistogram.getStdDeviation() / config.outputValueUnitRatio,
            totalThroughput / config.outputValueUnitRatio,
    };
}
 
Example 13
Source File: TestPerformanceTracker.java    From hazelcast-simulator with Apache License 2.0 4 votes vote down vote up
private void makeUpdate(long updateIntervalMillis, long currentTimeMillis) {
    Map<String, Probe> probeMap = testContainer.getProbeMap();
    Map<String, Histogram> intervalHistograms = new HashMap<>(probeMap.size());

    long intervalPercentileLatency = -1;
    double intervalMean = -1;
    long intervalMaxLatency = -1;

    long iterations = testContainer.iteration() - iterationsDuringWarmup;
    long intervalOperationCount = iterations - lastIterations;

    for (Map.Entry<String, Probe> entry : probeMap.entrySet()) {
        String probeName = entry.getKey();
        Probe probe = entry.getValue();
        if (!(probe instanceof HdrProbe)) {
            continue;
        }

        HdrProbe hdrProbe = (HdrProbe) probe;
        Histogram intervalHistogram = hdrProbe.getRecorder().getIntervalHistogram();
        intervalHistogram.setStartTimeStamp(lastUpdateMillis);
        intervalHistogram.setEndTimeStamp(currentTimeMillis);
        intervalHistograms.put(probeName, intervalHistogram);

        long percentileValue = intervalHistogram.getValueAtPercentile(INTERVAL_LATENCY_PERCENTILE);
        if (percentileValue > intervalPercentileLatency) {
            intervalPercentileLatency = percentileValue;
        }

        double meanLatency = intervalHistogram.getMean();
        if (meanLatency > intervalMean) {
            intervalMean = meanLatency;
        }

        long maxValue = intervalHistogram.getMaxValue();
        if (maxValue > intervalMaxLatency) {
            intervalMaxLatency = maxValue;
        }

        if (probe.isPartOfTotalThroughput()) {
            intervalOperationCount += intervalHistogram.getTotalCount();
        }
    }

    this.intervalHistogramMap = intervalHistograms;

    this.intervalLatency999PercentileNanos = intervalPercentileLatency;
    this.intervalLatencyAvgNanos = intervalMean;
    this.intervalLatencyMaxNanos = intervalMaxLatency;

    this.intervalOperationCount = intervalOperationCount;
    this.totalOperationCount += intervalOperationCount;

    long intervalTimeDelta = currentTimeMillis - lastUpdateMillis;
    long totalTimeDelta = currentTimeMillis - testContainer.getRunStartedMillis();

    this.intervalThroughput = (intervalOperationCount * ONE_SECOND_IN_MILLIS) / (double) intervalTimeDelta;
    this.totalThroughput = (totalOperationCount * ONE_SECOND_IN_MILLIS / (double) totalTimeDelta);

    this.lastIterations = iterations;
    this.nextUpdateMillis += updateIntervalMillis;
    this.lastUpdateMillis = currentTimeMillis;
}