allow activities to set hdr-digits

This commit is contained in:
Jonathan Shook 2020-05-21 08:46:19 -05:00
parent fa846a3c94
commit d43941d10d
4 changed files with 49 additions and 14 deletions

View File

@ -244,7 +244,7 @@ public class SimpleActivity implements Activity {
* by the provided ratios. Also, modify the ActivityDef with reasonable defaults when requested.
* @param seq - The {@link OpSequence} to derive the defaults from
*/
public void setDefaultsFromOpSequence(OpSequence seq) {
public void setDefaultsFromOpSequence(OpSequence<?> seq) {
Optional<String> strideOpt = getParams().getOptionalString("stride");
if (strideOpt.isEmpty()) {
String stride = String.valueOf(seq.getSequence().length);

View File

@ -18,7 +18,6 @@
package io.nosqlbench.engine.api.metrics;
import com.codahale.metrics.*;
import io.nosqlbench.engine.api.activityapi.core.Activity;
import io.nosqlbench.engine.api.activityapi.core.MetricRegistryService;
import io.nosqlbench.engine.api.activityimpl.ActivityDef;
import io.nosqlbench.engine.api.util.Unit;
@ -37,6 +36,11 @@ import java.util.regex.Pattern;
public class ActivityMetrics {
private final static Logger logger = LoggerFactory.getLogger(ActivityMetrics.class);
public static final String HDRDIGITS_PARAM = "hdr-digits";
public static final int DEFAULT_HDRDIGITS= 4;
private static int _HDRDIGITS = DEFAULT_HDRDIGITS;
private static MetricRegistry registry;
public static MetricFilter METRIC_FILTER = (name, metric) -> {
@ -44,14 +48,13 @@ public class ActivityMetrics {
};
private static List<MetricsCloseable> metricsCloseables = new ArrayList<>();
private static int significantDigits = 4;
public static int getSignificantDigits() {
return significantDigits;
public static int getHdrDigits() {
return _HDRDIGITS;
}
public static void setHdrDigits(int hdrDigits) {
ActivityMetrics.significantDigits = hdrDigits;
ActivityMetrics._HDRDIGITS = hdrDigits;
}
private ActivityMetrics() {
@ -99,6 +102,10 @@ public class ActivityMetrics {
}
/**
* <p>Create a timer associated with an activity.</p>
*
* <p>If the provide ActivityDef contains a parameter "hdr-digits", then it will be used to set the number of
* significant digits on the histogram's precision.</p>
*
* <p>This method ensures that if multiple threads attempt to create the same-named metric on a given activity,
* that only one of them succeeds.</p>
*
@ -109,15 +116,25 @@ public class ActivityMetrics {
public static Timer timer(ActivityDef activityDef, String name) {
String fullMetricName = activityDef.getAlias() + "." + name;
Timer registeredTimer = (Timer) register(activityDef, name, () ->
new NicerTimer(fullMetricName, new DeltaHdrHistogramReservoir(fullMetricName, significantDigits)));
new NicerTimer(fullMetricName,
new DeltaHdrHistogramReservoir(
fullMetricName,
activityDef.getParams().getOptionalInteger(HDRDIGITS_PARAM).orElse(_HDRDIGITS)
)
));
return registeredTimer;
}
/**
* <p>Create a histogram associated with an activity.</p>
* <p>Create an HDR histogram associated with an activity.</p>
*
* <p>If the provide ActivityDef contains a parameter "hdr-digits", then it will be used to set the number of
* significant digits on the histogram's precision.</p>
*
* <p>This method ensures that if multiple threads attempt to create the same-named metric on a given activity,
* that only one of them succeeds.</p>
*
*
* @param activityDef an associated activity def
* @param name a simple, descriptive name for the histogram
* @return the histogram, perhaps a different one if it has already been registered
@ -125,7 +142,13 @@ public class ActivityMetrics {
public static Histogram histogram(ActivityDef activityDef, String name) {
String fullMetricName = activityDef.getAlias() + "." + name;
return (Histogram) register(activityDef, name, () ->
new NicerHistogram(fullMetricName, new DeltaHdrHistogramReservoir(fullMetricName, significantDigits)));
new NicerHistogram(
fullMetricName,
new DeltaHdrHistogramReservoir(
fullMetricName,
activityDef.getParams().getOptionalInteger(HDRDIGITS_PARAM).orElse(_HDRDIGITS)
)
));
}
/**

View File

@ -360,9 +360,21 @@ In detail, the rendering appears as `0.0(A), 0.0(B), 0.0(C), 0.25(A),
0.5(A), 0.5(B), 0.75(A)`, which yields `A B C A A B A` as the op
sequence.
This sequencer is most useful when you want a stable ordering of
operation from a rich mix of statement types, where each operations is
spaced as evenly as possible over time, and where it is not important to
control the cycle-by-cycle sequencing of statements.
This sequencer is most useful when you want a stable ordering of operation from a rich mix of statement types, where
each operations is spaced as evenly as possible over time, and where it is not important to control the cycle-by-cycle
sequencing of statements.
## hdr-digits
- `hdr-digits=3`
- _default_: `4`
- _required_: no
- _dynamic_: no
This parameter determines the number of significant digits used in all HDR histograms for metrics collected from this
activity. The default of 4 allows 4 significant digits, which means *up to* 10000 distinct histogram buckets per named
metric, per histogram interval. This does not mean that there _will be_ 10000 distinct buckets, but it means there could
be if there is significant volume and variety in the measurements.
If you are running a scenario that creates many activities, then you can set `hdr-digits=1` on some of them to save
client resources.

View File

@ -160,7 +160,7 @@ you can do so this way:
The default is 4 digits, which creates 10000 equisized histogram buckets for every named metric in every reporting
interval. For longer running test or for test which do not require this level of precision in metrics, you can set this
down to 3 or 2.
down to 3 or 2. Note that this only sets the global default. Each activity can also override this value.
Enlist engineblock to stand up your metrics infrastructure using a local docker runtime: