From d43941d10d4fc066e82dadf8615714625e587782 Mon Sep 17 00:00:00 2001 From: Jonathan Shook Date: Thu, 21 May 2020 08:46:19 -0500 Subject: [PATCH] allow activities to set hdr-digits --- .../api/activityimpl/SimpleActivity.java | 2 +- .../engine/api/metrics/ActivityMetrics.java | 39 +++++++++++++++---- .../reference/activity_parameters.md | 20 ++++++++-- .../docs-for-nb/reference/command_line.md | 2 +- 4 files changed, 49 insertions(+), 14 deletions(-) diff --git a/engine-api/src/main/java/io/nosqlbench/engine/api/activityimpl/SimpleActivity.java b/engine-api/src/main/java/io/nosqlbench/engine/api/activityimpl/SimpleActivity.java index 73d1e57c0..19a267c96 100644 --- a/engine-api/src/main/java/io/nosqlbench/engine/api/activityimpl/SimpleActivity.java +++ b/engine-api/src/main/java/io/nosqlbench/engine/api/activityimpl/SimpleActivity.java @@ -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 strideOpt = getParams().getOptionalString("stride"); if (strideOpt.isEmpty()) { String stride = String.valueOf(seq.getSequence().length); diff --git a/engine-api/src/main/java/io/nosqlbench/engine/api/metrics/ActivityMetrics.java b/engine-api/src/main/java/io/nosqlbench/engine/api/metrics/ActivityMetrics.java index f21e00fe0..e6a2db9c1 100644 --- a/engine-api/src/main/java/io/nosqlbench/engine/api/metrics/ActivityMetrics.java +++ b/engine-api/src/main/java/io/nosqlbench/engine/api/metrics/ActivityMetrics.java @@ -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 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 { } /** *

Create a timer associated with an activity.

+ * + *

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.

+ * *

This method ensures that if multiple threads attempt to create the same-named metric on a given activity, * that only one of them succeeds.

* @@ -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; } /** - *

Create a histogram associated with an activity.

+ *

Create an HDR histogram associated with an activity.

+ * + *

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.

+ * *

This method ensures that if multiple threads attempt to create the same-named metric on a given activity, * that only one of them succeeds.

* + * * @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) + ) + )); } /** diff --git a/engine-docs/src/main/resources/docs-for-nb/reference/activity_parameters.md b/engine-docs/src/main/resources/docs-for-nb/reference/activity_parameters.md index 473ec5002..a6f90f9de 100644 --- a/engine-docs/src/main/resources/docs-for-nb/reference/activity_parameters.md +++ b/engine-docs/src/main/resources/docs-for-nb/reference/activity_parameters.md @@ -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. diff --git a/engine-docs/src/main/resources/docs-for-nb/reference/command_line.md b/engine-docs/src/main/resources/docs-for-nb/reference/command_line.md index 1d19dd04b..1e82e542a 100644 --- a/engine-docs/src/main/resources/docs-for-nb/reference/command_line.md +++ b/engine-docs/src/main/resources/docs-for-nb/reference/command_line.md @@ -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: