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

The following examples show how to use org.HdrHistogram.Histogram#outputPercentileDistribution() . 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: Main.java    From jbender with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) throws SuspendExecution, InterruptedException {
  final IntervalGenerator intervalGen = new ConstantIntervalGenerator(10000000);
  final RequestExecutor<EchoRequest, EchoResponse> requestExector = new EchoRequestExecutor();

  final Channel<EchoRequest> requestCh = Channels.newChannel(-1);
  final Channel<TimingEvent<EchoResponse>> eventCh = Channels.newChannel(-1);

  // Requests generator
  new Fiber<Void>("req-gen", () -> {
    for (int i=0; i < 1000; ++i) {
      final EchoRequest req = new EchoRequest();
      req.setMessage("foo");
      requestCh.send(req);
    }

    requestCh.close();
  }).start();

  final Histogram histogram = new Histogram(3600000000L, 3);
  // Event recording, both HistHDR and logging
  record(eventCh, new HdrHistogramRecorder(histogram, 1000000), new LoggingRecorder(LOG));

  JBender.loadTestThroughput(intervalGen, 0, requestCh, requestExector, eventCh);

  histogram.outputPercentileDistribution(System.out, 1000.0);
}
 
Example 2
Source File: TextReporter.java    From Rainfall-core with Apache License 2.0 6 votes vote down vote up
@Override
  public void summarize(final StatisticsHolder<E> statisticsHolder) {
//    sb.append(String.format(FORMAT, "Cache", "Type", "Txn_Count", "TPS", "Avg_Lat"))
    Enum<E>[] results = statisticsHolder.getResultsReported();
    for (Enum<E> result : results) {
      System.out.println("Percentiles distribution for result : " + result);
      try {
        Histogram histogram = statisticsHolder.fetchHistogram(result);
        try {
          histogram = histogram.copyCorrectedForCoordinatedOmission(1000L);
        } catch (Throwable t) {
          // again, inexplicably needed
        }
        histogram.outputPercentileDistribution(System.out, 5, 1000000d, false);
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
  }
 
Example 3
Source File: LoadTest.java    From jbender with Apache License 2.0 5 votes vote down vote up
public static void main(final String[] args) throws SuspendExecution, InterruptedException, ExecutionException, IOReactorException, IOException {
  final IntervalGenerator intervalGenerator = new ConstantIntervalGenerator(10000000);
  try (final FiberApacheHttpClientRequestExecutor requestExecutor =
          new FiberApacheHttpClientRequestExecutor<>((res) -> {
            if (res == null) {
              throw new AssertionError("Response is null");
            }
            final int status = res.getStatusLine().getStatusCode();
            if (status != 200) {
              throw new AssertionError("Status is " + status);
            }
          }, 1000000)) {

    final Channel<HttpGet> requestCh = Channels.newChannel(1000);
    final Channel<TimingEvent<CloseableHttpResponse>> eventCh = Channels.newChannel(1000);

    // Requests generator
    new Fiber<Void>("req-gen", () -> {
      // Bench handling 1k reqs
      for (int i = 0; i < 1000; ++i) {
        requestCh.send(new HttpGet("http://localhost:8080/hello-world"));
      }

      requestCh.close();
    }).start();

    final Histogram histogram = new Histogram(3600000000L, 3);

    // Event recording, both HistHDR and logging
    record(eventCh, new HdrHistogramRecorder(histogram, 1000000), new LoggingRecorder(LOG));

    // Main
    new Fiber<Void>("jbender", () -> {
      JBender.loadTestThroughput(intervalGenerator, 0, requestCh, requestExecutor, eventCh);
    }).start().join();

    histogram.outputPercentileDistribution(System.out, 1000.0);
  }
}
 
Example 4
Source File: ResultsAggregator.java    From benchmarks with Apache License 2.0 5 votes vote down vote up
private void createReportFile(final Histogram aggregate, final Path reportFile) throws IOException
{
    try (FileOutputStream fos = new FileOutputStream(reportFile.toFile(), false);
        PrintStream printStream = new PrintStream(fos))
    {
        aggregate.outputPercentileDistribution(printStream, reportOutputScalingRatio);
    }
}
 
Example 5
Source File: ResultsAggregatorTest.java    From benchmarks with Apache License 2.0 5 votes vote down vote up
private byte[] outputPercentileDistribution(final Histogram histogram, final double outputValueUnitScalingRatio)
{
    final ByteArrayOutputStream bos = new ByteArrayOutputStream();
    try (PrintStream printStream = new PrintStream(bos))
    {
        histogram.outputPercentileDistribution(printStream, outputValueUnitScalingRatio);
    }

    return bos.toByteArray();
}
 
Example 6
Source File: Printer.java    From rolling-metrics with Apache License 2.0 5 votes vote down vote up
public static String histogramToString(Histogram histogram) {
    try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
        PrintStream writer = new PrintStream(baos);
        histogram.outputPercentileDistribution(writer, 1.0);
        byte[] resultBytes = baos.toByteArray();
        return new String(resultBytes);
    } catch (IOException e) {
        throw new IllegalStateException(e);
    }
}
 
Example 7
Source File: SendHackSelectReceiveUdpPing.java    From aeron with Apache License 2.0 5 votes vote down vote up
private void measureRoundTrip(
    final Histogram histogram,
    final InetSocketAddress sendAddress,
    final ByteBuffer buffer,
    final DatagramChannel sendChannel,
    final Selector selector,
    final NioSelectedKeySet keySet,
    final AtomicBoolean running)
    throws IOException
{
    for (sequenceNumber = 0; sequenceNumber < Common.NUM_MESSAGES; sequenceNumber++)
    {
        final long timestampNs = System.nanoTime();

        buffer.clear();
        buffer.putLong(sequenceNumber);
        buffer.putLong(timestampNs);
        buffer.flip();

        sendChannel.send(buffer, sendAddress);

        while (selector.selectNow() == 0)
        {
            if (!running.get())
            {
                return;
            }
        }

        keySet.forEach(this);
    }

    histogram.outputPercentileDistribution(System.out, 1000.0);
}
 
Example 8
Source File: StatsTest.java    From Rainfall-core with Apache License 2.0 4 votes vote down vote up
@Test
@Ignore
public void testStatsHolderOnly() {
  ScheduledExecutorService topOfSecondExecutor = Executors.newSingleThreadScheduledExecutor();

  final Reporter reporter = text();
  final ReportingConfig reportingConfig = ReportingConfig.report(StatsTestResult.class).log(reporter);

  final RuntimeStatisticsHolder<StatsTestResult> statisticsHolder = new RuntimeStatisticsHolder<StatsTestResult>(
      reportingConfig.getResults(), reportingConfig.getResultsReported(),
      reportingConfig.getStatisticsCollectors()
  );

  String name = "MY_TEST";

  TimeUnit reportIntervalUnit = reportingConfig.getReportTimeUnit();
  long reportIntervalMillis = reportIntervalUnit.toMillis(reportingConfig.getReportInterval());

  Calendar myDate = Calendar.getInstance();
  myDate.add(Calendar.SECOND, 1);
  myDate.set(Calendar.MILLISECOND, 0);
  Date afterOneSecond = myDate.getTime();
  long delay = afterOneSecond.getTime() - System.currentTimeMillis() - 4;
  topOfSecondExecutor.scheduleAtFixedRate(new Runnable() {
    @Override
    public void run() {
      reporter.report(statisticsHolder.peek());
    }
  }, delay, reportIntervalMillis, TimeUnit.MILLISECONDS);

  Map<Long, String> pseudoCache = new HashMap<Long, String>();
  for (long i = 0; i < 3000000; i++) {
    long start = statisticsHolder.getTimeInNs();
    pseudoCache.put(i % 100000, UUID.randomUUID().toString());
    long end = statisticsHolder.getTimeInNs();

    statisticsHolder.record(name, end - start, RESULT);
  }

  topOfSecondExecutor.shutdown();

  Histogram histogram = statisticsHolder.fetchHistogram(RESULT);
  histogram.outputPercentileDistribution(System.out, 1.0);
}
 
Example 9
Source File: WriteReceiveUdpPing.java    From aeron with Apache License 2.0 4 votes vote down vote up
private static void measureRoundTrip(
    final Histogram histogram,
    final ByteBuffer buffer,
    final DatagramChannel[] receiveChannels,
    final DatagramChannel writeChannel,
    final AtomicBoolean running)
    throws IOException
{
    for (int sequenceNumber = 0; sequenceNumber < Common.NUM_MESSAGES; sequenceNumber++)
    {
        final long timestampNs = System.nanoTime();

        buffer.clear();
        buffer.putLong(sequenceNumber);
        buffer.putLong(timestampNs);
        buffer.flip();

        writeChannel.write(buffer);

        buffer.clear();
        boolean available = false;
        while (!available)
        {
            if (!running.get())
            {
                return;
            }

            for (int i = receiveChannels.length - 1; i >= 0; i--)
            {
                if (null != receiveChannels[i].receive(buffer))
                {
                    available = true;
                    break;
                }
            }
        }

        final long receivedSequenceNumber = buffer.getLong(0);
        if (receivedSequenceNumber != sequenceNumber)
        {
            throw new IllegalStateException("Data Loss:" + sequenceNumber + " to " + receivedSequenceNumber);
        }

        final long durationNs = System.nanoTime() - buffer.getLong(SIZE_OF_LONG);
        histogram.recordValue(durationNs);
    }

    histogram.outputPercentileDistribution(System.out, 1000.0);
}
 
Example 10
Source File: SendSelectReceiveUdpPing.java    From aeron with Apache License 2.0 4 votes vote down vote up
private void measureRoundTrip(
    final Histogram histogram,
    final InetSocketAddress sendAddress,
    final ByteBuffer buffer,
    final DatagramChannel sendChannel,
    final Selector selector,
    final AtomicBoolean running)
    throws IOException
{
    for (sequenceNumber = 0; sequenceNumber < Common.NUM_MESSAGES; sequenceNumber++)
    {
        final long timestamp = System.nanoTime();

        buffer.clear();
        buffer.putLong(sequenceNumber);
        buffer.putLong(timestamp);
        buffer.flip();

        sendChannel.send(buffer, sendAddress);

        while (selector.selectNow() == 0)
        {
            if (!running.get())
            {
                return;
            }
        }

        final Set<SelectionKey> selectedKeys = selector.selectedKeys();
        final Iterator<SelectionKey> iter = selectedKeys.iterator();

        while (iter.hasNext())
        {
            final SelectionKey key = iter.next();
            if (key.isReadable())
            {
                ((IntSupplier)key.attachment()).getAsInt();
            }

            iter.remove();
        }
    }

    histogram.outputPercentileDistribution(System.out, 1000.0);
}
 
Example 11
Source File: SendReceiveUdpPing.java    From aeron with Apache License 2.0 4 votes vote down vote up
private static void measureRoundTrip(
    final Histogram histogram,
    final InetSocketAddress sendAddress,
    final ByteBuffer buffer,
    final DatagramChannel[] receiveChannels,
    final DatagramChannel sendChannel,
    final AtomicBoolean running)
    throws IOException
{
    for (int sequenceNumber = 0; sequenceNumber < Common.NUM_MESSAGES; sequenceNumber++)
    {
        final long timestampNs = System.nanoTime();

        buffer.clear();
        buffer.putLong(sequenceNumber);
        buffer.putLong(timestampNs);
        buffer.flip();

        sendChannel.send(buffer, sendAddress);

        buffer.clear();
        boolean available = false;
        while (!available)
        {
            if (!running.get())
            {
                return;
            }

            for (int i = receiveChannels.length - 1; i >= 0; i--)
            {
                if (null != receiveChannels[i].receive(buffer))
                {
                    available = true;
                    break;
                }
            }
        }

        final long receivedSequenceNumber = buffer.getLong(0);
        if (receivedSequenceNumber != sequenceNumber)
        {
            throw new IllegalStateException("Data Loss:" + sequenceNumber + " to " + receivedSequenceNumber);
        }

        final long durationNs = System.nanoTime() - buffer.getLong(BitUtil.SIZE_OF_LONG);
        histogram.recordValue(durationNs);
    }

    histogram.outputPercentileDistribution(System.out, 1000.0);
}
 
Example 12
Source File: ResponseTimeTest.java    From logging-log4j2 with Apache License 2.0 4 votes vote down vote up
public static void main(final String[] args) throws Exception {
    if (args.length < 2) {
        System.out.println("Please specify thread count, target throughput (msg/sec) " +
                "and logger library (Log4j1, Log4j2, Logback, JUL)");
        return;
    }
    final int threadCount = Integer.parseInt(args[0]);
    final double loadMessagesPerSec = Double.parseDouble(args[1]);
    final String loggerLib = args.length > 2 ? args[2] : "Log4j2";

    // print to console if ringbuffer is full
    System.setProperty("log4j2.AsyncQueueFullPolicy", PrintingAsyncQueueFullPolicy.class.getName());
    System.setProperty("AsyncLogger.RingBufferSize", String.valueOf(256 * 1024));
    //System.setProperty("Log4jContextSelector", AsyncLoggerContextSelector.class.getName());
    //System.setProperty("log4j.configurationFile", "perf3PlainNoLoc.xml");
    if (System.getProperty("AsyncLogger.WaitStrategy") == null) {
        System.setProperty("AsyncLogger.WaitStrategy", "Yield");
    }
    //for (Object key : System.getProperties().keySet()) {
    //    System.out.println(key + "=" + System.getProperty((String) key));
    //}

    // initialize the logger
    final String wrapper = loggerLib.startsWith("Run") ? loggerLib : "Run" + loggerLib;
    final String loggerWrapperClass = "org.apache.logging.log4j.core.async.perftest." + wrapper;
    final IPerfTestRunner logger = Loader.newCheckedInstanceOf(loggerWrapperClass, IPerfTestRunner.class);
    logger.log("Starting..."); // ensure initialized
    Thread.sleep(100);

    final int requiredProcessors = threadCount + 1 + 1; // producers + 1 consumer + 1 for OS
    final IdleStrategy idleStrategy = Runtime.getRuntime().availableProcessors() > requiredProcessors
            ? new NoOpIdleStrategy()
            : new YieldIdleStrategy();

    System.out.printf("%s: %d threads, load is %,f msg/sec, using %s%n", loggerLib, threadCount,
            loadMessagesPerSec, idleStrategy.getClass().getSimpleName());

    // Warmup: run as many iterations of 50,000 calls to logger.log as we can in 1 minute
    final long WARMUP_DURATION_MILLIS = TimeUnit.MINUTES.toMillis(1);
    final List<Histogram> warmupServiceTmHistograms = new ArrayList<>(threadCount);
    final List<Histogram> warmupResponseTmHistograms = new ArrayList<>(threadCount);

    final int WARMUP_COUNT = 50000 / threadCount;
    runLatencyTest(logger, WARMUP_DURATION_MILLIS, WARMUP_COUNT, loadMessagesPerSec, idleStrategy,
            warmupServiceTmHistograms, warmupResponseTmHistograms, threadCount);
    System.out.println("-----------------Warmup done. load=" + loadMessagesPerSec);
    if (!Constants.ENABLE_DIRECT_ENCODERS || !Constants.ENABLE_THREADLOCALS) {
        //System.gc();
        //Thread.sleep(5000);
    }
    System.out.println("-----------------Starting measured run. load=" + loadMessagesPerSec);

    final long start = System.currentTimeMillis();
    final List<Histogram> serviceTmHistograms = new ArrayList<>(threadCount);
    final List<Histogram> responseTmHistograms = new ArrayList<>(threadCount);
    PrintingAsyncQueueFullPolicy.ringbufferFull.set(0);

    // Actual test: run as many iterations of 1,000,000 calls to logger.log as we can in 4 minutes.
    final long TEST_DURATION_MILLIS = TimeUnit.MINUTES.toMillis(4);
    final int COUNT = (1000 * 1000) / threadCount;
    runLatencyTest(logger, TEST_DURATION_MILLIS, COUNT, loadMessagesPerSec, idleStrategy, serviceTmHistograms,
            responseTmHistograms, threadCount);
    logger.shutdown();
    final long end = System.currentTimeMillis();

    // ... and report the results
    final Histogram resultServiceTm = createResultHistogram(serviceTmHistograms, start, end);
    resultServiceTm.outputPercentileDistribution(System.out, 1000.0);
    writeToFile("s", resultServiceTm, (int) (loadMessagesPerSec / 1000), 1000.0);

    final Histogram resultResponseTm = createResultHistogram(responseTmHistograms, start, end);
    resultResponseTm.outputPercentileDistribution(System.out, 1000.0);
    writeToFile("r", resultResponseTm, (int) (loadMessagesPerSec / 1000), 1000.0);

    System.out.printf("%n%s: %d threads, load %,f msg/sec, ringbuffer full=%d%n", loggerLib, threadCount,
            loadMessagesPerSec, PrintingAsyncQueueFullPolicy.ringbufferFull.get());
    System.out.println("Test duration: " + (end - start) / 1000.0 + " seconds");
}
 
Example 13
Source File: ResponseTimeTest.java    From logging-log4j2 with Apache License 2.0 4 votes vote down vote up
private static void writeToFile(final String suffix, final Histogram hist, final int thousandMsgPerSec,
        final double scale) throws IOException {
    try (PrintStream pout = new PrintStream(new FileOutputStream(thousandMsgPerSec + "k" + suffix))) {
        hist.outputPercentileDistribution(pout, scale);
    }
}