Apache Lucene open-source search software
SOLR-10226 JMX metric avgTimePerRequest broken.
Andrzej Bialecki2d51a42d3cae
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txtindex db721da4e9e..5b0eb03f93e 100644--- a/solr/CHANGES.txt+++ b/solr/CHANGES.txt@@ -96,6 +96,10 @@ Detailed Change ListUpgrade Notes----------------------+* SOLR-10226: JMX metric "avgTimePerRequest" (and the corresponding metric in the metrics API for+ each handler) used to be a simple non-decaying average based on total cumulative time and the+ number of requests. New Codahale Metrics implementation applies exponential decay to this value,+ which heavily biases the average towards the last 5 minutes. (ab)New Features----------------------@@ -212,6 +216,8 @@ Bug Fixes* SOLR-10088: Installer script does not put zoo.cfg in SOLR_HOME (janhoy)+* SOLR-10226: add back "totalTime" metric to all handlers. See also the back-compat note. (ab)+Optimizations----------------------diff --git a/solr/core/src/java/org/apache/solr/handler/RequestHandlerBase.java b/solr/core/src/java/org/apache/solr/handler/RequestHandlerBase.javaindex 3c6f5fa37bd..1958e11f587 100644--- a/solr/core/src/java/org/apache/solr/handler/RequestHandlerBase.java+++ b/solr/core/src/java/org/apache/solr/handler/RequestHandlerBase.java@@ -66,6 +66,7 @@ public abstract class RequestHandlerBase implements SolrRequestHandler, SolrInfoprivate Meter numTimeouts = new Meter();private Counter requests = new Counter();private Timer requestTimes = new Timer();+ private Counter totalTime = new Counter();private final long handlerStart;@@ -143,6 +144,7 @@ public abstract class RequestHandlerBase implements SolrRequestHandler, SolrInfonumTimeouts = manager.meter(registryName, "timeouts", getCategory().toString(), scope);requests = manager.counter(registryName, "requests", getCategory().toString(), scope);requestTimes = manager.timer(registryName, "requestTimes", getCategory().toString(), scope);+ totalTime = manager.counter(registryName, "totalTime", getCategory().toString(), scope);}public static SolrParams getSolrParamsFromNamedList(NamedList args, String key) {@@ -209,7 +211,8 @@ public abstract class RequestHandlerBase implements SolrRequestHandler, SolrInfo}}} finally {- timer.stop();+ long elapsed = timer.stop();+ totalTime.inc(elapsed);}}@@ -292,6 +295,8 @@ public abstract class RequestHandlerBase implements SolrRequestHandler, SolrInfolst.add("serverErrors", numServerErrors.getCount());lst.add("clientErrors", numClientErrors.getCount());lst.add("timeouts", numTimeouts.getCount());+ // convert totalTime to ms+ lst.add("totalTime", MetricUtils.nsToMs(totalTime.getCount()));MetricUtils.addMetrics(lst, requestTimes);return lst;}diff --git a/solr/core/src/java/org/apache/solr/util/stats/MetricUtils.java b/solr/core/src/java/org/apache/solr/util/stats/MetricUtils.javaindex 0d386ae74ef..80f035bda7d 100644--- a/solr/core/src/java/org/apache/solr/util/stats/MetricUtils.java+++ b/solr/core/src/java/org/apache/solr/util/stats/MetricUtils.java@@ -63,7 +63,7 @@ public class MetricUtils {* @param ns the amount of time in nanoseconds* @return the amount of time in milliseconds*/- static double nsToMs(double ns) {+ public static double nsToMs(double ns) {return ns / TimeUnit.MILLISECONDS.toNanos(1);}