jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jsedd...@apache.org
Subject svn commit: r1740828 - in /jackrabbit/branches/2.10: ./ jackrabbit-core/src/main/java/org/apache/jackrabbit/core/CachingHierarchyManager.java
Date Mon, 25 Apr 2016 12:19:53 GMT
Author: jsedding
Date: Mon Apr 25 12:19:52 2016
New Revision: 1740828

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

- merged to branches/2.10

Modified:
    jackrabbit/branches/2.10/   (props changed)
    jackrabbit/branches/2.10/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/CachingHierarchyManager.java

Propchange: jackrabbit/branches/2.10/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Mon Apr 25 12:19:52 2016
@@ -1,3 +1,3 @@
 /jackrabbit/branches/JCR-2272:1173165-1176545
 /jackrabbit/sandbox/JCR-2415-lucene-3.0:1060860-1064038
-/jackrabbit/trunk:1729382,1732436,1740814
+/jackrabbit/trunk:1729382,1732436,1740814-1740815

Modified: jackrabbit/branches/2.10/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/CachingHierarchyManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/2.10/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/CachingHierarchyManager.java?rev=1740828&r1=1740827&r2=1740828&view=diff
==============================================================================
--- jackrabbit/branches/2.10/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/CachingHierarchyManager.java
(original)
+++ jackrabbit/branches/2.10/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/CachingHierarchyManager.java
Mon Apr 25 12:19:52 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