org.HdrHistogram.EncodableHistogram Java Examples

The following examples show how to use org.HdrHistogram.EncodableHistogram. 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: PersistedHistogramTest.java    From benchmarks with Apache License 2.0 6 votes vote down vote up
private Histogram readHistogram(final Path file) throws FileNotFoundException
{
    final List<EncodableHistogram> histograms = new ArrayList<>();
    final HistogramLogReader logReader = new HistogramLogReader(file.toFile());
    try
    {
        while (logReader.hasNext())
        {
            histograms.add(logReader.nextIntervalHistogram());
        }
    }
    finally
    {
        logReader.close();
    }
    assertEquals(1, histograms.size());
    return (Histogram)histograms.get(0);
}
 
Example #2
Source File: HistogramLogProcessor.java    From hazelcast-simulator with Apache License 2.0 6 votes vote down vote up
private EncodableHistogram getIntervalHistogram() {
    EncodableHistogram histogram = null;
    try {
        histogram = logReader.nextIntervalHistogram(config.rangeStartTimeSec, config.rangeEndTimeSec);
    } catch (RuntimeException ex) {
        System.err.println("Log file parsing error at line number " + lineNumber +
                ": line appears to be malformed.");
        if (config.verbose) {
            throw ex;
        } else {
            exitWithError();
        }
    }
    lineNumber++;
    return histogram;
}
 
Example #3
Source File: HistogramLogProcessor.java    From hazelcast-simulator with Apache License 2.0 5 votes vote down vote up
private EncodableHistogram getIntervalHistogram(String tag) {
    EncodableHistogram histogram;
    if (tag == null) {
        do {
            histogram = getIntervalHistogram();
        } while ((histogram != null) && histogram.getTag() != null);
    } else {
        do {
            histogram = getIntervalHistogram();
        } while ((histogram != null) && !tag.equals(histogram.getTag()));
    }
    return histogram;
}
 
Example #4
Source File: Util.java    From maestro-java with Apache License 2.0 4 votes vote down vote up
public static Histogram getAccumulated(final File histogramFile) throws FileNotFoundException {
    Histogram accumulatedHistogram = null;
    DoubleHistogram accumulatedDoubleHistogram = null;

    HistogramLogReader histogramLogReader = new HistogramLogReader(histogramFile);

    int i = 0;
    while (histogramLogReader.hasNext()) {
        EncodableHistogram eh = histogramLogReader.nextIntervalHistogram();
        if (eh == null) {
            logger.error("The histogram library returned an unexpected null value");
            break;
        }

        if (i == 0) {
            if (eh instanceof DoubleHistogram) {
                accumulatedDoubleHistogram = ((DoubleHistogram) eh).copy();
                accumulatedDoubleHistogram.reset();
                accumulatedDoubleHistogram.setAutoResize(true);
            }
            else {
                accumulatedHistogram = ((Histogram) eh).copy();
                accumulatedHistogram.reset();
                accumulatedHistogram.setAutoResize(true);
            }
        }

        logger.debug("Processing histogram from point in time {} to {}",
                Instant.ofEpochMilli(eh.getStartTimeStamp()), Instant.ofEpochMilli(eh.getEndTimeStamp()));

        if (eh instanceof DoubleHistogram) {
            Objects.requireNonNull(accumulatedDoubleHistogram).add((DoubleHistogram) eh);
        }
        else {
            Objects.requireNonNull(accumulatedHistogram).add((Histogram) eh);
        }

        i++;
    }

    if (accumulatedHistogram == null) {
        throw new EmptyDataSet("The HDR data file did not contain any histogram data");
    }

    return accumulatedHistogram;
}
 
Example #5
Source File: DefaultHistogramHandler.java    From maestro-java with Apache License 2.0 4 votes vote down vote up
private void doSave(final EncodableHistogram eh, final File histogramFile) throws IOException {
    Properties prop = new Properties();

    prop.setProperty("latencyStartTS", Long.toString(eh.getStartTimeStamp()));
    prop.setProperty("latencyEndTS", Long.toString(eh.getEndTimeStamp()));

    prop.setProperty("latencyMaxValue", Double.toString(eh.getMaxValueAsDouble() / unitRatio));


    if (eh instanceof AbstractHistogram) {
        AbstractHistogram ah = (AbstractHistogram) eh;

        prop.setProperty("latency50th", Long.toString(ah.getValueAtPercentile(50.0) / (long) unitRatio));
        prop.setProperty("latency90th", Long.toString(ah.getValueAtPercentile(90.0) / (long) unitRatio));
        prop.setProperty("latency95th", Long.toString(ah.getValueAtPercentile(95.0) / (long) unitRatio));
        prop.setProperty("latency99th", Long.toString(ah.getValueAtPercentile(99.0) / (long) unitRatio));
        prop.setProperty("latency999th", Long.toString(ah.getValueAtPercentile(99.9) / (long) unitRatio));
        prop.setProperty("latency9999th", Long.toString(ah.getValueAtPercentile(99.99) / (long) unitRatio));
        prop.setProperty("latency99999th", Long.toString(ah.getValueAtPercentile(99.999) / (long) unitRatio));
        prop.setProperty("latencyStdDeviation", Double.toString(ah.getStdDeviation() / unitRatio));
        prop.setProperty("latencyTotalCount", Long.toString(ah.getTotalCount()));
        prop.setProperty("latencyMean", Double.toString(ah.getMean() / unitRatio));


    }
    else {
        if (eh instanceof DoubleHistogram) {
            DoubleHistogram dh = (DoubleHistogram) eh;

            prop.setProperty("latency50th", Double.toString(dh.getValueAtPercentile(50.0) / unitRatio));
            prop.setProperty("latency90th", Double.toString(dh.getValueAtPercentile(90.0) / unitRatio));
            prop.setProperty("latency95th", Double.toString(dh.getValueAtPercentile(95.0) / unitRatio));
            prop.setProperty("latency99th", Double.toString(dh.getValueAtPercentile(99.0) / unitRatio));
            prop.setProperty("latency999th", Double.toString(dh.getValueAtPercentile(99.9) / unitRatio));
            prop.setProperty("latency9999th", Double.toString(dh.getValueAtPercentile(99.99) / unitRatio));
            prop.setProperty("latency99999th", Double.toString(dh.getValueAtPercentile(99.999) / unitRatio));
            prop.setProperty("latencyStdDeviation", Double.toString(dh.getStdDeviation() / unitRatio));
            prop.setProperty("latencyTotalCount", Long.toString(dh.getTotalCount()));
            prop.setProperty("latencyMean", Double.toString(dh.getMean() / unitRatio));
        }
    }

    File outFile = new File(histogramFile.getParentFile(), "latency.properties");
    try (OutputStream fos = new BufferedOutputStream(new FileOutputStream(outFile))) {
        prop.store(fos, "hdr-histogram-plotter");
    }
}
 
Example #6
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 #7
Source File: LatencyWriter.java    From maestro-java with Apache License 2.0 2 votes vote down vote up
/**
 * Sets up the output interval histogram
 * @param histogram the output interval histogram
 */
public void outputIntervalHistogram(EncodableHistogram histogram) {
    logWriter.outputIntervalHistogram(histogram);
}