diff options
| author | Andrew Branson <andrew.branson@cern.ch> | 2012-12-18 17:02:17 +0100 |
|---|---|---|
| committer | Andrew Branson <andrew.branson@cern.ch> | 2012-12-18 17:02:17 +0100 |
| commit | 31746638f0a7d99093f9348e14436c3b7aea28db (patch) | |
| tree | 40f3f215f72974287e0a057d6fe4547a9d81963c /src/main/java/com/c2kernel/persistency | |
| parent | 82a3a75cf8045a638e0dcd90dcff39a67609bc68 (diff) | |
Added optional WeakCache to hold fewer ClusterStorage objects in memory.
Enabled with Storage.useWeakCache property. Useful for large imports and
other operations that involve accessing a large number of items over a
short period.
Diffstat (limited to 'src/main/java/com/c2kernel/persistency')
| -rw-r--r-- | src/main/java/com/c2kernel/persistency/ClusterStorageManager.java | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/src/main/java/com/c2kernel/persistency/ClusterStorageManager.java b/src/main/java/com/c2kernel/persistency/ClusterStorageManager.java index 70fb46d..c49b41f 100644 --- a/src/main/java/com/c2kernel/persistency/ClusterStorageManager.java +++ b/src/main/java/com/c2kernel/persistency/ClusterStorageManager.java @@ -16,7 +16,9 @@ import com.c2kernel.persistency.outcome.Outcome; import com.c2kernel.persistency.outcome.Viewpoint;
import com.c2kernel.process.Gateway;
import com.c2kernel.utils.Logger;
+import com.c2kernel.utils.NonStrongRefCache;
import com.c2kernel.utils.SoftCache;
+import com.c2kernel.utils.WeakCache;
/**
* instantiates ClusterStorages listed in properties file All read/write requests to storage pass through this object, which
@@ -31,7 +33,7 @@ public class ClusterStorageManager { HashMap<String, ArrayList<ClusterStorage>> clusterWriters = new HashMap<String, ArrayList<ClusterStorage>>();
HashMap<String, ArrayList<ClusterStorage>> clusterReaders = new HashMap<String, ArrayList<ClusterStorage>>();
// we don't need a soft cache for the top level cache - the proxies and entities clear that when reaped
- HashMap<Integer, SoftCache<String, C2KLocalObject>> memoryCache = new HashMap<Integer, SoftCache<String, C2KLocalObject>>();
+ HashMap<Integer, NonStrongRefCache<String, C2KLocalObject>> memoryCache = new HashMap<Integer, NonStrongRefCache<String, C2KLocalObject>>();
/**
* Initialises all ClusterStorage handlers listed by class name in the property "ClusterStorages"
@@ -159,7 +161,7 @@ public class ClusterStorageManager { public C2KLocalObject get(Integer sysKeyIntObj, String path) throws ClusterStorageException, ObjectNotFoundException {
C2KLocalObject result = null;
// check cache first
- SoftCache<String, C2KLocalObject> sysKeyMemCache = null;
+ NonStrongRefCache<String, C2KLocalObject> sysKeyMemCache = null;
if (memoryCache.containsKey(sysKeyIntObj)) {
sysKeyMemCache = memoryCache.get(sysKeyIntObj);
synchronized(sysKeyMemCache) {
@@ -208,7 +210,9 @@ public class ClusterStorageManager { if (result != null) { // got it!
// store it in the cache
if (sysKeyMemCache == null) { // create cache if needed
- sysKeyMemCache = new SoftCache<String, C2KLocalObject>(0);
+ boolean useWeak = Gateway.getProperty("Storage.useWeakCache","false").equals("true");
+ Logger.msg(7,"ClusterStorageManager.put() - Creating "+(useWeak?"Weak":"Strong")+" cache for entity "+sysKeyIntObj);
+ sysKeyMemCache = useWeak?new WeakCache<String, C2KLocalObject>():new SoftCache<String, C2KLocalObject>(0);
synchronized (memoryCache) {
memoryCache.put(sysKeyIntObj, sysKeyMemCache);
}
@@ -242,11 +246,13 @@ public class ClusterStorageManager { }
}
// put in mem cache if that worked
- SoftCache<String, C2KLocalObject> sysKeyMemCache;
+ NonStrongRefCache<String, C2KLocalObject> sysKeyMemCache;
if (memoryCache.containsKey(sysKeyIntObj))
sysKeyMemCache = memoryCache.get(sysKeyIntObj);
else {
- sysKeyMemCache = new SoftCache<String, C2KLocalObject>();
+ boolean useWeak = Gateway.getProperty("Storage.useWeakCache","false").equals("true");
+ Logger.msg(7,"ClusterStorageManager.put() - Creating "+(useWeak?"Weak":"Strong")+" cache for entity "+sysKeyIntObj);
+ sysKeyMemCache = useWeak?new WeakCache<String, C2KLocalObject>():new SoftCache<String, C2KLocalObject>(0);
synchronized (memoryCache) {
memoryCache.put(sysKeyIntObj, sysKeyMemCache);
}
@@ -277,7 +283,7 @@ public class ClusterStorageManager { }
if (memoryCache.containsKey(sysKeyIntObj)) {
- SoftCache<?, ?> sysKeyMemCache = memoryCache.get(sysKeyIntObj);
+ NonStrongRefCache<?, ?> sysKeyMemCache = memoryCache.get(sysKeyIntObj);
synchronized (sysKeyMemCache) {
sysKeyMemCache.remove(path);
}
@@ -292,7 +298,7 @@ public class ClusterStorageManager { Logger.msg(7, "CSM.clearCache() - removing "+sysKeyIntObj+"/"+path);
if (memoryCache.containsKey(sysKeyIntObj)) {
- SoftCache<String, C2KLocalObject> sysKeyMemCache = memoryCache.get(sysKeyIntObj);
+ NonStrongRefCache<String, C2KLocalObject> sysKeyMemCache = memoryCache.get(sysKeyIntObj);
synchronized(sysKeyMemCache) {
for (Iterator<String> iter = sysKeyMemCache.keySet().iterator(); iter.hasNext();) {
String thisPath = iter.next();
@@ -312,7 +318,7 @@ public class ClusterStorageManager { if (memoryCache.containsKey(sysKeyIntObj)) {
synchronized (memoryCache) {
if (Logger.doLog(6)) {
- SoftCache<?, ?> sysKeyMemCache = memoryCache.get(sysKeyIntObj);
+ NonStrongRefCache<?, ?> sysKeyMemCache = memoryCache.get(sysKeyIntObj);
int size = sysKeyMemCache.size();
Logger.msg(6, "CSM.clearCache() - "+size+" objects to remove.");
}
@@ -335,7 +341,7 @@ public class ClusterStorageManager { synchronized(memoryCache) {
for (Integer sysKey : memoryCache.keySet()) {
Logger.msg(logLevel, "Cached Objects of Entity "+sysKey);
- SoftCache<?, ?> sysKeyMemCache = memoryCache.get(sysKey);
+ NonStrongRefCache<?, ?> sysKeyMemCache = memoryCache.get(sysKey);
try {
synchronized(sysKeyMemCache) {
for (Object name : sysKeyMemCache.keySet()) {
|
