Author: jbellis
Date: Thu Apr 29 01:45:38 2010
New Revision: 939163
URL: http://svn.apache.org/viewvc?rev=939163&view=rev
Log:
add latency histogram to CFSMbean. patch by Ryan King; reviewed by jbellis and
Stu Hood for CASSANDRA-1024
Added:
cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/utils/EstimatedHistogram.java
cassandra/branches/cassandra-0.6/test/unit/org/apache/cassandra/utils/EstimatedHistogramTest.java
Modified:
cassandra/branches/cassandra-0.6/CHANGES.txt
cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/db/ColumnFamilyStore.java
cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/db/ColumnFamilyStoreMBean.java
cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/utils/LatencyTracker.java
Modified: cassandra/branches/cassandra-0.6/CHANGES.txt
URL:
http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.6/CHANGES.txt?rev=939163&r1=939162&r2=939163&view=diff
==============================================================================
--- cassandra/branches/cassandra-0.6/CHANGES.txt (original)
+++ cassandra/branches/cassandra-0.6/CHANGES.txt Thu Apr 29 01:45:38 2010
@@ -2,6 +2,7 @@
* fix contrib/word_count build. (CASSANDRA-992)
* split CommitLogExecutorService into BatchCommitLogExecutorService and
PeriodicCommitLogExecutorService (CASSANDRA-1014)
+ * add latency histograms to CFSMBean (CASSANDRA-1024)
0.6.1
Modified:
cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/db/ColumnFamilyStore.java
URL:
http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/db/ColumnFamilyStore.java?rev=939163&r1=939162&r2=939163&view=diff
==============================================================================
---
cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/db/ColumnFamilyStore.java
(original)
+++
cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/db/ColumnFamilyStore.java
Thu Apr 29 01:45:38 2010
@@ -683,6 +683,16 @@ public class ColumnFamilyStore implement
return readStats_.getRecentLatencyMicros();
}
+ public long[] getLifetimeReadLatencyHistogramMicros()
+ {
+ return readStats_.getTotalLatencyHistogramMicros();
+ }
+
+ public long[] getRecentReadLatencyHistogramMicros()
+ {
+ return readStats_.getRecentLatencyHistogramMicros();
+ }
+
public long getTotalReadLatencyMicros()
{
return readStats_.getTotalLatencyMicros();
@@ -709,6 +719,16 @@ public class ColumnFamilyStore implement
return writeStats_.getRecentLatencyMicros();
}
+ public long[] getLifetimeWriteLatencyHistogramMicros()
+ {
+ return writeStats_.getTotalLatencyHistogramMicros();
+ }
+
+ public long[] getRecentWriteLatencyHistogramMicros()
+ {
+ return writeStats_.getRecentLatencyHistogramMicros();
+ }
+
public ColumnFamily getColumnFamily(String key, QueryPath path, byte[]
start, byte[] finish, boolean reversed, int limit) throws IOException
{
return getColumnFamily(new SliceQueryFilter(key, path, start, finish,
reversed, limit));
Modified:
cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/db/ColumnFamilyStoreMBean.java
URL:
http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/db/ColumnFamilyStoreMBean.java?rev=939163&r1=939162&r2=939163&view=diff
==============================================================================
---
cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/db/ColumnFamilyStoreMBean.java
(original)
+++
cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/db/ColumnFamilyStoreMBean.java
Thu Apr 29 01:45:38 2010
@@ -20,6 +20,7 @@ package org.apache.cassandra.db;
import java.util.concurrent.Future;
import java.io.IOException;
+import java.util.concurrent.atomic.AtomicLongArray;
/**
* The MBean interface for ColumnFamilyStore
@@ -70,6 +71,16 @@ public interface ColumnFamilyStoreMBean
public long getTotalReadLatencyMicros();
/**
+ * @return an array representing the latency histogram
+ */
+ public long[] getLifetimeReadLatencyHistogramMicros();
+
+ /**
+ * @return an array representing the latency histogram
+ */
+ public long[] getRecentReadLatencyHistogramMicros();
+
+ /**
* @return average latency per read operation since the last call
*/
public double getRecentReadLatencyMicros();
@@ -85,6 +96,16 @@ public interface ColumnFamilyStoreMBean
public long getTotalWriteLatencyMicros();
/**
+ * @return an array representing the latency histogram
+ */
+ public long[] getLifetimeWriteLatencyHistogramMicros();
+
+ /**
+ * @return an array representing the latency histogram
+ */
+ public long[] getRecentWriteLatencyHistogramMicros();
+
+ /**
* @return average latency per write operation since the last call
*/
public double getRecentWriteLatencyMicros();
Added:
cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/utils/EstimatedHistogram.java
URL:
http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/utils/EstimatedHistogram.java?rev=939163&view=auto
==============================================================================
---
cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/utils/EstimatedHistogram.java
(added)
+++
cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/utils/EstimatedHistogram.java
Thu Apr 29 01:45:38 2010
@@ -0,0 +1,77 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements. See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership. The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License. You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing,
+* software distributed under the License is distributed on an
+* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+* KIND, either express or implied. See the License for the
+* specific language governing permissions and limitations
+* under the License.
+*/
+package org.apache.cassandra.utils;
+
+import java.util.concurrent.atomic.AtomicLongArray;
+import java.util.Arrays;
+
+public class EstimatedHistogram
+{
+
+ /**
+ * This series starts at 1 and grows by 1.2 each time (rounding down and
removing duplicates). It goes from 1
+ * to around 30M, which will give us timing resolution from microseconds
to 30 seconds, with less precision
+ * as the numbers get larger.
+ */
+ private static final long[] bucketOffsets = {
+ 1, 2, 3, 4, 5, 6, 7, 8, 10, 12, 15, 18, 22, 26, 31, 38, 46, 55,
66, 79, 95, 114, 137, 164, 197, 237, 284, 341, 410, 492, 590,
+ 708, 850, 1020, 1224, 1469, 1763, 2116, 2539, 3047, 3657, 4388,
5266, 6319, 7583, 9100, 10920, 13104, 15725, 18870, 22644,
+ 27173, 32608, 39130, 46956, 56347, 67617, 81140, 97368, 116842,
140210, 168252, 201903, 242283, 290740, 348888, 418666,
+ 502400, 602880, 723456, 868147, 1041776, 1250132, 1500158,
1800190, 2160228, 2592274, 3110728, 3732874, 4479449, 5375339,
+ 6450407, 7740489, 9288586, 11146304, 13375565, 16050678, 19260813,
23112976, 27735572, 33282686
+ };
+
+ private static final int numBuckets = bucketOffsets.length + 1;
+
+ public AtomicLongArray buckets;
+
+ public EstimatedHistogram()
+ {
+ buckets = new AtomicLongArray(numBuckets);
+ }
+
+ public void add(long n)
+ {
+ int index = Arrays.binarySearch(bucketOffsets, n);
+ if (index < 0)
+ {
+ //inexact match, find closest bucket
+ index = -index - 1;
+ }
+ else
+ {
+ //exact match, so we want the next highest one
+ index += 1;
+ }
+ buckets.incrementAndGet(index);
+ }
+
+ public long[] get(Boolean reset)
+ {
+ long[] rv = new long[numBuckets];
+ for (int i = 0; i < numBuckets; i++)
+ rv[i] = buckets.get(i);
+
+ if (reset)
+ for (int i = 0; i < numBuckets; i++)
+ buckets.set(i, 0L);
+
+ return rv;
+ }
+}
Modified:
cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/utils/LatencyTracker.java
URL:
http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/utils/LatencyTracker.java?rev=939163&r1=939162&r2=939163&view=diff
==============================================================================
---
cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/utils/LatencyTracker.java
(original)
+++
cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/utils/LatencyTracker.java
Thu Apr 29 01:45:38 2010
@@ -22,6 +22,7 @@ package org.apache.cassandra.utils;
import java.util.concurrent.atomic.AtomicLong;
+import java.util.concurrent.atomic.AtomicLongArray;
public class LatencyTracker
{
@@ -29,6 +30,8 @@ public class LatencyTracker
private final AtomicLong totalLatency = new AtomicLong(0);
private long lastLatency = 0;
private long lastOpCount = 0;
+ private EstimatedHistogram totalHistogram = new EstimatedHistogram();
+ private EstimatedHistogram recentHistogram = new EstimatedHistogram();
/** takes nanoseconds **/
public void addNano(long nanos)
@@ -41,6 +44,8 @@ public class LatencyTracker
{
opCount.incrementAndGet();
totalLatency.addAndGet(micros);
+ totalHistogram.add(micros);
+ recentHistogram.add(micros);
}
public long getOpCount()
@@ -69,4 +74,14 @@ public class LatencyTracker
lastOpCount = ops;
}
}
+
+ public long[] getTotalLatencyHistogramMicros()
+ {
+ return totalHistogram.get(false);
+ }
+
+ public long[] getRecentLatencyHistogramMicros()
+ {
+ return recentHistogram.get(true);
+ }
}
Added:
cassandra/branches/cassandra-0.6/test/unit/org/apache/cassandra/utils/EstimatedHistogramTest.java
URL:
http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.6/test/unit/org/apache/cassandra/utils/EstimatedHistogramTest.java?rev=939163&view=auto
==============================================================================
---
cassandra/branches/cassandra-0.6/test/unit/org/apache/cassandra/utils/EstimatedHistogramTest.java
(added)
+++
cassandra/branches/cassandra-0.6/test/unit/org/apache/cassandra/utils/EstimatedHistogramTest.java
Thu Apr 29 01:45:38 2010
@@ -0,0 +1,50 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements. See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership. The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License. You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing,
+* software distributed under the License is distributed on an
+* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+* KIND, either express or implied. See the License for the
+* specific language governing permissions and limitations
+* under the License.
+*/
+package org.apache.cassandra.utils;
+
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+
+
+public class EstimatedHistogramTest
+{
+ @Test
+ public void testFindingCorrectBuckets()
+ {
+ EstimatedHistogram histogram = new EstimatedHistogram();
+
+ histogram.add(0L);
+ assertEquals(1, histogram.get(true)[0]);
+
+ histogram.add(33282687);
+ assertEquals(1, histogram.get(true)[histogram.buckets.length()-1]);
+
+ histogram.add(1);
+ assertEquals(1, histogram.get(true)[1]);
+
+ histogram.add(9);
+ assertEquals(1, histogram.get(true)[8]);
+
+ histogram.add(23);
+ histogram.add(24);
+ histogram.add(25);
+ assertEquals(3, histogram.get(true)[13]);
+ }
+}