Search in sources :

Example 21 with Histogram

use of org.HdrHistogram.Histogram in project grpc-java by grpc.

the class AsyncClient method run.

/**
   * Start the QPS Client.
   */
public void run() throws Exception {
    if (config == null) {
        return;
    }
    SimpleRequest req = newRequest();
    List<ManagedChannel> channels = new ArrayList<ManagedChannel>(config.channels);
    for (int i = 0; i < config.channels; i++) {
        channels.add(config.newChannel());
    }
    // Do a warmup first. It's the same as the actual benchmark, except that
    // we ignore the statistics.
    warmup(req, channels);
    long startTime = System.nanoTime();
    long endTime = startTime + TimeUnit.SECONDS.toNanos(config.duration);
    List<Histogram> histograms = doBenchmark(req, channels, endTime);
    long elapsedTime = System.nanoTime() - startTime;
    Histogram merged = merge(histograms);
    printStats(merged, elapsedTime);
    if (config.histogramFile != null) {
        saveHistogram(merged, config.histogramFile);
    }
    shutdown(channels);
}
Also used : Utils.saveHistogram(io.grpc.benchmarks.Utils.saveHistogram) Histogram(org.HdrHistogram.Histogram) ArrayList(java.util.ArrayList) ManagedChannel(io.grpc.ManagedChannel) SimpleRequest(io.grpc.benchmarks.proto.Messages.SimpleRequest)

Example 22 with Histogram

use of org.HdrHistogram.Histogram in project grpc-java by grpc.

the class OpenLoopClient method run.

/**
   * Start the open loop client.
   */
public void run() throws Exception {
    if (config == null) {
        return;
    }
    config.channels = 1;
    config.directExecutor = true;
    ManagedChannel ch = config.newChannel();
    SimpleRequest req = config.newRequest();
    LoadGenerationWorker worker = new LoadGenerationWorker(ch, req, config.targetQps, config.duration);
    final long start = System.nanoTime();
    Histogram histogram = worker.call();
    final long end = System.nanoTime();
    printStats(histogram, end - start);
    if (config.histogramFile != null) {
        saveHistogram(histogram, config.histogramFile);
    }
    ch.shutdown();
}
Also used : Utils.saveHistogram(io.grpc.benchmarks.Utils.saveHistogram) AtomicHistogram(org.HdrHistogram.AtomicHistogram) Histogram(org.HdrHistogram.Histogram) ManagedChannel(io.grpc.ManagedChannel) SimpleRequest(io.grpc.benchmarks.proto.Messages.SimpleRequest)

Example 23 with Histogram

use of org.HdrHistogram.Histogram in project grpc-java by grpc.

the class LoadClient method getStats.

/**
   * Take a snapshot of the statistics which can be returned to the driver.
   */
Stats.ClientStats getStats() {
    Histogram intervalHistogram = recorder.getIntervalHistogram();
    Stats.ClientStats.Builder statsBuilder = Stats.ClientStats.newBuilder();
    Stats.HistogramData.Builder latenciesBuilder = statsBuilder.getLatenciesBuilder();
    double resolution = 1.0 + Math.max(config.getHistogramParams().getResolution(), 0.01);
    LogarithmicIterator logIterator = new LogarithmicIterator(intervalHistogram, 1, resolution);
    double base = 1;
    while (logIterator.hasNext()) {
        latenciesBuilder.addBucket((int) logIterator.next().getCountAddedInThisIterationStep());
        base = base * resolution;
    }
    // have values.
    while (base < config.getHistogramParams().getMaxPossible()) {
        latenciesBuilder.addBucket(0);
        base = base * resolution;
    }
    latenciesBuilder.setMaxSeen(intervalHistogram.getMaxValue());
    latenciesBuilder.setMinSeen(intervalHistogram.getMinNonZeroValue());
    latenciesBuilder.setCount(intervalHistogram.getTotalCount());
    latenciesBuilder.setSum(intervalHistogram.getMean() * intervalHistogram.getTotalCount());
    // TODO: No support for sum of squares
    statsBuilder.setTimeElapsed((intervalHistogram.getEndTimeStamp() - intervalHistogram.getStartTimeStamp()) / 1000.0);
    if (osBean != null) {
        // Report all the CPU time as user-time  (which is intentionally incorrect)
        long nowCpu = osBean.getProcessCpuTime();
        statsBuilder.setTimeUser(((double) nowCpu - lastMarkCpuTime) / 1000000000.0);
        lastMarkCpuTime = nowCpu;
    }
    return statsBuilder.build();
}
Also used : Histogram(org.HdrHistogram.Histogram) LogarithmicIterator(org.HdrHistogram.LogarithmicIterator)

Example 24 with Histogram

use of org.HdrHistogram.Histogram in project grpc-java by grpc.

the class AsyncClient method merge.

private static Histogram merge(List<Histogram> histograms) {
    Histogram merged = new Histogram(HISTOGRAM_MAX_VALUE, HISTOGRAM_PRECISION);
    for (Histogram histogram : histograms) {
        for (HistogramIterationValue value : histogram.allValues()) {
            long latency = value.getValueIteratedTo();
            long count = value.getCountAtValueIteratedTo();
            merged.recordValueWithCount(latency, count);
        }
    }
    return merged;
}
Also used : Utils.saveHistogram(io.grpc.benchmarks.Utils.saveHistogram) Histogram(org.HdrHistogram.Histogram) HistogramIterationValue(org.HdrHistogram.HistogramIterationValue)

Example 25 with Histogram

use of org.HdrHistogram.Histogram in project hazelcast by hazelcast.

the class HyperLogLogEncoderAbstractTest method testEstimateErrorRateForBigCardinalities.

/**
     * - Add up-to runLength() random numbers on both a Set and a HyperLogLog encoder.
     * - Sample the actual count, and the estimate respectively every 100 operations.
     * - Compute the error rate, of the measurements and store it in a histogram.
     * - Assert that the 99th percentile of the histogram is less than the expected max error,
     * which is the result of std error (1.04 / sqrt(m)) + 3%.
     * (2% is the typical accuracy, but tests on the implementation showed up rare occurrences of 3%)
     */
@Test
public void testEstimateErrorRateForBigCardinalities() {
    double stdError = (1.04 / Math.sqrt(1 << precision())) * 100;
    double maxError = Math.ceil(stdError + 3.0);
    IntHashSet actualCount = new IntHashSet(runLength(), -1);
    Random random = new Random();
    Histogram histogram = new Histogram(5);
    ByteBuffer bb = ByteBuffer.allocate(4);
    int sampleStep = 100;
    long expected;
    long actual;
    for (int i = 1; i <= runLength(); i++) {
        int toCount = random.nextInt();
        actualCount.add(toCount);
        bb.clear();
        bb.putInt(toCount);
        encoder.add(HashUtil.MurmurHash3_x64_64(bb.array(), 0, bb.array().length));
        if (i % sampleStep == 0) {
            expected = actualCount.size();
            actual = encoder.estimate();
            double errorPct = ((actual * 100.0) / expected) - 100;
            histogram.recordValue(Math.abs((long) (errorPct * 100)));
        }
    }
    double errorPerc99 = histogram.getValueAtPercentile(99) / 100.0;
    if (errorPerc99 > maxError) {
        fail("For P=" + precision() + ", max error=" + maxError + "% expected." + " Error: " + errorPerc99 + "%.");
    }
}
Also used : Histogram(org.HdrHistogram.Histogram) Random(java.util.Random) IntHashSet(com.hazelcast.util.collection.IntHashSet) ByteBuffer(java.nio.ByteBuffer) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Aggregations

Histogram (org.HdrHistogram.Histogram)32 Utils.saveHistogram (io.grpc.benchmarks.Utils.saveHistogram)6 ByteBuffer (java.nio.ByteBuffer)6 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)5 InetSocketAddress (java.net.InetSocketAddress)4 DatagramChannel (java.nio.channels.DatagramChannel)4 ManagedChannel (io.grpc.ManagedChannel)3 SimpleRequest (io.grpc.benchmarks.proto.Messages.SimpleRequest)3 ArrayList (java.util.ArrayList)3 AtomicHistogram (org.HdrHistogram.AtomicHistogram)3 FCSubscriber (org.nustaq.fastcast.api.FCSubscriber)3 Bytez (org.nustaq.offheap.bytez.Bytez)3 ParameterException (com.beust.jcommander.ParameterException)2 RateLimiter (com.google.common.util.concurrent.RateLimiter)2 IntHashSet (com.hazelcast.util.collection.IntHashSet)2 BenchmarkServiceStub (io.grpc.benchmarks.proto.BenchmarkServiceGrpc.BenchmarkServiceStub)2 DefaultThreadFactory (io.netty.util.concurrent.DefaultThreadFactory)2 FileOutputStream (java.io.FileOutputStream)2 IOException (java.io.IOException)2 PrintStream (java.io.PrintStream)2