use of org.HdrHistogram.Histogram in project logging-log4j2 by apache.
the class ResponseTimeTest method main.
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("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);
// ensure initialized
logger.log("Starting...");
Thread.sleep(100);
// producers + 1 consumer + 1 for OS
final int requiredProcessors = threadCount + 1 + 1;
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");
}
use of org.HdrHistogram.Histogram in project logging-log4j2 by apache.
the class ResponseTimeTest method runLatencyTest.
public static void runLatencyTest(final IPerfTestRunner logger, final long durationMillis, final int samples, final double loadMessagesPerSec, final IdleStrategy idleStrategy, final List<Histogram> serviceTmHistograms, final List<Histogram> responseTmHistograms, final int threadCount) throws InterruptedException {
final Thread[] threads = new Thread[threadCount];
final CountDownLatch LATCH = new CountDownLatch(threadCount);
for (int i = 0; i < threadCount; i++) {
final Histogram serviceTmHist = new Histogram(TimeUnit.SECONDS.toNanos(10), 3);
final Histogram responseTmHist = new Histogram(TimeUnit.SECONDS.toNanos(10), 3);
serviceTmHistograms.add(serviceTmHist);
responseTmHistograms.add(responseTmHist);
threads[i] = new Thread("latencytest-" + i) {
@Override
public void run() {
LATCH.countDown();
try {
// wait until all threads are ready to go
LATCH.await();
} catch (final InterruptedException e) {
interrupt();
return;
}
final long endTimeMillis = System.currentTimeMillis() + durationMillis;
do {
final Pacer pacer = new Pacer(loadMessagesPerSec, idleStrategy);
runLatencyTest(samples, logger, serviceTmHist, responseTmHist, pacer);
} while (System.currentTimeMillis() < endTimeMillis);
}
};
threads[i].start();
}
for (int i = 0; i < threadCount; i++) {
threads[i].join();
}
}
use of org.HdrHistogram.Histogram in project YCSB by brianfrankcooper.
the class OneMeasurementHdrHistogram method exportMeasurements.
/**
* This is called from a main thread, on orderly termination.
*/
@Override
public void exportMeasurements(MeasurementsExporter exporter) throws IOException {
// accumulate the last interval which was not caught by status thread
Histogram intervalHistogram = getIntervalHistogramAndAccumulate();
if (histogramLogWriter != null) {
histogramLogWriter.outputIntervalHistogram(intervalHistogram);
// we can close now
log.close();
}
exporter.write(getName(), "Operations", totalHistogram.getTotalCount());
exporter.write(getName(), "AverageLatency(us)", totalHistogram.getMean());
exporter.write(getName(), "MinLatency(us)", totalHistogram.getMinValue());
exporter.write(getName(), "MaxLatency(us)", totalHistogram.getMaxValue());
for (Double percentile : percentiles) {
exporter.write(getName(), ordinal(percentile) + "PercentileLatency(us)", totalHistogram.getValueAtPercentile(percentile));
}
exportStatusCounts(exporter);
}
use of org.HdrHistogram.Histogram in project YCSB by brianfrankcooper.
the class OneMeasurementHdrHistogram method getSummary.
/**
* This is called periodically from the StatusThread. There's a single
* StatusThread per Client process. We optionally serialize the interval to
* log on this opportunity.
*
* @see com.yahoo.ycsb.measurements.OneMeasurement#getSummary()
*/
@Override
public String getSummary() {
Histogram intervalHistogram = getIntervalHistogramAndAccumulate();
// we use the summary interval as the histogram file interval.
if (histogramLogWriter != null) {
histogramLogWriter.outputIntervalHistogram(intervalHistogram);
}
DecimalFormat d = new DecimalFormat("#.##");
return "[" + getName() + ": Count=" + intervalHistogram.getTotalCount() + ", Max=" + intervalHistogram.getMaxValue() + ", Min=" + intervalHistogram.getMinValue() + ", Avg=" + d.format(intervalHistogram.getMean()) + ", 90=" + d.format(intervalHistogram.getValueAtPercentile(90)) + ", 99=" + d.format(intervalHistogram.getValueAtPercentile(99)) + ", 99.9=" + d.format(intervalHistogram.getValueAtPercentile(99.9)) + ", 99.99=" + d.format(intervalHistogram.getValueAtPercentile(99.99)) + "]";
}
use of org.HdrHistogram.Histogram in project grpc-java by grpc.
the class AsyncClient method doStreamingCalls.
private static Future<Histogram> doStreamingCalls(Channel channel, final SimpleRequest request, final long endTime) {
final BenchmarkServiceStub stub = BenchmarkServiceGrpc.newStub(channel);
final Histogram histogram = new Histogram(HISTOGRAM_MAX_VALUE, HISTOGRAM_PRECISION);
final HistogramFuture future = new HistogramFuture(histogram);
ThisIsAHackStreamObserver responseObserver = new ThisIsAHackStreamObserver(request, histogram, future, endTime);
StreamObserver<SimpleRequest> requestObserver = stub.streamingCall(responseObserver);
responseObserver.requestObserver = requestObserver;
requestObserver.onNext(request);
return future;
}
Aggregations