Java 类com.lmax.disruptor.collections.Histogram 实例源码

项目:log4j2    文件:RunLog4j2.java   
@Override
public void runLatencyTest(final int samples, final Histogram histogram,
        final long nanoTimeCost, final int threadCount) {
    final Logger logger = LogManager.getLogger(getClass());
    for (int i = 0; i < samples; i++) {
        final long s1 = System.nanoTime();
        logger.info(LATENCY_MSG);
        final long s2 = System.nanoTime();
        final long value = s2 - s1 - nanoTimeCost;
        if (value > 0) {
            histogram.addObservation(value);
        }
        // wait 1 microsec
        final long PAUSE_NANOS = 10000 * threadCount;
        final long pauseStart = System.nanoTime();
        while (PAUSE_NANOS > (System.nanoTime() - pauseStart)) {
            // busy spin
        }
    }
}
项目:log4j2    文件:RunLog4j1.java   
@Override
public void runLatencyTest(final int samples, final Histogram histogram,
        final long nanoTimeCost, final int threadCount) {
    final Logger logger = LogManager.getLogger(getClass());
    for (int i = 0; i < samples; i++) {
        final long s1 = System.nanoTime();
        logger.info(LATENCY_MSG);
        final long s2 = System.nanoTime();
        final long value = s2 - s1 - nanoTimeCost;
        if (value > 0) {
            histogram.addObservation(value);
        }
        // wait 1 microsec
        final long PAUSE_NANOS = 10000 * threadCount;
        final long pauseStart = System.nanoTime();
        while (PAUSE_NANOS > (System.nanoTime() - pauseStart)) {
            // busy spin
        }
    }
}
项目:log4j2    文件:RunLogback.java   
@Override
public void runLatencyTest(final int samples, final Histogram histogram,
        final long nanoTimeCost, final int threadCount) {
    final Logger logger = (Logger) LoggerFactory.getLogger(getClass());
    for (int i = 0; i < samples; i++) {
        final long s1 = System.nanoTime();
        logger.info(LATENCY_MSG);
        final long s2 = System.nanoTime();
        final long value = s2 - s1 - nanoTimeCost;
        if (value > 0) {
            histogram.addObservation(value);
        }
        // wait 1 microsec
        final long PAUSE_NANOS = 10000 * threadCount;
        final long pauseStart = System.nanoTime();
        while (PAUSE_NANOS > (System.nanoTime() - pauseStart)) {
            // busy spin
        }
    }
}
项目:logging-log4j2    文件:RunLog4j2.java   
@Override
public void runLatencyTest(final int samples, final Histogram histogram,
        final long nanoTimeCost, final int threadCount) {
    final Logger logger = LOGGER;
    for (int i = 0; i < samples; i++) {
        final long s1 = System.nanoTime();
        logger.info(LATENCY_MSG);
        final long s2 = System.nanoTime();
        final long value = s2 - s1 - nanoTimeCost;
        if (value > 0) {
            histogram.addObservation(value);
        }
        // wait 1 microsec
        final long PAUSE_NANOS = 10000 * threadCount;
        final long pauseStart = System.nanoTime();
        while (PAUSE_NANOS > (System.nanoTime() - pauseStart)) {
            // busy spin
        }
    }
}
项目:logging-log4j2    文件:RunLog4j1.java   
@Override
public void runLatencyTest(final int samples, final Histogram histogram,
        final long nanoTimeCost, final int threadCount) {
    final Logger logger = LOGGER;
    for (int i = 0; i < samples; i++) {
        final long s1 = System.nanoTime();
        logger.info(LATENCY_MSG);
        final long s2 = System.nanoTime();
        final long value = s2 - s1 - nanoTimeCost;
        if (value > 0) {
            histogram.addObservation(value);
        }
        // wait 1 microsec
        final long PAUSE_NANOS = 10000 * threadCount;
        final long pauseStart = System.nanoTime();
        while (PAUSE_NANOS > (System.nanoTime() - pauseStart)) {
            // busy spin
        }
    }
}
项目:logging-log4j2    文件:RunLogback.java   
@Override
public void runLatencyTest(final int samples, final Histogram histogram,
        final long nanoTimeCost, final int threadCount) {
    final Logger logger = LOGGER;
    for (int i = 0; i < samples; i++) {
        final long s1 = System.nanoTime();
        logger.info(LATENCY_MSG);
        final long s2 = System.nanoTime();
        final long value = s2 - s1 - nanoTimeCost;
        if (value > 0) {
            histogram.addObservation(value);
        }
        // wait 1 microsec
        final long PAUSE_NANOS = 10000 * threadCount;
        final long pauseStart = System.nanoTime();
        while (PAUSE_NANOS > (System.nanoTime() - pauseStart)) {
            // busy spin
        }
    }
}
项目:Camel    文件:SedaDisruptorCompareTest.java   
private void outputExchangeAwaitersResult(final long start) throws InterruptedException {
    for (final ExchangeAwaiter exchangeAwaiter : exchangeAwaiters) {
        final long stop = exchangeAwaiter.getCountDownReachedTime();
        final Histogram histogram = exchangeAwaiter.getLatencyHistogram();

        System.out.printf("%-45s time spent = %5d ms. Latency (ms): %s %n", componentName, stop - start, histogram.toString());
    }
}
项目:Camel    文件:SedaDisruptorCompareTest.java   
private void uninstallSizeMonitoring(final ExecutorService monitoring) {
    if (monitoring != null) {
        monitoring.shutdownNow();
    }
    final Histogram histogram = new Histogram(sizeHistogramBounds);
    for (final int observation : endpointSizeQueue) {
        histogram.addObservation(observation);
    }
    System.out.printf("%82s %s%n", "Endpoint size (# exchanges pending):", histogram.toString());
}
项目:Camel    文件:SedaDisruptorCompareTest.java   
public Histogram getLatencyHistogram() {
    final Histogram histogram = new Histogram(LATENCY_HISTOGRAM_BOUNDS);
    for (final Long latencyValue : latencyQueue) {
        histogram.addObservation(latencyValue / 1000000);
    }
    return histogram;
}
项目:log4j2    文件:RunLog4j2.java   
@Override
public void runThroughputTest(final int lines, final Histogram histogram) {
    final long s1 = System.nanoTime();
    final Logger logger = LogManager.getLogger(getClass());
    for (int j = 0; j < lines; j++) {
        logger.info(THROUGHPUT_MSG);
    }
    final long s2 = System.nanoTime();
    final long opsPerSec = (1000L * 1000L * 1000L * lines) / (s2 - s1);
    histogram.addObservation(opsPerSec);
}
项目:log4j2    文件:PerfTest.java   
static Histogram createHistogram() {
    final long[] intervals = new long[31];
    long intervalUpperBound = 1L;
    for (int i = 0, size = intervals.length - 1; i < size; i++) {
        intervalUpperBound *= 2;
        intervals[i] = intervalUpperBound;
    }

    intervals[intervals.length - 1] = Long.MAX_VALUE;
    return new Histogram(intervals);
}
项目:log4j2    文件:PerfTest.java   
public void runTestAndPrintResult(final IPerfTestRunner runner,
        final String name, final int threadCount, final String resultFile)
        throws Exception {
    final Histogram warmupHist = createHistogram();

    // ThreadContext.put("aKey", "mdcVal");
    println("Warming up the JVM...");
    final long t1 = System.nanoTime();

    // warmup at least 2 rounds and at most 1 minute
    final long stop = System.currentTimeMillis() + (60 * 1000);
    for (int i = 0; i < 10; i++) {
        final int LINES = throughput ? 50000 : 200000;
        runTest(runner, LINES, null, warmupHist, 1);
        if (i > 0 && System.currentTimeMillis() >= stop) {
            return;
        }
    }

    printf("Warmup complete in %.1f seconds%n", (System.nanoTime() - t1)
            / (1000.0 * 1000.0 * 1000.0));
    println("Waiting 10 seconds for buffers to drain warmup data...");
    Thread.sleep(10000);

    println("Starting the main test...");
    // test
    throughput = false;
    runSingleThreadedTest(runner, name, resultFile);

    Thread.sleep(1000);

    throughput = true;
    runSingleThreadedTest(runner, name, resultFile);
}
项目:log4j2    文件:PerfTest.java   
private int runSingleThreadedTest(final IPerfTestRunner runner, final String name,
        final String resultFile) throws IOException {
    final Histogram latency = createHistogram();
    final int LINES = throughput ? 50000 : 5000000;
    runTest(runner, LINES, "end", latency, 1);
    reportResult(resultFile, name, latency);
    return LINES;
}
项目:log4j2    文件:PerfTest.java   
static void reportResult(final String file, final String name, final Histogram histogram)
        throws IOException {
    final String result = createSamplingReport(name, histogram);
    println(result);

    if (file != null) {
        final FileWriter writer = new FileWriter(file, true);
        writer.write(result);
        writer.write(System.getProperty("line.separator"));
        writer.close();
    }
}
项目:log4j2    文件:PerfTest.java   
static String createSamplingReport(final String name, final Histogram histogram) {
    final Histogram data = histogram;
    if (throughput) {
        return data.getMax() + " operations/second";
    }
    final String result = String.format(
            "avg=%.0f 99%%=%d 99.99%%=%d sampleCount=%d", data.getMean(), //
            data.getTwoNinesUpperBound(), //
            data.getFourNinesUpperBound(), //
            data.getCount() //
            );
    return result;
}
项目:log4j2    文件:PerfTest.java   
public void runTest(final IPerfTestRunner runner, final int lines, final String finalMessage,
        final Histogram histogram, final int threadCount) {
    if (throughput) {
        runner.runThroughputTest(lines, histogram);
    } else {
        final long nanoTimeCost = calcNanoTimeCost();
        runner.runLatencyTest(lines, histogram, nanoTimeCost, threadCount);
    }
    if (finalMessage != null) {
        runner.log(finalMessage);
    }
}
项目:log4j2    文件:RunLog4j1.java   
@Override
public void runThroughputTest(final int lines, final Histogram histogram) {
    final long s1 = System.nanoTime();
    final Logger logger = LogManager.getLogger(getClass());
    for (int j = 0; j < lines; j++) {
        logger.info(THROUGHPUT_MSG);
    }
    final long s2 = System.nanoTime();
    final long opsPerSec = (1000L * 1000L * 1000L * lines) / (s2 - s1);
    histogram.addObservation(opsPerSec);
}
项目:log4j2    文件:RunLogback.java   
@Override
public void runThroughputTest(final int lines, final Histogram histogram) {
    final long s1 = System.nanoTime();
    final Logger logger = (Logger) LoggerFactory.getLogger(getClass());
    for (int j = 0; j < lines; j++) {
        logger.info(THROUGHPUT_MSG);
    }
    final long s2 = System.nanoTime();
    final long opsPerSec = (1000L * 1000L * 1000L * lines) / (s2 - s1);
    histogram.addObservation(opsPerSec);
}
项目:logging-log4j2    文件:RunLog4j2.java   
@Override
public void runThroughputTest(final int lines, final Histogram histogram) {
    final long s1 = System.nanoTime();
    final Logger logger = LOGGER;
    for (int j = 0; j < lines; j++) {
        logger.info(THROUGHPUT_MSG);
    }
    final long s2 = System.nanoTime();
    final long opsPerSec = (1000L * 1000L * 1000L * lines) / (s2 - s1);
    histogram.addObservation(opsPerSec);
}
项目:logging-log4j2    文件:PerfTest.java   
static Histogram createHistogram() {
    final long[] intervals = new long[31];
    long intervalUpperBound = 1L;
    for (int i = 0, size = intervals.length - 1; i < size; i++) {
        intervalUpperBound *= 2;
        intervals[i] = intervalUpperBound;
    }

    intervals[intervals.length - 1] = Long.MAX_VALUE;
    return new Histogram(intervals);
}
项目:logging-log4j2    文件:PerfTest.java   
public void runTestAndPrintResult(final IPerfTestRunner runner, final String name, final int threadCount,
        final String resultFile) throws Exception {
    final Histogram warmupHist = createHistogram();

    // ThreadContext.put("aKey", "mdcVal");
    println("Warming up the JVM...");
    final long t1 = System.nanoTime();

    // warmup at least 10 seconds
    final int LINES = 50000;
    int iterations = 0;
    final long stop = System.nanoTime() + TimeUnit.SECONDS.toNanos(10);
    do {
        runTest(runner, LINES, null, warmupHist, 1);
        iterations++;
    } while (System.nanoTime() - stop < 0);

    printf("Warmup complete in %.1f seconds (%d iterations)%n", (System.nanoTime() - t1)
            / (1000.0 * 1000.0 * 1000.0), iterations);
    println("Waiting 10 seconds for buffers to drain warmup data...");

    Thread.sleep(3000);
    //forceRemap(LINES, iterations, runner);
    Thread.sleep(7000);

    println("Starting the main test...");
    runSingleThreadedTest(runner, LINES, name, resultFile);
    Thread.sleep(1000);
}
项目:logging-log4j2    文件:PerfTest.java   
private int runSingleThreadedTest(final IPerfTestRunner runner, final int LINES, final String name,
        final String resultFile) throws IOException {
    final Histogram latency = createHistogram();
    runTest(runner, LINES, "end", latency, 1);
    reportResult(resultFile, name, latency);
    return LINES;
}
项目:logging-log4j2    文件:PerfTest.java   
static void reportResult(final String file, final String name, final Histogram histogram) throws IOException {
    final String result = createSamplingReport(name, histogram);
    println(result);

    if (file != null) {
        try (final FileWriter writer = new FileWriter(file, true)) {
            writer.write(result);
            writer.write(System.lineSeparator());
        }
    }
}
项目:logging-log4j2    文件:PerfTest.java   
static String createSamplingReport(final String name, final Histogram histogram) {
    final Histogram data = histogram;
    if (throughput) {
        return data.getMax() + " operations/second";
    }
    final String result = String.format("avg=%.0f 99%%=%d 99.99%%=%d sampleCount=%d", //
            data.getMean(), //
            data.getTwoNinesUpperBound(), //
            data.getFourNinesUpperBound(), //
            data.getCount() //
            );
    return result;
}
项目:logging-log4j2    文件:PerfTest.java   
public void runTest(final IPerfTestRunner runner, final int lines, final String finalMessage,
        final Histogram histogram, final int threadCount) {
    if (throughput) {
        runner.runThroughputTest(lines, histogram);
    } else {
        final long nanoTimeCost = calcNanoTimeCost();
        runner.runLatencyTest(lines, histogram, nanoTimeCost, threadCount);
    }
    if (finalMessage != null) {
        runner.log(finalMessage);
    }
}
项目:logging-log4j2    文件:RunLog4j1.java   
@Override
public void runThroughputTest(final int lines, final Histogram histogram) {
    final long s1 = System.nanoTime();
    final Logger logger = LOGGER;
    for (int j = 0; j < lines; j++) {
        logger.info(THROUGHPUT_MSG);
    }
    final long s2 = System.nanoTime();
    final long opsPerSec = (1000L * 1000L * 1000L * lines) / (s2 - s1);
    histogram.addObservation(opsPerSec);
}
项目:logging-log4j2    文件:RunLogback.java   
@Override
public void runThroughputTest(final int lines, final Histogram histogram) {
    final long s1 = System.nanoTime();
    final Logger logger = LOGGER;
    for (int j = 0; j < lines; j++) {
        logger.info(THROUGHPUT_MSG);
    }
    final long s2 = System.nanoTime();
    final long opsPerSec = (1000L * 1000L * 1000L * lines) / (s2 - s1);
    histogram.addObservation(opsPerSec);
}
项目:log4j2    文件:IPerfTestRunner.java   
void runLatencyTest(int samples, Histogram histogram, long nanoTimeCost,
int threadCount);
项目:log4j2    文件:MTPerfTest.java   
@Override
public void runTestAndPrintResult(final IPerfTestRunner runner,
        final String name, final int threadCount, final String resultFile)
        throws Exception {

    // ThreadContext.put("aKey", "mdcVal");
    PerfTest.println("Warming up the JVM...");
    final long t1 = System.nanoTime();

    // warmup at least 2 rounds and at most 1 minute
    final Histogram warmupHist = PerfTest.createHistogram();
    final long stop = System.currentTimeMillis() + (60 * 1000);
    final Runnable run1 = new Runnable() {
        @Override
        public void run() {
            for (int i = 0; i < 10; i++) {
                final int LINES = PerfTest.throughput ? 50000 : 200000;
                runTest(runner, LINES, null, warmupHist, 2);
                if (i > 0 && System.currentTimeMillis() >= stop) {
                    return;
                }
            }
        }
    };
    final Thread thread1 = new Thread(run1);
    final Thread thread2 = new Thread(run1);
    thread1.start();
    thread2.start();
    thread1.join();
    thread2.join();

    PerfTest.printf("Warmup complete in %.1f seconds%n",
            (System.nanoTime() - t1) / (1000.0 * 1000.0 * 1000.0));
    PerfTest.println("Waiting 10 seconds for buffers to drain warmup data...");
    Thread.sleep(10000);
    new File("perftest.log").delete();
    new File("perftest.log").createNewFile();

    PerfTest.println("Starting the main test...");
    PerfTest.throughput = false;
    multiThreadedTestRun(runner, name, threadCount, resultFile);

    Thread.sleep(1000);
    PerfTest.throughput = true;
    multiThreadedTestRun(runner, name, threadCount, resultFile);
}
项目:logging-log4j2    文件:IPerfTestRunner.java   
void runLatencyTest(int samples, Histogram histogram, long nanoTimeCost,
int threadCount);
项目:logging-log4j2    文件:AbstractRunQueue.java   
@Override
public void runThroughputTest(final int lines, final Histogram histogram) {
}
项目:logging-log4j2    文件:AbstractRunQueue.java   
@Override
public void runLatencyTest(final int samples, final Histogram histogram,
                           final long nanoTimeCost, final int threadCount) {
}
项目:logging-log4j2    文件:MultiThreadPerfTest.java   
@Override
public void runTestAndPrintResult(final IPerfTestRunner runner,
        final String name, final int threadCount, final String resultFile)
        throws Exception {

    // ThreadContext.put("aKey", "mdcVal");
    PerfTest.println("Warming up the JVM...");
    final long t1 = System.nanoTime();

    // warmup at least 2 rounds and at most 1 minute
    final Histogram warmupHist = PerfTest.createHistogram();
    final long stop = System.nanoTime() + TimeUnit.MINUTES.toNanos(1);
    final Runnable run1 = new Runnable() {
        @Override
        public void run() {
            for (int i = 0; i < 10; i++) {
                final int LINES = PerfTest.throughput ? 50000 : 200000;
                runTest(runner, LINES, null, warmupHist, 2);
                if (i > 0 && System.nanoTime() - stop >= 0) {
                    return;
                }
            }
        }
    };
    final Thread thread1 = new Thread(run1);
    final Thread thread2 = new Thread(run1);
    thread1.start();
    thread2.start();
    thread1.join();
    thread2.join();

    PerfTest.printf("Warmup complete in %.1f seconds%n",
            (System.nanoTime() - t1) / (1000.0 * 1000.0 * 1000.0));
    PerfTest.println("Waiting 10 seconds for buffers to drain warmup data...");
    Thread.sleep(10000);
    new File("perftest.log").delete();
    new File("perftest.log").createNewFile();

    PerfTest.println("Starting the main test...");
    PerfTest.throughput = false;
    multiThreadedTestRun(runner, name, threadCount, resultFile);

    Thread.sleep(1000);
    PerfTest.throughput = true;
    multiThreadedTestRun(runner, name, threadCount, resultFile);
}
项目:log4j2    文件:IPerfTestRunner.java   
void runThroughputTest(int lines, Histogram histogram);
项目:logging-log4j2    文件:IPerfTestRunner.java   
void runThroughputTest(int lines, Histogram histogram);