cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jbel...@apache.org
Subject svn commit: r898177 - in /incubator/cassandra/trunk/src/java/org/apache/cassandra: db/ColumnFamilyStore.java utils/InstrumentedCache.java utils/InstrumentedCacheMBean.java
Date Tue, 12 Jan 2010 04:04:14 GMT
Author: jbellis
Date: Tue Jan 12 04:04:13 2010
New Revision: 898177

URL: http://svn.apache.org/viewvc?rev=898177&view=rev
Log:
row cache instrumentation
patch by jbellis; reviewed by goffinet for CASSANDRA-678

Added:
    incubator/cassandra/trunk/src/java/org/apache/cassandra/utils/InstrumentedCache.java 
 (with props)
    incubator/cassandra/trunk/src/java/org/apache/cassandra/utils/InstrumentedCacheMBean.java
  (with props)
Modified:
    incubator/cassandra/trunk/src/java/org/apache/cassandra/db/ColumnFamilyStore.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=898177&r1=898176&r2=898177&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 Tue
Jan 12 04:04:13 2010
@@ -106,7 +106,7 @@
     /* active memtable associated with this ColumnFamilyStore. */
     private Memtable memtable_;
 
-    private ConcurrentLinkedHashMap<String, ColumnFamily> rowCache;
+    private InstrumentedCache<String, ColumnFamily> rowCache;
 
     // TODO binarymemtable ops are not threadsafe (do they need to be?)
     private AtomicReference<BinaryMemtable> binaryMemtable_;
@@ -185,9 +185,9 @@
         }
         ssTables_ = new SSTableTracker(sstables);
 
-        int cacheSize = (int)(0.1 * SSTableReader.estimatedKeys(columnFamilyName));
+        int cacheSize = (int)(0.2 * SSTableReader.estimatedKeys(columnFamilyName));
         logger_.info("cache size for " + columnFamilyName + " is " + cacheSize);
-        rowCache = ConcurrentLinkedHashMap.create(ConcurrentLinkedHashMap.EvictionPolicy.SECOND_CHANCE,
cacheSize);
+        rowCache = new InstrumentedCache<String, ColumnFamily>(table, columnFamilyName
+ "RowCache", cacheSize);
     }
 
     public static ColumnFamilyStore createColumnFamilyStore(String table, String columnFamily)
throws IOException
@@ -224,7 +224,7 @@
         MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
         try
         {
-            String mbeanName = "org.apache.cassandra.db:type=ColumnFamilyStores,name=" +
table + ",columnfamily=" + columnFamily;
+            String mbeanName = "org.apache.cassandra.db:type=ColumnFamilyStores,keyspace="
+ table + ",columnfamily=" + columnFamily;
             mbs.registerMBean(cfs, new ObjectName(mbeanName));
         }
         catch (Exception e)

Added: incubator/cassandra/trunk/src/java/org/apache/cassandra/utils/InstrumentedCache.java
URL: http://svn.apache.org/viewvc/incubator/cassandra/trunk/src/java/org/apache/cassandra/utils/InstrumentedCache.java?rev=898177&view=auto
==============================================================================
--- incubator/cassandra/trunk/src/java/org/apache/cassandra/utils/InstrumentedCache.java (added)
+++ incubator/cassandra/trunk/src/java/org/apache/cassandra/utils/InstrumentedCache.java Tue
Jan 12 04:04:13 2010
@@ -0,0 +1,64 @@
+package org.apache.cassandra.utils;
+
+import java.lang.management.ManagementFactory;
+import javax.management.MBeanServer;
+import javax.management.ObjectName;
+
+import com.reardencommerce.kernel.collections.shared.evictable.ConcurrentLinkedHashMap;
+
+public class InstrumentedCache<K, V> implements InstrumentedCacheMBean
+{
+    private final int capacity;
+    private final ConcurrentLinkedHashMap<K, V> map;
+    private final TimedStatsDeque stats;
+
+    public InstrumentedCache(String table, String name, int capacity)
+    {
+        this.capacity = capacity;
+        map = ConcurrentLinkedHashMap.create(ConcurrentLinkedHashMap.EvictionPolicy.SECOND_CHANCE,
capacity);
+        stats = new TimedStatsDeque(60000);
+
+        MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
+        try
+        {
+            String mbeanName = "org.apache.cassandra.db:type=Caches,keyspace=" + table +
",cache=" + name;
+            mbs.registerMBean(this, new ObjectName(mbeanName));
+        }
+        catch (Exception e)
+        {
+            throw new RuntimeException(e);
+        }
+    }
+
+    public void put(K key, V value)
+    {
+        map.put(key, value);
+    }
+
+    public V get(K key)
+    {
+        V v = map.get(key);
+        stats.add(v == null ? 0 : 1);
+        return v;
+    }
+
+    public void remove(K key)
+    {
+        map.remove(key);
+    }
+
+    public int getCapacity()
+    {
+        return capacity;
+    }
+
+    public int getSize()
+    {
+        return map.size();
+    }
+
+    public double getHitRate()
+    {
+        return stats.mean();
+    }
+}

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

Added: incubator/cassandra/trunk/src/java/org/apache/cassandra/utils/InstrumentedCacheMBean.java
URL: http://svn.apache.org/viewvc/incubator/cassandra/trunk/src/java/org/apache/cassandra/utils/InstrumentedCacheMBean.java?rev=898177&view=auto
==============================================================================
--- incubator/cassandra/trunk/src/java/org/apache/cassandra/utils/InstrumentedCacheMBean.java
(added)
+++ incubator/cassandra/trunk/src/java/org/apache/cassandra/utils/InstrumentedCacheMBean.java
Tue Jan 12 04:04:13 2010
@@ -0,0 +1,8 @@
+package org.apache.cassandra.utils;
+
+public interface InstrumentedCacheMBean
+{
+    public int getCapacity();
+    public int getSize();
+    public double getHitRate();
+}

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



Mime
View raw message