aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoy Varghese2014-01-14 14:12:24 (EST)
committerRoy Varghese2014-01-14 14:15:25 (EST)
commit3ed47faa878d87e79674affd601ce824fe64e1c2 (patch)
tree2e7423a5f905b142193f54f9cf6bc605150fed9b
parentb8c008b5fb7b7fe9ca7681e4497ae9170ac83617 (diff)
downloadorg.eclipse.hudson.core-3ed47faa878d87e79674affd601ce824fe64e1c2.zip
org.eclipse.hudson.core-3ed47faa878d87e79674affd601ce824fe64e1c2.tar.gz
org.eclipse.hudson.core-3ed47faa878d87e79674affd601ce824fe64e1c2.tar.bz2
Expose system parameters to tune cache settings.refs/changes/27/20627/1
// For all jobs hudson.jobs.cache.evict_in_seconds ( default=60 ) hudson.jobs.cache.initial_capacity ( default=1024 ) hudson.jobs.cache.max_entries ( default=1024) // For each job hudson.job.builds.cache.evict_in_seconds ( default=60 ) hudson.job.builds.cache.initial_capacity" ( default=512 ) hudson.job.builds.cache.max_entries ( default=10240 ) Signed-Off-By: Roy Varghese <rovarghe@gmail.com>
-rw-r--r--hudson-core/src/main/java/hudson/model/RunMap.java29
-rw-r--r--hudson-core/src/main/java/hudson/model/TopLevelItemsCache.java32
2 files changed, 50 insertions, 11 deletions
diff --git a/hudson-core/src/main/java/hudson/model/RunMap.java b/hudson-core/src/main/java/hudson/model/RunMap.java
index 4ae43a9..60b3ac0 100644
--- a/hudson-core/src/main/java/hudson/model/RunMap.java
+++ b/hudson-core/src/main/java/hudson/model/RunMap.java
@@ -736,14 +736,35 @@ public final class RunMap<J extends Job<J, R>, R extends Run<J, R>>
private static class LazyRunValueCache {
final private LoadingCache<LazyRunValue.Key, Run> cache;
- final static int EVICT_BUILD_IN_SECONDS = 60;
- final static int MAX_ENTRIES = 10000;
+
+ // Seconds after which items in cache are removed. Time is reset on access.
+ private static int EVICT_IN_SECONDS;
+
+ // Initial cache capacity
+ private static int INITIAL_CAPACITY;
+
+ // Maximum number of cached entries.
+ private static int MAX_ENTRIES;
+
+ // Initialize from system properties if available
+ {
+ Integer val;
+
+ val = Integer.getInteger("hudson.job.builds.cache.evict_in_seconds");
+ EVICT_IN_SECONDS = val == null? 60: val;
+
+ val = Integer.getInteger("hudson.job.builds.cache.initial_capacity");
+ INITIAL_CAPACITY = val == null ? 512: val;
+
+ val = Integer.getInteger("hudson.job.builds.cache.max_entries");
+ MAX_ENTRIES = val == null ? 10 * 1024 : val;
+ }
private LazyRunValueCache() {
cache = CacheBuilder.newBuilder()
- .expireAfterAccess(EVICT_BUILD_IN_SECONDS, TimeUnit.SECONDS)
- .initialCapacity(1024)
+ .expireAfterAccess(EVICT_IN_SECONDS, TimeUnit.SECONDS)
+ .initialCapacity(INITIAL_CAPACITY)
.maximumSize(MAX_ENTRIES)
.softValues()
.build( new CacheLoader<LazyRunValue.Key, Run>() {
diff --git a/hudson-core/src/main/java/hudson/model/TopLevelItemsCache.java b/hudson-core/src/main/java/hudson/model/TopLevelItemsCache.java
index 3c9a20c..aaa1b09 100644
--- a/hudson-core/src/main/java/hudson/model/TopLevelItemsCache.java
+++ b/hudson-core/src/main/java/hudson/model/TopLevelItemsCache.java
@@ -6,7 +6,7 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- * Hudson - initial API and implementation and/or initial documentation
+ * Roy Varghese
*/
package hudson.model;
@@ -19,8 +19,7 @@ import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
-import java.util.logging.Level;
-import java.util.logging.Logger;
+import org.slf4j.LoggerFactory;
/**
* A cache for {@link TopLevelItems} object that are directly held by
@@ -33,9 +32,28 @@ import java.util.logging.Logger;
class TopLevelItemsCache {
// Cache parameters
- private final static int EVICT_IN_SECONDS = 60;
- private final static int INITIAL_CAPACITY = 1024;
- private final static int MAX_ENTRIES = 1000;
+ // Seconds after which items in cache are removed. Time is reset on access.
+ private static int EVICT_IN_SECONDS;
+
+ // Initial cache capacity
+ private static int INITIAL_CAPACITY;
+
+ // Maximum number of cached entries.
+ private static int MAX_ENTRIES;
+
+ // Initialize from system properties if available
+ {
+ Integer val;
+
+ val = Integer.getInteger("hudson.jobs.cache.evict_in_seconds");
+ EVICT_IN_SECONDS = val == null? 60: val;
+
+ val = Integer.getInteger("hudson.jobs.cache.initial_capacity");
+ INITIAL_CAPACITY = val == null ? 1024: val;
+
+ val = Integer.getInteger("hudson.jobs.cache.max_entries");
+ MAX_ENTRIES = val == null ? 1024 : val;
+ }
final LoadingCache<LazyTopLevelItem.Key, TopLevelItem> cache;
@@ -77,7 +95,7 @@ class TopLevelItemsCache {
try {
return cache.get(key);
} catch (ExecutionException ex) {
- Logger.getLogger(TopLevelItemsCache.class.getName()).log(Level.SEVERE, null, ex);
+ LoggerFactory.getLogger(TopLevelItemsCache.class.getName()).error("Error when retrieving item from cache", ex);
return null;
}