diff --git a/core/src/main/java/com/yahoo/ycsb/measurements/OneMeasurementHistogram.java b/core/src/main/java/com/yahoo/ycsb/measurements/OneMeasurementHistogram.java index 2cba955a2a3c926f1d7b719c26b9696562522a08..4e8f5642e3ad2b20854f431eba5024a8aba19d72 100644 --- a/core/src/main/java/com/yahoo/ycsb/measurements/OneMeasurementHistogram.java +++ b/core/src/main/java/com/yahoo/ycsb/measurements/OneMeasurementHistogram.java @@ -36,11 +36,39 @@ public class OneMeasurementHistogram extends OneMeasurement public static final String BUCKETS="histogram.buckets"; public static final String BUCKETS_DEFAULT="1000"; + + /** + * Specify the range of latencies to track in the histogram. + */ int _buckets; + + /** + * Groups operations in discrete blocks of 1ms width. + */ int[] histogram; + + /** + * Counts all operations outside the histogram's range. + */ int histogramoverflow; + + /** + * The total number of reported operations. + */ int operations; - long totallatency; + + /** + * The sum of each latency measurement over all operations. + * Calculated in ms. + */ + double totallatency; + + /** + * The sum of each latency measurement squared over all operations. + * Used to calculate variance of latency. + * Calculated in ms. + */ + double totalsquaredlatency; //keep a windowed version of these stats for printing status int windowoperations; @@ -58,6 +86,7 @@ public class OneMeasurementHistogram extends OneMeasurement histogramoverflow=0; operations=0; totallatency=0; + totalsquaredlatency=0; windowoperations=0; windowtotallatency=0; min=-1; @@ -86,6 +115,7 @@ public class OneMeasurementHistogram extends OneMeasurement */ public synchronized void measure(int latency) { + //latency reported in us and collected in bucket by ms. if (latency/1000>=_buckets) { histogramoverflow++; @@ -95,10 +125,11 @@ public class OneMeasurementHistogram extends OneMeasurement histogram[latency/1000]++; } operations++; - totallatency+=latency; + totallatency += ((double)latency) / 1000; + totalsquaredlatency += ((double)latency) * ((double)latency) / 1000000; windowoperations++; - windowtotallatency+=latency; - + windowtotallatency += latency; + if ( (min<0) || (latency<min) ) { min=latency; @@ -112,10 +143,14 @@ public class OneMeasurementHistogram extends OneMeasurement @Override - public void exportMeasurements(MeasurementsExporter exporter) throws IOException + public void exportMeasurements(MeasurementsExporter exporter) + throws IOException { + double mean = totallatency/((double)operations); + double variance = totalsquaredlatency/((double)operations) - (mean * mean); exporter.write(getName(), "Operations", operations); - exporter.write(getName(), "AverageLatency(us)", (((double)totallatency)/((double)operations))); + exporter.write(getName(), "AverageLatency(ms)", mean); + exporter.write(getName(), "LatencyVariance(ms)", variance); exporter.write(getName(), "MinLatency(us)", min); exporter.write(getName(), "MaxLatency(us)", max);