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);
}
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();
}
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();
}
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;
}
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 + "%.");
}
}
Aggregations