cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brandonwilli...@apache.org
Subject [09/14] git commit: Fix LatencyMetrics returning infinity.
Date Wed, 02 Apr 2014 22:00:45 GMT
Fix LatencyMetrics returning infinity.

Patch by Nick Bailey, reviewed by Lyuben Todorov for CASSANDRA-6920


Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo
Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/5e51aa4e
Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/5e51aa4e
Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/5e51aa4e

Branch: refs/heads/cassandra-2.1
Commit: 5e51aa4e6d1d868bb82a1aa2ffaed4613b24ffc1
Parents: 60079af
Author: Brandon Williams <brandonwilliams@apache.org>
Authored: Wed Apr 2 16:56:08 2014 -0500
Committer: Brandon Williams <brandonwilliams@apache.org>
Committed: Wed Apr 2 16:56:08 2014 -0500

----------------------------------------------------------------------
 .../apache/cassandra/metrics/LatencyMetrics.java    | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/5e51aa4e/src/java/org/apache/cassandra/metrics/LatencyMetrics.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/metrics/LatencyMetrics.java b/src/java/org/apache/cassandra/metrics/LatencyMetrics.java
index b53449c..ef1dee9 100644
--- a/src/java/org/apache/cassandra/metrics/LatencyMetrics.java
+++ b/src/java/org/apache/cassandra/metrics/LatencyMetrics.java
@@ -85,8 +85,11 @@ public class LatencyMetrics
     public void addNano(long nanos)
     {
         // convert to microseconds. 1 millionth
-        latency.update(nanos, TimeUnit.NANOSECONDS);
-        totalLatency.inc(nanos / 1000);
+        synchronized (this)
+        {
+            latency.update(nanos, TimeUnit.NANOSECONDS);
+            totalLatency.inc(nanos / 1000);
+        }
         totalLatencyHistogram.add(nanos / 1000);
         recentLatencyHistogram.add(nanos / 1000);
     }
@@ -100,8 +103,13 @@ public class LatencyMetrics
     @Deprecated
     public double getRecentLatency()
     {
-        long ops = latency.count();
-        long n = totalLatency.count();
+        long ops = 0;
+        long n = 0;
+        synchronized (this)
+        {
+            ops = latency.count();
+            n = totalLatency.count();
+        }
         try
         {
             return ((double) n - lastLatency) / (ops - lastOpCount);


Mime
View raw message