jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From alexparvule...@apache.org
Subject svn commit: r1182835 - in /jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core: cache/AbstractCache.java cache/CacheManager.java persistence/bundle/AbstractBundlePersistenceManager.java
Date Thu, 13 Oct 2011 13:19:38 GMT
Author: alexparvulescu
Date: Thu Oct 13 13:19:38 2011
New Revision: 1182835

URL: http://svn.apache.org/viewvc?rev=1182835&view=rev
Log:
JCR-3098 Add hit miss statistics and logging to caches
 - patch by Bart van der Schans, continued

Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cache/AbstractCache.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cache/CacheManager.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/AbstractBundlePersistenceManager.java

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cache/AbstractCache.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cache/AbstractCache.java?rev=1182835&r1=1182834&r2=1182835&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cache/AbstractCache.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cache/AbstractCache.java
Thu Oct 13 13:19:38 2011
@@ -114,6 +114,7 @@ public abstract class AbstractCache impl
      * interval has passed since the previous listener call.
      */
     protected void recordCacheAccess() {
+        totalAccessCount.incrementAndGet();
         long count = accessCount.incrementAndGet();
         if (count % ACCESS_INTERVAL == 0) {
             CacheAccessListener listener = accessListener.get();
@@ -121,7 +122,6 @@ public abstract class AbstractCache impl
                 listener.cacheAccessed(count);
             }
         }
-        totalAccessCount.incrementAndGet();
     }
 
     protected void recordCacheMiss() {
@@ -186,13 +186,13 @@ public abstract class AbstractCache impl
         long u = getMemoryUsed() / 1024;
         long m = getMaxMemorySize() / 1024;
         StringBuilder c = new StringBuilder();
-        c.append("Cache name=");
+        c.append("cachename=");
         c.append(this.toString());
         c.append(", elements=");
         c.append(getElementCount());
-        c.append(", used memory=");
+        c.append(", usedmemorykb=");
         c.append(u);
-        c.append(", max memory=");
+        c.append(", maxmemorykb=");
         c.append(m);
         c.append(", access=");
         c.append(getTotalAccessCount());

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cache/CacheManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cache/CacheManager.java?rev=1182835&r1=1182834&r2=1182835&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cache/CacheManager.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cache/CacheManager.java
Thu Oct 13 13:19:38 2011
@@ -156,17 +156,18 @@ public class CacheManager implements Cac
      * Log info about the caches.
      */
     private void logCacheStats() {
-        if (log.isDebugEnabled()) {
+        if (log.isInfoEnabled()) {
             long now = System.currentTimeMillis();
             if (now < nextLogStats) {
                 return;
             }
             for (Cache cache : caches.keySet()) {
-                log.debug(cache.getCacheInfoAsString());
+                log.info(cache.getCacheInfoAsString());
             }
             nextLogStats = now + minLogStatsInterval;
         }
     }
+
     /**
      * Re-calculate the maximum memory for each cache, and set the new limits.
      */

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/AbstractBundlePersistenceManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/AbstractBundlePersistenceManager.java?rev=1182835&r1=1182834&r2=1182835&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/AbstractBundlePersistenceManager.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/AbstractBundlePersistenceManager.java
Thu Oct 13 13:19:38 2011
@@ -28,6 +28,8 @@ import javax.jcr.PropertyType;
 
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.apache.jackrabbit.core.cache.Cache;
+import org.apache.jackrabbit.core.cache.CacheAccessListener;
 import org.apache.jackrabbit.core.cache.ConcurrentCache;
 import org.apache.jackrabbit.core.fs.FileSystemResource;
 import org.apache.jackrabbit.core.fs.FileSystem;
@@ -82,7 +84,7 @@ import org.apache.jackrabbit.spi.Name;
  * </ul>
  */
 public abstract class AbstractBundlePersistenceManager implements
-    PersistenceManager, CachingPersistenceManager, IterablePersistenceManager {
+    PersistenceManager, CachingPersistenceManager, IterablePersistenceManager, CacheAccessListener
{
 
     /** the default logger */
     private static Logger log = LoggerFactory.getLogger(AbstractBundlePersistenceManager.class);
@@ -112,6 +114,18 @@ public abstract class AbstractBundlePers
     /** the cache of loaded bundles */
     private ConcurrentCache<NodeId, NodePropBundle> bundles;
 
+    /** The default minimum stats logging interval (in ms). */
+    private static final int DEFAULT_LOG_STATS_INTERVAL = 60 * 1000;
+
+    /** The minimum interval time between stats are logged */
+    private long minLogStatsInterval = Long.getLong(
+            "org.apache.jackrabbit.cacheLogStatsInterval",
+            DEFAULT_LOG_STATS_INTERVAL);
+
+    /** The last time the cache stats were logged. */
+    private volatile long nextLogStats =
+            System.currentTimeMillis() + DEFAULT_LOG_STATS_INTERVAL;
+
     /** the persistence manager context */
     protected PMContext context;
 
@@ -379,6 +393,7 @@ public abstract class AbstractBundlePers
         // init bundle cache
         bundles = new ConcurrentCache<NodeId, NodePropBundle>(context.getHomeDir().getName()
+ "BundleCache");
         bundles.setMaxMemorySize(bundleCacheSize);
+        bundles.setAccessListener(this);
     }
 
     /**
@@ -709,4 +724,22 @@ public abstract class AbstractBundlePers
         bundles.remove(id);
     }
 
+    public void cacheAccessed(long accessCount) {
+        logCacheStats();
+    }
+
+    private void logCacheStats() {
+        if (log.isInfoEnabled()) {
+            long now = System.currentTimeMillis();
+            if (now < nextLogStats) {
+                return;
+            }
+            log.info(bundles.getCacheInfoAsString());
+            nextLogStats = now + minLogStatsInterval;
+        }
+    }
+
+    public void disposeCache(Cache cache) {
+        // NOOP
+    }
 }



Mime
View raw message