You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jackrabbit.apache.org by ju...@apache.org on 2007/04/18 08:57:22 UTC
svn commit: r529894 - in
/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core:
RepositoryImpl.java state/CacheManager.java
Author: jukka
Date: Tue Apr 17 23:57:21 2007
New Revision: 529894
URL: http://svn.apache.org/viewvc?view=rev&rev=529894
Log:
JCR-725: Enabled runtime configuration of cache size with a patch from Jaka Jaksic. Thanks!
Modified:
jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/RepositoryImpl.java
jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/CacheManager.java
Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/RepositoryImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/RepositoryImpl.java?view=diff&rev=529894&r1=529893&r2=529894
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/RepositoryImpl.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/RepositoryImpl.java Tue Apr 17 23:57:21 2007
@@ -330,9 +330,20 @@
}
/**
- * Get the item state cache factory of this repository.
+ * Get the cache manager of this repository, useful
+ * for setting its memory parameters.
*
* @return the cache manager
+ * @since 1.3
+ */
+ public CacheManager getCacheManager() {
+ return cacheMgr;
+ }
+
+ /**
+ * Get the item state cache factory of this repository.
+ *
+ * @return the cache factory
*/
public ItemStateCacheFactory getItemStateCacheFactory() {
return cacheFactory;
Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/CacheManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/CacheManager.java?view=diff&rev=529894&r1=529893&r2=529894
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/CacheManager.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/CacheManager.java Tue Apr 17 23:57:21 2007
@@ -41,14 +41,14 @@
/** The logger instance. */
private static Logger log = LoggerFactory.getLogger(CacheManager.class);
- /** The amount of memory to distribute accross the caches. */
- private static final long MAX_MEMORY = 16 * 1024 * 1024;
+ /** The default maximum amount of memory to distribute accross the caches. */
+ private static final long DEFAULT_MAX_MEMORY = 16 * 1024 * 1024;
- /** The minimum size of a cache. */
- private static final long MIN_MEMORY_PER_CACHE = 128 * 1024;
+ /** The default minimum size of a cache. */
+ private static final long DEFAULT_MIN_MEMORY_PER_CACHE = 128 * 1024;
- /** The maximum memory per cache (unless, there is some unused memory). */
- private static final long MAX_MEMORY_PER_CACHE = 4 * 1024 * 1024;
+ /** The default maximum memory per cache. */
+ private static final long DEFAULT_MAX_MEMORY_PER_CACHE = 4 * 1024 * 1024;
/** The set of caches (weakly referenced). */
private WeakHashMap caches = new WeakHashMap();
@@ -59,9 +59,44 @@
/** The size of a big object, to detect if a cache is full or not. */
private static final int BIG_OBJECT_SIZE = 16 * 1024;
+ /** The amount of memory to distribute accross the caches. */
+ private long maxMemory = DEFAULT_MAX_MEMORY;
+
+ /** The minimum size of a cache. */
+ private long minMemoryPerCache = DEFAULT_MIN_MEMORY_PER_CACHE;
+
+ /** The maximum memory per cache (unless, there is some unused memory). */
+ private long maxMemoryPerCache = DEFAULT_MAX_MEMORY_PER_CACHE;
+
/** The last time the caches where resized. */
private volatile long nextResize = System.currentTimeMillis() + SLEEP;
+
+ public long getMaxMemory() {
+ return maxMemory;
+ }
+
+ public void setMaxMemory(final long maxMemory) {
+ this.maxMemory = maxMemory;
+ }
+
+ public long getMaxMemoryPerCache() {
+ return maxMemoryPerCache;
+ }
+
+ public void setMaxMemoryPerCache(final long maxMemoryPerCache) {
+ this.maxMemoryPerCache = maxMemoryPerCache;
+ }
+
+ public long getMinMemoryPerCache() {
+ return minMemoryPerCache;
+ }
+
+ public void setMinMemoryPerCache(final long minMemoryPerCache) {
+ this.minMemoryPerCache = minMemoryPerCache;
+ }
+
+
/**
* After one of the caches is accessed a number of times, this method is called.
* Resize the caches if required.
@@ -118,27 +153,27 @@
// and find out how many caches are full
// 50% is distributed according to access count,
// and 50% according to memory used
- double memoryPerAccess = (double) MAX_MEMORY / 2.
+ double memoryPerAccess = (double) maxMemory / 2.
/ Math.max(1., (double) totalAccessCount);
- double memoryPerUsed = (double) MAX_MEMORY / 2.
+ double memoryPerUsed = (double) maxMemory / 2.
/ Math.max(1., (double) totalMemoryUsed);
int fullCacheCount = 0;
for (int i = 0; i < infos.length; i++) {
CacheInfo info = infos[i];
long mem = (long) (memoryPerAccess * info.getAccessCount());
mem += (long) (memoryPerUsed * info.getMemoryUsed());
- mem = Math.min(mem, MAX_MEMORY_PER_CACHE);
+ mem = Math.min(mem, maxMemoryPerCache);
if (info.wasFull()) {
fullCacheCount++;
} else {
mem = Math.min(mem, info.getMemoryUsed());
}
- mem = Math.min(mem, MAX_MEMORY_PER_CACHE);
- mem = Math.max(mem, MIN_MEMORY_PER_CACHE);
+ mem = Math.min(mem, maxMemoryPerCache);
+ mem = Math.max(mem, minMemoryPerCache);
info.setMemory(mem);
}
// calculate the unused memory
- long unusedMemory = MAX_MEMORY;
+ long unusedMemory = maxMemory;
for (int i = 0; i < infos.length; i++) {
unusedMemory -= infos[i].getMemory();
}