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

The following examples show how to use org.HdrHistogram.Histogram#add() . 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: ResultsAggregator.java    From benchmarks with Apache License 2.0 6 votes vote down vote up
private Histogram aggregateHistograms(final Entry<String, List<Path>> entry) throws FileNotFoundException
{
    Histogram aggregate = null;

    for (final Path file : entry.getValue())
    {
        try (HistogramLogReader logReader = new HistogramLogReader(file.toFile()))
        {
            while (logReader.hasNext())
            {
                final Histogram histogram = (Histogram)logReader.nextIntervalHistogram();
                if (null == aggregate)
                {
                    aggregate = histogram;
                }
                else
                {
                    aggregate.add(histogram);
                }
            }
        }
    }

    return aggregate;
}
 
Example 2
Source File: Accumulator.java    From perf-workshop with Apache License 2.0 5 votes vote down vote up
private Histogram mergeHistogramsAfterWarmupPeriod(final Histogram[] histograms)
{
    final Histogram target = HISTOGRAMS.createHistogram();
    for (int i = 0; i < histograms.length; i++)
    {
        if(i > commandLineArgs.getNumberOfWarmups())
        {
            target.add(histograms[i]);
        }
    }

    return target;
}
 
Example 3
Source File: HdrHistogramPerformanceBenchmark.java    From incubator-gobblin with Apache License 2.0 5 votes vote down vote up
@Benchmark
public Histogram trackMergeHistogram(HistogramState histogramState) {
  Histogram histogram = new Histogram(histogramState.MIN_VALUE, histogramState.MAX_VALUE, 3);
  histogram.add(histogramState.histogram1);
  histogram.add(histogramState.histogram2);
  histogram.add(histogramState.histogram3);
  histogram.add(histogramState.histogram4);
  return histogram;
}
 
Example 4
Source File: HistogramTrimmer.java    From hazelcast-simulator with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws FileNotFoundException {
    File inputFile = new File(args[0]);
    File outputFile = new File(inputFile.getParent(), inputFile.getName() + ".tmp");
    long startMillis = Long.parseLong(args[1]);
    long endMillis = Long.parseLong(args[2]);

    HistogramLogReader reader = new HistogramLogReader(inputFile);
    HistogramLogWriter writer = new HistogramLogWriter(outputFile);
    for (; ; ) {
        Histogram histogram = (Histogram) reader.nextIntervalHistogram();
        if (histogram == null) {
            break;
        }

        if (histogram.getStartTimeStamp() >= startMillis && histogram.getEndTimeStamp() <= endMillis) {
            Histogram out = new Histogram(
                    histogram.getLowestDiscernibleValue(),
                    histogram.getHighestTrackableValue(),
                    histogram.getNumberOfSignificantValueDigits());
            out.setStartTimeStamp(histogram.getStartTimeStamp());
            out.setEndTimeStamp(histogram.getEndTimeStamp());
            out.add(histogram);
            writer.outputIntervalHistogram(out);
        }
    }

    outputFile.renameTo(new File(args[0]));
}
 
Example 5
Source File: ResponseTimeTest.java    From logging-log4j2 with Apache License 2.0 5 votes vote down vote up
private static Histogram createResultHistogram(final List<Histogram> list, final long start, final long end) {
    final Histogram result = new Histogram(TimeUnit.SECONDS.toNanos(10), 3);
    result.setStartTimeStamp(start);
    result.setEndTimeStamp(end);
    for (final Histogram hist : list) {
        result.add(hist);
    }
    return result;
}
 
Example 6
Source File: PutBench.java    From kudu-ts with Apache License 2.0 4 votes vote down vote up
protected void run(Environment environment,
                   Namespace namespace,
                   KTSDConfiguration config) throws Exception {

  final CloseableHttpClient client =
      new HttpClientBuilder(environment).using(config.getBench().getHttpClient())
                                        .build(getName());

  long start = config.getBench().getStart();
  long end = config.getBench().getEnd();
  if (end == 0) end = System.currentTimeMillis();
  if (start == 0) start = end - TimeUnit.HOURS.toMillis(1);
  if (start < 0) start = end - start;

  URI uri = new URIBuilder()
      .setScheme("http")
      .setHost(config.getBench().getKtsdHost())
      .setPort(config.getBench().getKtsdPort())
      .setPath("/api/put")
      .setParameter("summary", "true")
      .build();

  List<SortedMap<String, String>> tags = new ArrayList<>();
  tags.add(new TreeMap<String, String>());
  for (Map.Entry<String, List<String>> tag : config.getBench().getTags().entrySet()) {
    List<SortedMap<String, String>> original = tags;
    tags = new ArrayList<>();
    for (String value : tag.getValue()) {
      for (SortedMap<String, String> ts : original) {
        SortedMap<String, String> copy = new TreeMap<>(ts);
        copy.put(tag.getKey(), value);
        tags.add(copy);
      }
    }
  }

  CountDownLatch latch = new CountDownLatch(config.getBench().getMetrics().size() * tags.size());
  LatencyStats stats = new LatencyStats();

  List<Thread> threads = new ArrayList<>();
  for (String metric : config.getBench().getMetrics()) {
    for (SortedMap<String, String> tagset : tags) {
      DatapointGenerator datapoints = new DatapointGenerator(threads.size(), start, end,
                                                             config.getBench().getSampleFrequency());
      threads.add(new Thread(new PutSeries(uri, metric, tagset, datapoints, stats,
                                           client, environment.getObjectMapper(), latch)));
    }
  }

  for (Thread thread : threads) {
    thread.start();
  }

  Histogram hist = stats.getIntervalHistogram();
  while (!latch.await(10, TimeUnit.SECONDS)) {
    Histogram latest = stats.getIntervalHistogram();
    hist.add(latest);

    LOG.info("Progress:");
    LOG.info("puts: {}/{}", latest.getTotalCount(), hist.getTotalCount());
    LOG.info("mean latency: {}/{}", TimeUnit.NANOSECONDS.toMillis((long) latest.getMean()),
                                    TimeUnit.NANOSECONDS.toMillis((long) hist.getMean()));
    LOG.info("min: {}/{}", TimeUnit.NANOSECONDS.toMillis(latest.getMinValue()),
                           TimeUnit.NANOSECONDS.toMillis(hist.getMinValue()));
    LOG.info("max: {}/{}", TimeUnit.NANOSECONDS.toMillis(latest.getMaxValue()),
                           TimeUnit.NANOSECONDS.toMillis(hist.getMaxValue()));
    LOG.info("p50: {}/{}", TimeUnit.NANOSECONDS.toMillis(latest.getValueAtPercentile(50)),
                           TimeUnit.NANOSECONDS.toMillis(hist.getValueAtPercentile(50)));
    LOG.info("p99: {}/{}", TimeUnit.NANOSECONDS.toMillis(latest.getValueAtPercentile(99)),
                           TimeUnit.NANOSECONDS.toMillis(hist.getValueAtPercentile(99)));
  }

  LOG.info("Benchmark complete");
  LOG.info("puts: {}", hist.getTotalCount());
  LOG.info("mean latency: {}", TimeUnit.NANOSECONDS.toMillis((long) hist.getMean()));
  LOG.info("stddev: {}", TimeUnit.NANOSECONDS.toMillis((long) hist.getStdDeviation()));
  LOG.info("min: {}", TimeUnit.NANOSECONDS.toMillis(hist.getMinValue()));
  LOG.info("max: {}", TimeUnit.NANOSECONDS.toMillis(hist.getMaxValue()));
  LOG.info("p50: {}", TimeUnit.NANOSECONDS.toMillis(hist.getValueAtPercentile(50)));
  LOG.info("p90: {}", TimeUnit.NANOSECONDS.toMillis(hist.getValueAtPercentile(90)));
  LOG.info("p95: {}", TimeUnit.NANOSECONDS.toMillis(hist.getValueAtPercentile(95)));
  LOG.info("p99: {}", TimeUnit.NANOSECONDS.toMillis(hist.getValueAtPercentile(99)));
  LOG.info("p999: {}", TimeUnit.NANOSECONDS.toMillis(hist.getValueAtPercentile(99.9)));
}
 
Example 7
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);
    }
}