jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r1005057 - in /jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core: cache/ConcurrentCache.java state/ItemStateReferenceCache.java
Date Wed, 06 Oct 2010 14:30:13 GMT
Author: jukka
Date: Wed Oct  6 14:30:13 2010
New Revision: 1005057

URL: http://svn.apache.org/viewvc?rev=1005057&view=rev
Log:
JCR-2699: Improve read/write concurrency

Use a constant for the default number of cache segments to use, as computing the number of
available processors can be quite expensive.

Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cache/ConcurrentCache.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/ItemStateReferenceCache.java

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cache/ConcurrentCache.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cache/ConcurrentCache.java?rev=1005057&r1=1005056&r2=1005057&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cache/ConcurrentCache.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cache/ConcurrentCache.java
Wed Oct  6 14:30:13 2010
@@ -31,6 +31,19 @@ import java.util.Map;
  */
 public class ConcurrentCache<K, V> extends AbstractCache {
 
+    /**
+     * Default number of cache segments to use. Use the number of available
+     * processors (even if that might change during runtime!) as a reasonable
+     * approximation of the amount of parallelism we should expect in the
+     * worst case.
+     * <p>
+     * One reason for this value being a constant is that the
+     * {@link Runtime#availableProcessors()} call is somewhat expensive at
+     * least in some environments.
+     */
+    private static int DEFAULT_NUMBER_OF_SEGMENTS =
+        Runtime.getRuntime().availableProcessors();
+
     private static class E<V> {
 
         private final V value;
@@ -65,7 +78,7 @@ public class ConcurrentCache<K, V> exten
     }
 
     public ConcurrentCache() {
-        this(Runtime.getRuntime().availableProcessors());
+        this(DEFAULT_NUMBER_OF_SEGMENTS);
     }
 
     /**

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/ItemStateReferenceCache.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/ItemStateReferenceCache.java?rev=1005057&r1=1005056&r2=1005057&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/ItemStateReferenceCache.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/ItemStateReferenceCache.java
Wed Oct  6 14:30:13 2010
@@ -46,7 +46,21 @@ import java.util.Map;
 public class ItemStateReferenceCache implements ItemStateCache {
 
     /** Logger instance */
-    private static Logger log = LoggerFactory.getLogger(ItemStateReferenceCache.class);
+    private static final Logger log =
+        LoggerFactory.getLogger(ItemStateReferenceCache.class);
+
+    /**
+     * The number of cache segments to use. Use the number of available
+     * processors (even if that might change during runtime!) as a reasonable
+     * approximation of the amount of parallelism we should expect in the
+     * worst case.
+     * <p>
+     * One reason for this value being a constant is that the
+     * {@link Runtime#availableProcessors()} call is somewhat expensive at
+     * least in some environments.
+     */
+    private static int NUMBER_OF_SEGMENTS =
+        Runtime.getRuntime().availableProcessors();
 
     /**
      * Cache that automatically flushes entries based on some eviction policy;
@@ -79,7 +93,7 @@ public class ItemStateReferenceCache imp
     @SuppressWarnings("unchecked")
     public ItemStateReferenceCache(ItemStateCache cache) {
         this.cache = cache;
-        this.segments = new Map[Runtime.getRuntime().availableProcessors()];
+        this.segments = new Map[NUMBER_OF_SEGMENTS];
         for (int i = 0; i < segments.length; i++) {
             // I tried using soft instead of weak references here, but that
             // seems to have some unexpected performance consequences (notable



Mime
View raw message