Skip to content
Snippets Groups Projects
Commit b28a654b authored by kruthar's avatar kruthar
Browse files

[core] added configurable percentile values

In OneMeasurementHdrHistogram, now reading hdrhistogram.percentiles
from workload configuration. This property is a comma delimited string
of Integers to use as percentile values.

This implements #437
parent 57b22910
No related branches found
No related tags found
No related merge requests found
......@@ -23,8 +23,7 @@ import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintStream;
import java.text.DecimalFormat;
import java.util.Map;
import java.util.Properties;
import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;
import org.HdrHistogram.Histogram;
......@@ -49,8 +48,21 @@ public class OneMeasurementHdrHistogram extends OneMeasurement {
final Recorder histogram;
Histogram totalHistogram;
/**
* The name of the property for deciding what percentile values to output.
*/
public static final String PERCENTILES_PROPERTY = "hdrhistogram.percentiles";
/**
* The default value for the hdrhistogram.percentiles property.
*/
public static final String PERCENTILES_PROPERTY_DEFAULT = "95,99";
List<Integer> percentiles;
public OneMeasurementHdrHistogram(String name, Properties props) {
super(name);
percentiles = getPercentileValues(props.getProperty(PERCENTILES_PROPERTY, PERCENTILES_PROPERTY_DEFAULT));
boolean shouldLog = Boolean.parseBoolean(props.getProperty("hdrhistogram.fileoutput", "false"));
if (!shouldLog) {
log = null;
......@@ -101,8 +113,10 @@ public class OneMeasurementHdrHistogram extends OneMeasurement {
exporter.write(getName(), "AverageLatency(us)", totalHistogram.getMean());
exporter.write(getName(), "MinLatency(us)", totalHistogram.getMinValue());
exporter.write(getName(), "MaxLatency(us)", totalHistogram.getMaxValue());
exporter.write(getName(), "95thPercentileLatency(us)", totalHistogram.getValueAtPercentile(90));
exporter.write(getName(), "99thPercentileLatency(us)", totalHistogram.getValueAtPercentile(99));
for (Integer percentile: percentiles) {
exporter.write(getName(), percentile + "thPercentileLatency(us)", totalHistogram.getValueAtPercentile(percentile));
}
exportReturnCodes(exporter);
}
......@@ -142,4 +156,28 @@ public class OneMeasurementHdrHistogram extends OneMeasurement {
return intervalHistogram;
}
/**
* Helper method to parse the given percentile value string
*
* @param percentileString - comma delimited string of Integer values
* @return An Integer List of percentile values
*/
private List<Integer> getPercentileValues(String percentileString) {
List<Integer> percentileValues = new ArrayList<Integer>();
try {
for (String rawPercentile: percentileString.split(",")) {
percentileValues.add(Integer.parseInt(rawPercentile));
}
} catch(Exception e) {
// If the given hdrhistogram.percentiles value is unreadable for whatever reason,
// then calculate and return the default set.
System.err.println("[WARN] Couldn't read " + PERCENTILES_PROPERTY + " value: '" + percentileString +
"', the default of '" + PERCENTILES_PROPERTY_DEFAULT + "' will be used.");
return getPercentileValues(PERCENTILES_PROPERTY_DEFAULT);
}
return percentileValues;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment