jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jsedd...@apache.org
Subject svn commit: r1740815 - /jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/CachingHierarchyManager.java
Date Mon, 25 Apr 2016 11:35:27 GMT
Author: jsedding
Date: Mon Apr 25 11:35:26 2016
New Revision: 1740815

URL: http://svn.apache.org/viewvc?rev=1740815&view=rev
Log:
JCR-3972 - Make size of ID-cache in CachingHierarchyManager configurable

- original patch by Manfred Baedke

Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/CachingHierarchyManager.java

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/CachingHierarchyManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/CachingHierarchyManager.java?rev=1740815&r1=1740814&r2=1740815&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/CachingHierarchyManager.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/CachingHierarchyManager.java
Mon Apr 25 11:35:26 2016
@@ -56,6 +56,12 @@ public class CachingHierarchyManager ext
      */
     public static final int DEFAULT_UPPER_LIMIT = 10000;
 
+    private static final int MAX_UPPER_LIMIT =
+            Integer.getInteger("org.apache.jackrabbit.core.CachingHierarchyManager.cacheSize",
DEFAULT_UPPER_LIMIT);
+
+    private static final int CACHE_STATISTICS_LOG_INTERVAL_MILLIS =
+            Integer.getInteger("org.apache.jackrabbit.core.CachingHierarchyManager.logInterval",
60000);
+
     /**
      * Logger instance
      */
@@ -82,6 +88,11 @@ public class CachingHierarchyManager ext
     private final int upperLimit;
 
     /**
+     * Object collecting and logging statistics about the idCache
+     */
+    private final CacheStatistics idCacheStatistics;
+
+    /**
      * Head of LRU
      */
     private LRUEntry head;
@@ -115,7 +126,13 @@ public class CachingHierarchyManager ext
     public CachingHierarchyManager(NodeId rootNodeId,
                                    ItemStateManager provider) {
         super(rootNodeId, provider);
-        upperLimit = DEFAULT_UPPER_LIMIT;
+        upperLimit = MAX_UPPER_LIMIT;
+        idCacheStatistics = new CacheStatistics();
+        if (log.isTraceEnabled()) {
+            log.trace("CachingHierarchyManager initialized. Max cache size = {}", upperLimit,
new Exception());
+        } else {
+            log.debug("CachingHierarchyManager initialized. Max cache size = {}", upperLimit);
+        }
     }
 
     /**
@@ -552,6 +569,9 @@ public class CachingHierarchyManager ext
                 return;
             }
             if (idCache.size() >= upperLimit) {
+
+                idCacheStatistics.log();
+
                 /**
                  * Remove least recently used item. Scans the LRU list from
                  * head to tail and removes the first item that has no children.
@@ -1021,4 +1041,32 @@ public class CachingHierarchyManager ext
             return id.toString();
         }
     }
+
+    private final class CacheStatistics {
+
+        private final String id;
+
+        private final ReferenceMap cache;
+
+        private long timeStamp = 0;
+
+        public CacheStatistics() {
+            this.id = cacheMonitor.toString();
+            this.cache = idCache;
+        }
+
+        public void log() {
+            if (log.isDebugEnabled()) {
+                long now = System.currentTimeMillis();
+                final String msg = "Cache id = {};size = {};max = {}";
+                if (log.isTraceEnabled()) {
+                    log.trace(msg, new Object[]{id, this.cache.size(), upperLimit}, new Exception());
+                } else if (now > timeStamp + CACHE_STATISTICS_LOG_INTERVAL_MILLIS) {
+                    timeStamp = now;
+                    log.debug(msg, new Object[]{id, this.cache.size(), upperLimit}, new Exception());
+                }
+            }
+        }
+    }
+
 }



Mime
View raw message