Author: rwatler
Date: Wed Sep 15 03:32:37 2010
New Revision: 997181
URL: http://svn.apache.org/viewvc?rev=997181&view=rev
Log:
DBPM Fragment Property List Thread Cache Improvements
----------------------------------------------------------------------
- convert Fragment Property List Thread Cache to a limited capacity LRU
cache of weak references to limit the number of lists and consequently
pages/folders that are held on the heap if large numbers of lists are
read/written by a single thread.
- add max size accessor to JetspeedCache to facilitate scaling of
Fragment Property List Thread Cache to match 1/10 of DBPM cache sizes
per thread max.
Modified:
portals/jetspeed-2/portal/trunk/components/jetspeed-cm/src/main/java/org/apache/jetspeed/cache/impl/EhCacheImpl.java
portals/jetspeed-2/portal/trunk/components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/page/PageSerializerImpl.java
portals/jetspeed-2/portal/trunk/components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/page/impl/DatabasePageManager.java
portals/jetspeed-2/portal/trunk/jetspeed-api/src/main/java/org/apache/jetspeed/cache/JetspeedCache.java
Modified:
portals/jetspeed-2/portal/trunk/components/jetspeed-cm/src/main/java/org/apache/jetspeed/cache/impl/EhCacheImpl.java
URL:
http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-cm/src/main/java/org/apache/jetspeed/cache/impl/EhCacheImpl.java?rev=997181&r1=997180&r2=997181&view=diff
==============================================================================
---
portals/jetspeed-2/portal/trunk/components/jetspeed-cm/src/main/java/org/apache/jetspeed/cache/impl/EhCacheImpl.java
(original)
+++
portals/jetspeed-2/portal/trunk/components/jetspeed-cm/src/main/java/org/apache/jetspeed/cache/impl/EhCacheImpl.java
Wed Sep 15 03:32:37 2010
@@ -202,6 +202,11 @@ public class EhCacheImpl implements Jets
return false;
}
+ public int getMaxSize()
+ {
+ return
ehcache.getCacheConfiguration().getMaxElementsInMemory()+ehcache.getCacheConfiguration().getMaxElementsOnDisk();
+ }
+
// ------------------------------------------------------
public Object clone() throws CloneNotSupportedException
Modified:
portals/jetspeed-2/portal/trunk/components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/page/PageSerializerImpl.java
URL:
http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/page/PageSerializerImpl.java?rev=997181&r1=997180&r2=997181&view=diff
==============================================================================
---
portals/jetspeed-2/portal/trunk/components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/page/PageSerializerImpl.java
(original)
+++
portals/jetspeed-2/portal/trunk/components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/page/PageSerializerImpl.java
Wed Sep 15 03:32:37 2010
@@ -216,6 +216,9 @@ public class PageSerializerImpl implemen
context.logger.info((importing?"Import":"Export")+" skipped:
"+context.folder+" not found.");
}
context.logger = null;
+ // cleanup page manager thread/request caches
+ src.cleanupRequestCache();
+ dest.cleanupRequestCache();
return context;
}
Modified:
portals/jetspeed-2/portal/trunk/components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/page/impl/DatabasePageManager.java
URL:
http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/page/impl/DatabasePageManager.java?rev=997181&r1=997180&r2=997181&view=diff
==============================================================================
---
portals/jetspeed-2/portal/trunk/components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/page/impl/DatabasePageManager.java
(original)
+++
portals/jetspeed-2/portal/trunk/components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/page/impl/DatabasePageManager.java
Wed Sep 15 03:32:37 2010
@@ -16,12 +16,14 @@
*/
package org.apache.jetspeed.page.impl;
+import java.lang.ref.WeakReference;
import java.security.AccessController;
import java.security.Principal;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
+import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -133,6 +135,8 @@ public class DatabasePageManager extends
{
private static Logger log =
LoggerFactory.getLogger(DatabasePageManager.class);
+ private static final int MIN_THREAD_CACHE_SIZE = 16;
+
private static ThreadLocal fragmentPropertyListsCache = new ThreadLocal();
private static Map modelClasses = new HashMap();
@@ -170,7 +174,9 @@ public class DatabasePageManager extends
}
private DelegatingPageManager delegator;
-
+
+ private int maxThreadCacheSize;
+
private PageManager pageManagerProxy;
public DatabasePageManager(String repositoryPath, IdGenerator generator,
boolean isPermissionsSecurity, boolean isConstraintsSecurity, JetspeedCache
oidCache, JetspeedCache pathCache,
@@ -178,6 +184,7 @@ public class DatabasePageManager extends
{
super(repositoryPath);
delegator = new DelegatingPageManager(generator,
isPermissionsSecurity, isConstraintsSecurity, modelClasses);
+ maxThreadCacheSize =
Math.max(Math.max(Math.max(oidCache.getMaxSize()/10,
propertiesCache.getMaxSize()/10), principalPropertiesCache.getMaxSize()/10),
MIN_THREAD_CACHE_SIZE);
DatabasePageManagerCache.cacheInit(oidCache, pathCache,
propertiesCache, propertiesPathCache, principalPropertiesCache,
principalPropertiesPathCache, this);
}
@@ -2696,7 +2703,8 @@ public class DatabasePageManager extends
Principal userPrincipal = ((subject != null) ?
SubjectHelper.getBestPrincipal(subject, User.class) : null);
String fragmentListKey = getFragmentPropertyListKey(fragmentKey,
userPrincipal);
Map threadLocalCache = (Map)fragmentPropertyListsCache.get();
- FragmentPropertyList list = ((threadLocalCache != null) ?
(FragmentPropertyList)threadLocalCache.get(fragmentListKey) : null);
+ WeakReference listReference = ((threadLocalCache != null) ?
(WeakReference)threadLocalCache.get(fragmentListKey) : null);
+ FragmentPropertyList list = ((listReference != null) ?
(FragmentPropertyList)listReference.get() : null);
// get and cache persistent list
if (list == null)
@@ -2864,13 +2872,25 @@ public class DatabasePageManager extends
}
}
- // save fragment property list in thread local cache
+ // save fragment property list in thread local cache utilizing
+ // weak references to ensure threads locals for pooled threads
+ // are cleaned up when cleanupRequestCache() is not invoked,
+ // (typically batch processes accessing the PageManager).
if (threadLocalCache == null)
{
- threadLocalCache = new HashMap();
+ // create bounded LRU cache per thread to limit footprint
+ // of long running or pooled threads, (typically batch
+ // processes accessing the PageManager).
+ threadLocalCache = new LinkedHashMap(MIN_THREAD_CACHE_SIZE,
0.75F, true)
+ {
+ protected boolean removeEldestEntry(Map.Entry eldest)
+ {
+ return (size() > maxThreadCacheSize);
+ }
+ };
fragmentPropertyListsCache.set(threadLocalCache);
}
- threadLocalCache.put(fragmentListKey, list);
+ threadLocalCache.put(fragmentListKey, new WeakReference(list));
}
return list;
}
@@ -3109,7 +3129,8 @@ public class DatabasePageManager extends
Principal userPrincipal = ((subject != null) ?
SubjectHelper.getBestPrincipal(subject, User.class) : null);
String fragmentListKey = getFragmentPropertyListKey(fragmentKey,
userPrincipal);
Map threadLocalCache = (Map)fragmentPropertyListsCache.get();
- FragmentPropertyList list = ((threadLocalCache != null) ?
(FragmentPropertyList)threadLocalCache.get(fragmentListKey) : null);
+ WeakReference listReference = ((threadLocalCache != null) ?
(WeakReference)threadLocalCache.get(fragmentListKey) : null);
+ FragmentPropertyList list = ((listReference != null) ?
(FragmentPropertyList)listReference.get() : null);
// remove cached persistent list
if (list != null)
Modified:
portals/jetspeed-2/portal/trunk/jetspeed-api/src/main/java/org/apache/jetspeed/cache/JetspeedCache.java
URL:
http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/jetspeed-api/src/main/java/org/apache/jetspeed/cache/JetspeedCache.java?rev=997181&r1=997180&r2=997181&view=diff
==============================================================================
---
portals/jetspeed-2/portal/trunk/jetspeed-api/src/main/java/org/apache/jetspeed/cache/JetspeedCache.java
(original)
+++
portals/jetspeed-2/portal/trunk/jetspeed-api/src/main/java/org/apache/jetspeed/cache/JetspeedCache.java
Wed Sep 15 03:32:37 2010
@@ -143,4 +143,11 @@ public interface JetspeedCache
* @return distributed flag
*/
boolean isDistributed();
+
+ /**
+ * get the maximum size of the cache
+ *
+ * @return the maximum size of the cache
+ */
+ int getMaxSize();
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]