cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From yu...@apache.org
Subject [01/10] git commit: Add KeyCacheHitRate metric to CF metrics
Date Fri, 09 Aug 2013 19:36:17 GMT
Updated Branches:
  refs/heads/cassandra-1.2 73b0ffba8 -> f5d632fa7
  refs/heads/cassandra-2.0 8c94eb2fe -> e08d3e2ad
  refs/heads/cassandra-2.0.0 2bcfab03c -> d62382bfe
  refs/heads/trunk 1b750ad4c -> 505898135


Add KeyCacheHitRate metric to CF metrics

patch by yukim; reviewed by jbellis for CASSANDRA-5868


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

Branch: refs/heads/cassandra-1.2
Commit: f5d632fa7ad94021bde4f4f6401a1bfcc2759c2a
Parents: 73b0ffb
Author: Yuki Morishita <yukim@apache.org>
Authored: Fri Aug 9 14:10:36 2013 -0500
Committer: Yuki Morishita <yukim@apache.org>
Committed: Fri Aug 9 14:10:36 2013 -0500

----------------------------------------------------------------------
 CHANGES.txt                                     |  1 +
 .../db/compaction/CompactionController.java     |  2 +-
 .../cassandra/io/sstable/SSTableReader.java     | 36 ++++++++++++++++++--
 .../cassandra/metrics/ColumnFamilyMetrics.java  | 21 ++++++++++++
 .../apache/cassandra/service/CacheService.java  |  4 +--
 5 files changed, 59 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/f5d632fa/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index 30ce976..f8c472c 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -13,6 +13,7 @@
  * Future-proof inter-major-version schema migrations (CASSANDRA-5845)
  * (Hadoop) add CqlPagingRecordReader support for ReversedType in Thrift table
    (CASSANDRA-5718)
+ * Add KeyCacheHitRate metric to CF metrics (CASSANDRA-5868)
 Merged from 1.1:
  * Correctly validate sparse composite cells in scrub (CASSANDRA-5855)
 

http://git-wip-us.apache.org/repos/asf/cassandra/blob/f5d632fa/src/java/org/apache/cassandra/db/compaction/CompactionController.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/db/compaction/CompactionController.java b/src/java/org/apache/cassandra/db/compaction/CompactionController.java
index f91c7a5..14c9625 100644
--- a/src/java/org/apache/cassandra/db/compaction/CompactionController.java
+++ b/src/java/org/apache/cassandra/db/compaction/CompactionController.java
@@ -109,7 +109,7 @@ public class CompactionController
             {
                 // if we don't have bloom filter(bf_fp_chance=1.0 or filter file is missing),
                 // we check index file instead.
-                if (sstable.getBloomFilter() instanceof AlwaysPresentFilter && sstable.getPosition(key,
SSTableReader.Operator.EQ) != null)
+                if (sstable.getBloomFilter() instanceof AlwaysPresentFilter && sstable.getPosition(key,
SSTableReader.Operator.EQ, false) != null)
                     return false;
                 else if (sstable.getBloomFilter().isPresent(key.key))
                     return false;

http://git-wip-us.apache.org/repos/asf/cassandra/blob/f5d632fa/src/java/org/apache/cassandra/io/sstable/SSTableReader.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/io/sstable/SSTableReader.java b/src/java/org/apache/cassandra/io/sstable/SSTableReader.java
index 412e4c1..8efa4f1 100644
--- a/src/java/org/apache/cassandra/io/sstable/SSTableReader.java
+++ b/src/java/org/apache/cassandra/io/sstable/SSTableReader.java
@@ -23,6 +23,7 @@ import java.util.*;
 import java.util.concurrent.atomic.AtomicInteger;
 import java.util.concurrent.atomic.AtomicBoolean;
 import java.util.concurrent.*;
+import java.util.concurrent.atomic.AtomicLong;
 
 import com.google.common.util.concurrent.RateLimiter;
 import org.slf4j.Logger;
@@ -102,6 +103,9 @@ public class SSTableReader extends SSTable
 
     private final SSTableMetadata sstableMetadata;
 
+    private final AtomicLong keyCacheHit = new AtomicLong(0);
+    private final AtomicLong keyCacheRequest = new AtomicLong(0);
+
     public static long getApproximateKeyCount(Iterable<SSTableReader> sstables)
     {
         long count = 0;
@@ -764,8 +768,20 @@ public class SSTableReader extends SSTable
 
     private RowIndexEntry getCachedPosition(KeyCacheKey unifiedKey, boolean updateStats)
     {
-        if (keyCache != null && keyCache.getCapacity() > 0)
-            return updateStats ? keyCache.get(unifiedKey) : keyCache.getInternal(unifiedKey);
+        if (keyCache != null && keyCache.getCapacity() > 0) {
+            if (updateStats)
+            {
+                RowIndexEntry cachedEntry = keyCache.get(unifiedKey);
+                keyCacheRequest.incrementAndGet();
+                if (cachedEntry != null)
+                    keyCacheHit.incrementAndGet();
+                return cachedEntry;
+            }
+            else
+            {
+                return keyCache.getInternal(unifiedKey);
+            }
+        }
         return null;
     }
 
@@ -1218,6 +1234,22 @@ public class SSTableReader extends SSTable
     }
 
     /**
+     * @return Number of key cache hit
+     */
+    public long getKeyCacheHit()
+    {
+        return keyCacheHit.get();
+    }
+
+    /**
+     * @return Number of key cache request
+     */
+    public long getKeyCacheRequest()
+    {
+        return keyCacheRequest.get();
+    }
+
+    /**
      * @param sstables
      * @return true if all desired references were acquired.  Otherwise, it will unreference
any partial acquisition, and return false.
      */

http://git-wip-us.apache.org/repos/asf/cassandra/blob/f5d632fa/src/java/org/apache/cassandra/metrics/ColumnFamilyMetrics.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/metrics/ColumnFamilyMetrics.java b/src/java/org/apache/cassandra/metrics/ColumnFamilyMetrics.java
index d7ae745..d59cd50 100644
--- a/src/java/org/apache/cassandra/metrics/ColumnFamilyMetrics.java
+++ b/src/java/org/apache/cassandra/metrics/ColumnFamilyMetrics.java
@@ -22,6 +22,7 @@ import com.yammer.metrics.core.Counter;
 import com.yammer.metrics.core.Gauge;
 import com.yammer.metrics.core.Histogram;
 import com.yammer.metrics.core.MetricName;
+import com.yammer.metrics.util.RatioGauge;
 
 import org.apache.cassandra.db.ColumnFamilyStore;
 import org.apache.cassandra.db.Table;
@@ -76,6 +77,8 @@ public class ColumnFamilyMetrics
     public final Gauge<Double> recentBloomFilterFalseRatio;
     /** Disk space used by bloom filter */
     public final Gauge<Long> bloomFilterDiskSpaceUsed;
+    /** Key cache hit rate  for this CF */
+    public final Gauge<Double> keyCacheHitRate;
 
     private final MetricNameFactory factory;
 
@@ -274,6 +277,24 @@ public class ColumnFamilyMetrics
                 return total;
             }
         });
+        keyCacheHitRate = Metrics.newGauge(factory.createMetricName("KeyCacheHitRate"), new
RatioGauge()
+        {
+            protected double getNumerator()
+            {
+                long hits = 0L;
+                for (SSTableReader sstable : cfs.getSSTables())
+                    hits += sstable.getKeyCacheHit();
+                return hits;
+            }
+
+            protected double getDenominator()
+            {
+                long requests = 0L;
+                for (SSTableReader sstable : cfs.getSSTables())
+                    requests += sstable.getKeyCacheRequest();
+                return Math.max(requests, 1); // to avoid NaN.
+            }
+        });
     }
 
     public void updateSSTableIterated(int count)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/f5d632fa/src/java/org/apache/cassandra/service/CacheService.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/service/CacheService.java b/src/java/org/apache/cassandra/service/CacheService.java
index f77110c..34864f2 100644
--- a/src/java/org/apache/cassandra/service/CacheService.java
+++ b/src/java/org/apache/cassandra/service/CacheService.java
@@ -388,7 +388,7 @@ public class CacheService implements CacheServiceMBean
             }
             RowIndexEntry entry = promotedIndexes
                                 ? RowIndexEntry.serializer.deserialize(input, reader.descriptor.version)
-                                : reader.getPosition(reader.partitioner.decorateKey(key),
Operator.EQ);
+                                : reader.getPosition(reader.partitioner.decorateKey(key),
Operator.EQ, false);
             return Futures.immediateFuture(Pair.create(new KeyCacheKey(reader.descriptor,
key), entry));
         }
 
@@ -410,7 +410,7 @@ public class CacheService implements CacheServiceMBean
 
                 for (SSTableReader sstable : cfs.getSSTables())
                 {
-                    RowIndexEntry entry = sstable.getPosition(dk, Operator.EQ);
+                    RowIndexEntry entry = sstable.getPosition(dk, Operator.EQ, false);
                     if (entry != null)
                         keyCache.put(new KeyCacheKey(sstable.descriptor, key), entry);
                 }


Mime
View raw message