You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cassandra.apache.org by jb...@apache.org on 2010/01/29 16:46:58 UTC

svn commit: r904524 - in /incubator/cassandra/trunk/src/java/org/apache/cassandra: db/ service/ tools/ utils/

Author: jbellis
Date: Fri Jan 29 15:46:56 2010
New Revision: 904524

URL: http://svn.apache.org/viewvc?rev=904524&view=rev
Log:
replace remaining uses of TimedStatsDeque with LatencyTracker
patch by jbellis; reviewed by Brandon Williams for CASSANDRA-702

Added:
    incubator/cassandra/trunk/src/java/org/apache/cassandra/utils/LatencyTracker.java   (with props)
Removed:
    incubator/cassandra/trunk/src/java/org/apache/cassandra/utils/TimedStatsDeque.java
Modified:
    incubator/cassandra/trunk/src/java/org/apache/cassandra/db/ColumnFamilyStore.java
    incubator/cassandra/trunk/src/java/org/apache/cassandra/db/ColumnFamilyStoreMBean.java
    incubator/cassandra/trunk/src/java/org/apache/cassandra/service/StorageProxy.java
    incubator/cassandra/trunk/src/java/org/apache/cassandra/service/StorageProxyMBean.java
    incubator/cassandra/trunk/src/java/org/apache/cassandra/tools/NodeCmd.java
    incubator/cassandra/trunk/src/java/org/apache/cassandra/tools/NodeProbe.java

Modified: incubator/cassandra/trunk/src/java/org/apache/cassandra/db/ColumnFamilyStore.java
URL: http://svn.apache.org/viewvc/incubator/cassandra/trunk/src/java/org/apache/cassandra/db/ColumnFamilyStore.java?rev=904524&r1=904523&r2=904524&view=diff
==============================================================================
--- incubator/cassandra/trunk/src/java/org/apache/cassandra/db/ColumnFamilyStore.java (original)
+++ incubator/cassandra/trunk/src/java/org/apache/cassandra/db/ColumnFamilyStore.java Fri Jan 29 15:46:56 2010
@@ -53,7 +53,6 @@
 import org.apache.cassandra.db.filter.*;
 import org.apache.cassandra.db.marshal.AbstractType;
 
-import org.apache.commons.lang.ArrayUtils;
 import org.apache.commons.collections.IteratorUtils;
 
 import org.cliffc.high_scale_lib.NonBlockingHashMap;
@@ -118,8 +117,8 @@
     /* SSTables on disk for this column family */
     private SSTableTracker ssTables_;
 
-    private TimedStatsDeque readStats_ = new TimedStatsDeque(60000);
-    private TimedStatsDeque writeStats_ = new TimedStatsDeque(60000);
+    private LatencyTracker readStats_ = new LatencyTracker();
+    private LatencyTracker writeStats_ = new LatencyTracker();
     
     ColumnFamilyStore(String table, String columnFamilyName, boolean isSuper, int indexValue) throws IOException
     {
@@ -739,34 +738,40 @@
         return ssTables_.getSSTables();
     }
 
-    public int getReadCount()
+    public long getReadCount()
     {
-        return readStats_.size();
+        return readStats_.getOpCount();
     }
 
-    public double getReadLatency()
+    public double getRecentReadLatency()
     {
-        return readStats_.mean();
+        return readStats_.getRecentLatency();
     }
 
-    // TODO this actually isn't a good meature of pending tasks
+    public long getTotalReadLatency()
+    {
+        return readStats_.getTotalLatency();
+    }
+
+// TODO this actually isn't a good meature of pending tasks
     public int getPendingTasks()
     {
         return Table.flusherLock.getQueueLength();
     }
 
-    /**
-     * @return the number of write operations on this column family in the last minute
-     */
-    public int getWriteCount() {
-        return writeStats_.size();
+    public long getWriteCount()
+    {
+        return writeStats_.getOpCount();
     }
 
-    /**
-     * @return average latency per write operation in the last minute
-     */
-    public double getWriteLatency() {
-        return writeStats_.mean();
+    public long getTotalWriteLatency()
+    {
+        return writeStats_.getTotalLatency();
+    }
+
+    public double getRecentWriteLatency()
+    {
+        return writeStats_.getRecentLatency();
     }
 
     public ColumnFamily getColumnFamily(String key, QueryPath path, byte[] start, byte[] finish, boolean reversed, int limit) throws IOException

Modified: incubator/cassandra/trunk/src/java/org/apache/cassandra/db/ColumnFamilyStoreMBean.java
URL: http://svn.apache.org/viewvc/incubator/cassandra/trunk/src/java/org/apache/cassandra/db/ColumnFamilyStoreMBean.java?rev=904524&r1=904523&r2=904524&view=diff
==============================================================================
--- incubator/cassandra/trunk/src/java/org/apache/cassandra/db/ColumnFamilyStoreMBean.java (original)
+++ incubator/cassandra/trunk/src/java/org/apache/cassandra/db/ColumnFamilyStoreMBean.java Fri Jan 29 15:46:56 2010
@@ -60,26 +60,36 @@
     public Object forceFlush() throws IOException;
 
     /**
-     * @return the number of read operations on this column family in the last minute
+     * @return the number of read operations on this column family
      */
-    public int getReadCount();
+    public long getReadCount();
 
     /**
-     * @return average latency per read operation in the last minute
+     * @return total read latency (divide by getReadCount() for average)
      */
-    public double getReadLatency();
-    
+    public long getTotalReadLatency();
+
     /**
-     * @return the number of write operations on this column family in the last minute
+     * @return average latency per read operation since the last call
      */
-    public int getWriteCount();
-    
+    public double getRecentReadLatency();
+
     /**
-     * @return average latency per write operation in the last minute
+     * @return the number of write operations on this column family
      */
-    public double getWriteLatency();
+    public long getWriteCount();
     
     /**
+     * @return total write latency (divide by getReadCount() for average)
+     */
+    public long getTotalWriteLatency();
+
+    /**
+     * @return average latency per write operation since the last call
+     */
+    public double getRecentWriteLatency();
+
+    /**
      * @return the estimated number of tasks pending for this column family
      */
     public int getPendingTasks();

Modified: incubator/cassandra/trunk/src/java/org/apache/cassandra/service/StorageProxy.java
URL: http://svn.apache.org/viewvc/incubator/cassandra/trunk/src/java/org/apache/cassandra/service/StorageProxy.java?rev=904524&r1=904523&r2=904524&view=diff
==============================================================================
--- incubator/cassandra/trunk/src/java/org/apache/cassandra/service/StorageProxy.java (original)
+++ incubator/cassandra/trunk/src/java/org/apache/cassandra/service/StorageProxy.java Fri Jan 29 15:46:56 2010
@@ -36,7 +36,7 @@
 import org.apache.cassandra.net.IAsyncResult;
 import org.apache.cassandra.net.Message;
 import org.apache.cassandra.net.MessagingService;
-import org.apache.cassandra.utils.TimedStatsDeque;
+import org.apache.cassandra.utils.LatencyTracker;
 import org.apache.cassandra.utils.FBUtilities;
 import org.apache.cassandra.utils.Pair;
 import org.apache.cassandra.utils.WrappedRunnable;
@@ -58,9 +58,9 @@
     private static final Logger logger = Logger.getLogger(StorageProxy.class);
 
     // mbean stuff
-    private static final TimedStatsDeque readStats = new TimedStatsDeque(60000);
-    private static final TimedStatsDeque rangeStats = new TimedStatsDeque(60000);
-    private static final TimedStatsDeque writeStats = new TimedStatsDeque(60000);
+    private static final LatencyTracker readStats = new LatencyTracker();
+    private static final LatencyTracker rangeStats = new LatencyTracker();
+    private static final LatencyTracker writeStats = new LatencyTracker();
 
     private StorageProxy() {}
     static
@@ -608,34 +608,49 @@
         return results;
     }
 
-    public double getReadLatency()
+    public long getReadOperations()
     {
-        return readStats.mean();
+        return readStats.getOpCount();
     }
 
-    public double getRangeLatency()
+    public long getTotalReadLatency()
     {
-        return rangeStats.mean();
+        return readStats.getTotalLatency();
     }
 
-    public double getWriteLatency()
+    public double getRecentReadLatency()
     {
-        return writeStats.mean();
+        return readStats.getRecentLatency();
     }
 
-    public int getReadOperations()
+    public long getRangeOperations()
     {
-        return readStats.size();
+        return rangeStats.getOpCount();
     }
 
-    public int getRangeOperations()
+    public long getTotalRangeLatency()
     {
-        return rangeStats.size();
+        return rangeStats.getTotalLatency();
     }
 
-    public int getWriteOperations()
+    public double getRecentRangeLatency()
     {
-        return writeStats.size();
+        return rangeStats.getRecentLatency();
+    }
+
+    public long getWriteOperations()
+    {
+        return writeStats.getOpCount();
+    }
+
+    public long getTotalWriteLatency()
+    {
+        return writeStats.getTotalLatency();
+    }
+
+    public double getRecentWriteLatency()
+    {
+        return writeStats.getRecentLatency();
     }
 
     static class weakReadLocalCallable implements Callable<Object>

Modified: incubator/cassandra/trunk/src/java/org/apache/cassandra/service/StorageProxyMBean.java
URL: http://svn.apache.org/viewvc/incubator/cassandra/trunk/src/java/org/apache/cassandra/service/StorageProxyMBean.java?rev=904524&r1=904523&r2=904524&view=diff
==============================================================================
--- incubator/cassandra/trunk/src/java/org/apache/cassandra/service/StorageProxyMBean.java (original)
+++ incubator/cassandra/trunk/src/java/org/apache/cassandra/service/StorageProxyMBean.java Fri Jan 29 15:46:56 2010
@@ -20,10 +20,15 @@
 
 public interface StorageProxyMBean
 {
-    public double getReadLatency();
-    public int getReadOperations();
-    public double getRangeLatency();
-    public int getRangeOperations();
-    public double getWriteLatency();
-    public int getWriteOperations();
+    public long getReadOperations();
+    public long getTotalReadLatency();
+    public double getRecentReadLatency();
+
+    public long getRangeOperations();
+    public long getTotalRangeLatency();
+    public double getRecentRangeLatency();
+
+    public long getWriteOperations();
+    public long getTotalWriteLatency();
+    public double getRecentWriteLatency();
 }

Modified: incubator/cassandra/trunk/src/java/org/apache/cassandra/tools/NodeCmd.java
URL: http://svn.apache.org/viewvc/incubator/cassandra/trunk/src/java/org/apache/cassandra/tools/NodeCmd.java?rev=904524&r1=904523&r2=904524&view=diff
==============================================================================
--- incubator/cassandra/trunk/src/java/org/apache/cassandra/tools/NodeCmd.java (original)
+++ incubator/cassandra/trunk/src/java/org/apache/cassandra/tools/NodeCmd.java Fri Jan 29 15:46:56 2010
@@ -212,18 +212,18 @@
             outs.println("Keyspace: " + tableName);
             for (ColumnFamilyStoreMBean cfstore : columnFamilies)
             {
-                int writeCount = cfstore.getWriteCount();
-                int readCount = cfstore.getReadCount();
+                long writeCount = cfstore.getWriteCount();
+                long readCount = cfstore.getReadCount();
 
                 if (readCount > 0)
                 {
                     tableReadCount += readCount;
-                    tableTotalReadTime += cfstore.getReadLatency() * readCount;
+                    tableTotalReadTime += cfstore.getTotalReadLatency();
                 }
                 if (writeCount > 0)
                 {
                     tableWriteCount += writeCount;
-                    tableTotalWriteTime += cfstore.getWriteLatency() * writeCount;
+                    tableTotalWriteTime += cfstore.getTotalWriteLatency();
                 }
                 tablePendingTasks += cfstore.getPendingTasks();
             }
@@ -232,9 +232,9 @@
             double tableWriteLatency = tableWriteCount > 0 ? tableTotalWriteTime / tableWriteCount : Double.NaN;
 
             outs.println("\tRead Count: " + tableReadCount);
-            outs.println("\tRead Latency: " + String.format("%01.3f", tableReadLatency) + " ms.");
+            outs.println("\tRead Latency: " + String.format("%s", tableReadLatency) + " ms.");
             outs.println("\tWrite Count: " + tableWriteCount);
-            outs.println("\tWrite Latency: " + String.format("%01.3f", tableWriteLatency) + " ms.");
+            outs.println("\tWrite Latency: " + String.format("%s", tableWriteLatency) + " ms.");
             outs.println("\tPending Tasks: " + tablePendingTasks);
 
             // print out column family statistics for this table
@@ -248,9 +248,9 @@
                 outs.println("\t\tMemtable Data Size: " + cfstore.getMemtableDataSize());
                 outs.println("\t\tMemtable Switch Count: " + cfstore.getMemtableSwitchCount());
                 outs.println("\t\tRead Count: " + cfstore.getReadCount());
-                outs.println("\t\tRead Latency: " + String.format("%01.3f", cfstore.getReadLatency()) + " ms.");
+                outs.println("\t\tRead Latency: " + String.format("%01.3f", cfstore.getRecentReadLatency()) + " ms.");
                 outs.println("\t\tWrite Count: " + cfstore.getWriteCount());
-                outs.println("\t\tWrite Latency: " + String.format("%01.3f", cfstore.getWriteLatency()) + " ms.");
+                outs.println("\t\tWrite Latency: " + String.format("%01.3f", cfstore.getRecentWriteLatency()) + " ms.");
                 outs.println("\t\tPending Tasks: " + cfstore.getPendingTasks());
 
                 JMXAggregatingCacheMBean keyCacheMBean = probe.getKeyCacheMBean(tableName, cfstore.getColumnFamilyName());

Modified: incubator/cassandra/trunk/src/java/org/apache/cassandra/tools/NodeProbe.java
URL: http://svn.apache.org/viewvc/incubator/cassandra/trunk/src/java/org/apache/cassandra/tools/NodeProbe.java?rev=904524&r1=904523&r2=904524&view=diff
==============================================================================
--- incubator/cassandra/trunk/src/java/org/apache/cassandra/tools/NodeProbe.java (original)
+++ incubator/cassandra/trunk/src/java/org/apache/cassandra/tools/NodeProbe.java Fri Jan 29 15:46:56 2010
@@ -37,7 +37,6 @@
 import javax.management.remote.JMXConnectorFactory;
 import javax.management.remote.JMXServiceURL;
 
-import org.apache.cassandra.cache.JMXAggregatingCache;
 import org.apache.cassandra.cache.JMXAggregatingCacheMBean;
 import org.apache.cassandra.cache.JMXInstrumentedCacheMBean;
 import org.apache.cassandra.concurrent.IExecutorMBean;

Added: incubator/cassandra/trunk/src/java/org/apache/cassandra/utils/LatencyTracker.java
URL: http://svn.apache.org/viewvc/incubator/cassandra/trunk/src/java/org/apache/cassandra/utils/LatencyTracker.java?rev=904524&view=auto
==============================================================================
--- incubator/cassandra/trunk/src/java/org/apache/cassandra/utils/LatencyTracker.java (added)
+++ incubator/cassandra/trunk/src/java/org/apache/cassandra/utils/LatencyTracker.java Fri Jan 29 15:46:56 2010
@@ -0,0 +1,42 @@
+package org.apache.cassandra.utils;
+
+import java.util.concurrent.atomic.AtomicLong;
+
+public class LatencyTracker
+{
+    private final AtomicLong opCount = new AtomicLong(0);
+    private final AtomicLong totalLatency = new AtomicLong(0);
+    private long lastLatency = 0;
+    private long lastOpCount = 0;
+
+    public void add(long n)
+    {
+        opCount.incrementAndGet();
+        totalLatency.addAndGet(n);
+    }
+
+    public long getOpCount()
+    {
+        return opCount.get();
+    }
+
+    public long getTotalLatency()
+    {
+        return totalLatency.get();
+    }
+
+    public double getRecentLatency()
+    {
+        long ops = opCount.get();
+        long n = totalLatency.get();
+        try
+        {
+            return ((double)n - lastLatency) / (ops - lastOpCount);
+        }
+        finally
+        {
+            lastLatency = n;
+            lastOpCount = ops;
+        }
+    }
+}

Propchange: incubator/cassandra/trunk/src/java/org/apache/cassandra/utils/LatencyTracker.java
------------------------------------------------------------------------------
    svn:eol-style = native