changeset 22:b7e52953b7a6

Add some cache/memory statistics to help spot potential exhaustion and other tuning issues.
author Dan Creswell <dan.creswell@gmail.com>
date Fri, 28 Aug 2009 17:23:33 +0100
parents 8417eaebf5ab
children 28c84687bdb8
files src/org/dancres/blitz/arc/ArcCache.java src/org/dancres/blitz/entry/SleeveCache.java src/org/dancres/blitz/stats/SearchStat.java src/org/dancres/blitz/stats/StoreStat.java
diffstat 4 files changed, 87 insertions(+), 50 deletions(-) [+]
line wrap: on
line diff
--- a/src/org/dancres/blitz/arc/ArcCache.java	Sat Aug 22 23:28:55 2009 +0100
+++ b/src/org/dancres/blitz/arc/ArcCache.java	Fri Aug 28 17:23:33 2009 +0100
@@ -62,6 +62,16 @@
         return theCacheSize;
     }
 
+    public int getActiveSize() {
+        int mySize;
+
+        synchronized(this) {
+            mySize = theBlockIndex.size();
+        }
+
+        return mySize >> 1;
+    }
+
     /**
        For recovery purposes, we wish to be able to ensure that something
        has made it to disk and, if it hasn't, re-insert it to the cache.
--- a/src/org/dancres/blitz/entry/SleeveCache.java	Sat Aug 22 23:28:55 2009 +0100
+++ b/src/org/dancres/blitz/entry/SleeveCache.java	Fri Aug 28 17:23:33 2009 +0100
@@ -14,7 +14,7 @@
 import org.dancres.blitz.Logging;
 import org.dancres.blitz.stats.StatGenerator;
 import org.dancres.blitz.stats.Stat;
-import org.dancres.blitz.stats.SearchStat;
+import org.dancres.blitz.stats.StoreStat;
 import org.dancres.blitz.stats.StatsBoard;
 
 import org.dancres.blitz.oid.OID;
@@ -73,15 +73,13 @@
     }
 
     private final ArcCache[] theStoreCaches;
+    private final CacheSize theCacheSize;
     private final int theNumPartitions;
     private final int thePartitionsMask;
 
     private Storage theStore;
-
     private CountersImpl theCounters;
-
     private EntryConstraints theConstraints;
-
     private CacheIndexer theIndexer;
 
     private long theId = StatGenerator.UNSET_ID;
@@ -145,16 +143,16 @@
             throw myIOE;
         }
         
-        CacheSize myCacheSize = (CacheSize) theConstraints.get(CacheSize.class);
+        theCacheSize = (CacheSize) theConstraints.get(CacheSize.class);
 
         int myNumPartitions;
         int myEntriesPerCache;
 
         if (DESIRED_ENTRIES_PER_PARTITION == -1) {
             myNumPartitions = 1;
-            myEntriesPerCache = myCacheSize.getSize();
+            myEntriesPerCache = theCacheSize.getSize();
         } else {
-            myNumPartitions = (myCacheSize.getSize() / DESIRED_ENTRIES_PER_PARTITION);
+            myNumPartitions = (theCacheSize.getSize() / DESIRED_ENTRIES_PER_PARTITION);
             myEntriesPerCache = DESIRED_ENTRIES_PER_PARTITION;
         }
 
@@ -167,7 +165,7 @@
         thePartitionsMask = theNumPartitions - 1;
         
         theLogger.log(Level.INFO, aStore.getType() + " cache size = "
-                      + myCacheSize.getSize() + " partitions = " + theNumPartitions + 
+                      + theCacheSize.getSize() + " partitions = " + theNumPartitions +
                       " mask = " + Integer.toHexString(thePartitionsMask) + " partition size = " + myEntriesPerCache);
 
         theStoreCaches = new ArcCache[theNumPartitions];
@@ -214,8 +212,13 @@
             myDeld[i] = theTrackers[i].getDeld();
         }
 
-        return new SearchStat(theId, theStore.getType(), myTitles,
-            myMisses, myDeld);
+        int myActiveCache = 0;
+
+        for (int i = 0; i < theStoreCaches.length; i++)
+            myActiveCache += theStoreCaches[i].getActiveSize();
+
+        return new StoreStat(theId, theStore.getType(), myTitles,
+            myMisses, myDeld, myActiveCache, theCacheSize.getSize());
     }
 
     private int getPartition(CacheBlockDescriptor aCBD) {
--- a/src/org/dancres/blitz/stats/SearchStat.java	Sat Aug 22 23:28:55 2009 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,40 +0,0 @@
-package org.dancres.blitz.stats;
-
-/**
- */
-public class SearchStat implements Stat {
-    private long _id;
-    private String _type;
-    private String[] _titles;
-    private long[] _missed;
-    private long[] _deleted;
-
-    public SearchStat(long anId, String aType,
-                      String[] aTitles,
-                      long[] aMisses, long[] aDeld) {
-        _id = anId;
-        _type = aType;
-        _titles = aTitles;
-        _missed = aMisses;
-        _deleted = aDeld;
-    }
-    
-    public long getId() {
-        return _id;
-    }
-
-    public String toString() {
-        StringBuffer myBuffer = new StringBuffer("Search: " + _type);
-
-        for (int i = 0; i < _titles.length; i++) {
-            myBuffer.append(" ");
-            myBuffer.append(_titles[i]);
-            myBuffer.append(" miss: ");
-            myBuffer.append(_missed[i]);
-            myBuffer.append(" deld: ");
-            myBuffer.append(_deleted[i]);
-        }
-
-        return myBuffer.toString();
-    }
-}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/org/dancres/blitz/stats/StoreStat.java	Fri Aug 28 17:23:33 2009 +0100
@@ -0,0 +1,64 @@
+package org.dancres.blitz.stats;
+
+/**
+ */
+public class StoreStat implements Stat {
+    private static final long _minimalFree;
+
+    private long _id;
+    private String _type;
+    private String[] _titles;
+    private long[] _missed;
+    private long[] _deleted;
+    private boolean _safe;
+
+    private int _activeCache;
+    private int _totalCache;
+    private long _free;
+    private long _max;
+
+    static {
+        _minimalFree = Runtime.getRuntime().maxMemory() / 5;
+    }
+
+    public StoreStat(long anId, String aType,
+                      String[] aTitles,
+                      long[] aMisses, long[] aDeld, int anActiveCacheSize, int aCacheSize) {
+        _id = anId;
+        _type = aType;
+        _titles = aTitles;
+        _missed = aMisses;
+        _deleted = aDeld;
+
+        _activeCache = anActiveCacheSize;
+        _totalCache = aCacheSize;
+        _free = Runtime.getRuntime().freeMemory();
+        _max = Runtime.getRuntime().maxMemory();
+
+        _safe = (anActiveCacheSize == aCacheSize) &&
+                (Runtime.getRuntime().freeMemory() >= _minimalFree);
+    }
+    
+    public long getId() {
+        return _id;
+    }
+
+    public String toString() {
+        StringBuffer myBuffer = new StringBuffer("Store: " + _type);
+
+        for (int i = 0; i < _titles.length; i++) {
+            myBuffer.append(" ");
+            myBuffer.append(_titles[i]);
+            myBuffer.append(" miss: ");
+            myBuffer.append(_missed[i]);
+            myBuffer.append(" deld: ");
+            myBuffer.append(_deleted[i]);
+        }
+
+        myBuffer.append(" sustainable: ");
+        myBuffer.append(_safe);
+        myBuffer.append(" (" + _activeCache + ", " + _totalCache + ", " + _free + ", " + _max + ")");
+
+        return myBuffer.toString();
+    }
+}