You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cassandra.apache.org by yc...@apache.org on 2021/11/19 17:39:36 UTC

[cassandra] branch trunk updated: Increase the buckets count for timer histogram

This is an automated email from the ASF dual-hosted git repository.

ycai pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/cassandra.git


The following commit(s) were added to refs/heads/trunk by this push:
     new 4aab2c7  Increase the buckets count for timer histogram
4aab2c7 is described below

commit 4aab2c79b9539e8d8cfe90e4dd700b8da2f9e8a0
Author: Yifan Cai <yc...@apache.org>
AuthorDate: Mon Nov 15 16:12:08 2021 -0800

    Increase the buckets count for timer histogram
    
    patch by Yifan Cai; reviewed by Caleb Rackliffe for CASSANDRA-17155
---
 .../apache/cassandra/metrics/CassandraMetricsRegistry.java    |  7 +++----
 .../metrics/DecayingEstimatedHistogramReservoir.java          |  1 +
 .../cassandra/metrics/CassandraMetricsRegistryTest.java       | 11 +++++++++--
 3 files changed, 13 insertions(+), 6 deletions(-)

diff --git a/src/java/org/apache/cassandra/metrics/CassandraMetricsRegistry.java b/src/java/org/apache/cassandra/metrics/CassandraMetricsRegistry.java
index 90bbe15..14a2807 100644
--- a/src/java/org/apache/cassandra/metrics/CassandraMetricsRegistry.java
+++ b/src/java/org/apache/cassandra/metrics/CassandraMetricsRegistry.java
@@ -31,7 +31,6 @@ import javax.management.ObjectName;
 import com.google.common.annotations.VisibleForTesting;
 
 import com.codahale.metrics.*;
-import org.apache.cassandra.utils.EstimatedHistogram;
 import org.apache.cassandra.utils.MBeanWrapper;
 
 /**
@@ -109,7 +108,7 @@ public class CassandraMetricsRegistry extends MetricRegistry
 
     public Timer timer(MetricName name, TimeUnit durationUnit)
     {
-        Timer timer = register(name, new Timer(CassandraMetricsRegistry.createReservoir(TimeUnit.MICROSECONDS)));
+        Timer timer = register(name, new Timer(CassandraMetricsRegistry.createReservoir(durationUnit)));
         registerMBean(timer, name.getMBeanName());
 
         return timer;
@@ -128,9 +127,9 @@ public class CassandraMetricsRegistry extends MetricRegistry
         if (durationUnit != TimeUnit.NANOSECONDS)
         {
             Reservoir underlying = new DecayingEstimatedHistogramReservoir(DecayingEstimatedHistogramReservoir.DEFAULT_ZERO_CONSIDERATION,
-                                                                           EstimatedHistogram.DEFAULT_BUCKET_COUNT,
+                                                                           DecayingEstimatedHistogramReservoir.LOW_BUCKET_COUNT,
                                                                            DecayingEstimatedHistogramReservoir.DEFAULT_STRIPE_COUNT);
-            // less buckets (90) should suffice if timer is not based on nanos
+            // fewer buckets should suffice if timer is not based on nanos
             reservoir = new ScalingReservoir(underlying,
                                              // timer update values in nanos.
                                              v -> durationUnit.convert(v, TimeUnit.NANOSECONDS));
diff --git a/src/java/org/apache/cassandra/metrics/DecayingEstimatedHistogramReservoir.java b/src/java/org/apache/cassandra/metrics/DecayingEstimatedHistogramReservoir.java
index 6dd1687..6af2389 100644
--- a/src/java/org/apache/cassandra/metrics/DecayingEstimatedHistogramReservoir.java
+++ b/src/java/org/apache/cassandra/metrics/DecayingEstimatedHistogramReservoir.java
@@ -83,6 +83,7 @@ public class DecayingEstimatedHistogramReservoir implements Reservoir
      * The default number of decayingBuckets. Use this bucket count to reduce memory allocation for bucket offsets.
      */
     public static final int DEFAULT_BUCKET_COUNT = 164;
+    public static final int LOW_BUCKET_COUNT = 127;
     public static final int DEFAULT_STRIPE_COUNT = Integer.parseInt(System.getProperty("cassandra.dehr_stripe_count", "2"));
     public static final int MAX_BUCKET_COUNT = 237;
     public static final boolean DEFAULT_ZERO_CONSIDERATION = false;
diff --git a/test/unit/org/apache/cassandra/metrics/CassandraMetricsRegistryTest.java b/test/unit/org/apache/cassandra/metrics/CassandraMetricsRegistryTest.java
index 0dd7eab..02e4228 100644
--- a/test/unit/org/apache/cassandra/metrics/CassandraMetricsRegistryTest.java
+++ b/test/unit/org/apache/cassandra/metrics/CassandraMetricsRegistryTest.java
@@ -118,7 +118,7 @@ public class CassandraMetricsRegistryTest
     @Test
     public void testTimer()
     {
-        long[] offsets = new EstimatedHistogram().getBucketOffsets();
+        long[] offsets = EstimatedHistogram.newOffsets(DecayingEstimatedHistogramReservoir.LOW_BUCKET_COUNT, false);
         Timer timer = new Timer(CassandraMetricsRegistry.createReservoir(TimeUnit.MICROSECONDS));
         timer.update(42, TimeUnit.NANOSECONDS);
         timer.update(100, TimeUnit.NANOSECONDS);
@@ -126,8 +126,12 @@ public class CassandraMetricsRegistryTest
         timer.update(100, TimeUnit.MICROSECONDS);
         timer.update(42, TimeUnit.MILLISECONDS);
         timer.update(100, TimeUnit.MILLISECONDS);
+        timer.update(100, TimeUnit.SECONDS);
+        timer.update(100, TimeUnit.MINUTES);
+        int maxSeconds = 21356;
+        timer.update(maxSeconds, TimeUnit.SECONDS);
         long[] counts = timer.getSnapshot().getValues();
-        int expectedBucketsWithValues = 5;
+        int expectedBucketsWithValues = 8;
         int bucketsWithValues = 0;
         for (int i = 0; i < counts.length; i++)
         {
@@ -141,6 +145,9 @@ public class CassandraMetricsRegistryTest
                 || inRange(offsets[i], TimeUnit.MICROSECONDS.toMicros(100), 1.2)
                 || inRange(offsets[i], TimeUnit.MILLISECONDS.toMicros(42), 1.2)
                 || inRange(offsets[i], TimeUnit.MILLISECONDS.toMicros(100), 1.2)
+                || inRange(offsets[i], TimeUnit.SECONDS.toMicros(100), 1.2)
+                || inRange(offsets[i], TimeUnit.MINUTES.toMicros(100), 1.2)
+                || inRange(offsets[i], TimeUnit.SECONDS.toMicros(maxSeconds), 1.2)
                 );
             }
         }

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cassandra.apache.org
For additional commands, e-mail: commits-help@cassandra.apache.org