asmuts 02/02/18 20:46:54
Modified: src/java/org/apache/stratum/jcs/access TestCacheAccess.java
src/java/org/apache/stratum/jcs/engine/memory/shrinking
ShrinkingMemoryCache.java ShrinkerThread.java
src/java/org/apache/stratum/jcs/engine/memory/mru
MRUMemoryCache.java
src/java/org/apache/stratum/jcs/engine/memory/lru
LRUMemoryCache.java
src/conf cache.ccf
Log:
made the memory shrinker usable by all memory caches. it needs work. right now it
runs in a fail fast mode and then tries again. it is designed to fail rather than
lock the map
Revision Changes Path
1.14 +3 -0
jakarta-turbine-stratum/src/java/org/apache/stratum/jcs/access/TestCacheAccess.java
Index: TestCacheAccess.java
===================================================================
RCS file:
/home/cvs/jakarta-turbine-stratum/src/java/org/apache/stratum/jcs/access/TestCacheAccess.java,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- TestCacheAccess.java 18 Feb 2002 17:14:22 -0000 1.13
+++ TestCacheAccess.java 19 Feb 2002 04:46:54 -0000 1.14
@@ -522,6 +522,9 @@
else
{
IElementAttributes attrp = new ElementAttributes();
+ //attrp.setIsEternal(false);
+ //attrp.setMaxLifeSeconds(30);
+
attrp.setIsLateral(true);
attrp.setIsRemote(true);
long n_start = System.currentTimeMillis();
1.3 +7 -2
jakarta-turbine-stratum/src/java/org/apache/stratum/jcs/engine/memory/shrinking/ShrinkingMemoryCache.java
Index: ShrinkingMemoryCache.java
===================================================================
RCS file:
/home/cvs/jakarta-turbine-stratum/src/java/org/apache/stratum/jcs/engine/memory/shrinking/ShrinkingMemoryCache.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- ShrinkingMemoryCache.java 18 Feb 2002 18:43:58 -0000 1.2
+++ ShrinkingMemoryCache.java 19 Feb 2002 04:46:54 -0000 1.3
@@ -152,6 +152,7 @@
{
MemoryElementDescriptor me = new MemoryElementDescriptor( ce );
+ ce.getElementAttributes().setLastAccessTimeNow();
map.put( ce.getKey(), me );
}
@@ -282,7 +283,7 @@
try
{
- //me.ce.setLastAccessTimeNow();
+ me.ce.getElementAttributes().setLastAccessTimeNow();
}
catch ( Exception e )
{
@@ -374,12 +375,16 @@
/**
* Description of the Method
*
- * Puts an item to the cache.
+ * Description of the Method Puts an item to the cache.
*
*/
public void waterfal( MemoryElementDescriptor me )
throws IOException
{
+ if ( log.isDebugEnabled() )
+ {
+ log.debug( "Spooling item to disk -- " + me.ce.getKey() );
+ }
this.hub.spoolToDisk( me.ce );
}
1.3 +14 -5
jakarta-turbine-stratum/src/java/org/apache/stratum/jcs/engine/memory/shrinking/ShrinkerThread.java
Index: ShrinkerThread.java
===================================================================
RCS file:
/home/cvs/jakarta-turbine-stratum/src/java/org/apache/stratum/jcs/engine/memory/shrinking/ShrinkerThread.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- ShrinkerThread.java 18 Feb 2002 18:43:58 -0000 1.2
+++ ShrinkerThread.java 19 Feb 2002 04:46:54 -0000 1.3
@@ -155,27 +155,35 @@
long deadAt = me.ce.getElementAttributes().getLastAccessTime()
+ ( cache.getCacheAttributes().getMaxMemoryIdleTimeSeconds() * 1000 );
if ( ( deadAt - now ) < 0 )
{
- if ( log.isDebugEnabled() )
+ if ( log.isInfoEnabled() )
{
- log.debug( "Pushing item to disk -- " + me.ce.getKey()
);
+ log.info( "Exceeded memory idle time, Pushing item to
disk -- " + me.ce.getKey() + " over by = " + String.valueOf(deadAt - now) + " ms.");
}
itr.remove();
cache.waterfal( me );
}
- }
+ } else
if ( !me.ce.getElementAttributes().getIsEternal() )
{
// Exceeded maxLifeSeconds
if ( ( me.ce.getElementAttributes().getMaxLifeSeconds() != -1 )
&& ( now - me.ce.getElementAttributes().getCreateTime() ) > (
me.ce.getElementAttributes().getMaxLifeSeconds() * 1000 ) )
{
+ if ( log.isInfoEnabled() )
+ {
+ log.info( "Exceeded maxLifeSeconds -- " +
me.ce.getKey() );
+ }
itr.remove();
//cache.remove( me.ce.getKey() );
- }
+ } else
// Exceeded maxIdleTime, removal
- if ( ( me.ce.getElementAttributes().getIdleTime() * 1000 != -1
) && ( now - me.ce.getElementAttributes().getLastAccessTime() ) > (
me.ce.getElementAttributes().getIdleTime() * 1000 ) )
+ if ( ( me.ce.getElementAttributes().getIdleTime() != -1 ) && (
now - me.ce.getElementAttributes().getLastAccessTime() ) > (
me.ce.getElementAttributes().getIdleTime() * 1000 ) )
{
+ if ( log.isInfoEnabled() )
+ {
+ log.info( "Exceeded maxIdleTime [
me.ce.getElementAttributes().getIdleTime() = " +
me.ce.getElementAttributes().getIdleTime() + " ]-- " + me.ce.getKey() );
+ }
itr.remove();
//cache.remove( me.ce.getKey() );
}
@@ -185,6 +193,7 @@
}
catch ( Throwable t )
{
+ log.info( "Expected trouble in shrink cycle", t );
// keep going?
// concurrent modifications will be a serious problem here
// there is no good way yo interate througha map without locking it
1.6 +33 -5
jakarta-turbine-stratum/src/java/org/apache/stratum/jcs/engine/memory/mru/MRUMemoryCache.java
Index: MRUMemoryCache.java
===================================================================
RCS file:
/home/cvs/jakarta-turbine-stratum/src/java/org/apache/stratum/jcs/engine/memory/mru/MRUMemoryCache.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- MRUMemoryCache.java 18 Feb 2002 18:43:58 -0000 1.5
+++ MRUMemoryCache.java 19 Feb 2002 04:46:54 -0000 1.6
@@ -22,6 +22,7 @@
import org.apache.stratum.jcs.engine.behavior.ICacheType;
import org.apache.stratum.jcs.engine.behavior.ICompositeCacheAttributes;
+import org.apache.stratum.jcs.engine.memory.shrinking.ShrinkerThread;
import org.apache.stratum.jcs.engine.memory.MemoryElementDescriptor;
import org.apache.stratum.jcs.engine.memory.behavior.IMemoryCache;
@@ -81,7 +82,12 @@
private int status = this.STATUS_ERROR;
// make configurable
- private int chunkSize = 5;
+ private int chunkSize = 2;
+
+ /**
+ * The background memory shrinker
+ */
+ private ShrinkerThread shrinker;
// for reflection
@@ -122,6 +128,23 @@
this.cattr = cattr;
this.hub = hub;
status = this.STATUS_ALIVE;
+
+ if ( cattr.getUseMemoryShrinker() )
+ {
+ if ( shrinker == null )
+ {
+ synchronized ( MRUMemoryCache.class )
+ {
+ if ( shrinker == null )
+ {
+ shrinker = new ShrinkerThread( this );
+ shrinker.setPriority( shrinker.MIN_PRIORITY );
+ shrinker.start();
+ }
+ }
+ }
+ }
+
}
@@ -158,6 +181,7 @@
{
Serializable key = ce.getKey();
+ ce.getElementAttributes().setLastAccessTimeNow();
// need a more fine grained locking here
boolean replace = false;
@@ -320,7 +344,7 @@
else
{
found = true;
-
+ ce.getElementAttributes().setLastAccessTimeNow();
//ramHit++;
if ( log.isDebugEnabled() )
{
@@ -509,13 +533,17 @@
}
- /** Puts an item to the cache. */
+ /**
+ * Puts an item to the cache.
+ *
+ * @param me
+ * @exception IOException
+ */
public void waterfal( MemoryElementDescriptor me )
throws IOException
{
- this.hub.spoolToDisk(me.ce);
+ this.hub.spoolToDisk( me.ce );
}
-
/**
1.12 +34 -3
jakarta-turbine-stratum/src/java/org/apache/stratum/jcs/engine/memory/lru/LRUMemoryCache.java
Index: LRUMemoryCache.java
===================================================================
RCS file:
/home/cvs/jakarta-turbine-stratum/src/java/org/apache/stratum/jcs/engine/memory/lru/LRUMemoryCache.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- LRUMemoryCache.java 18 Feb 2002 18:43:59 -0000 1.11
+++ LRUMemoryCache.java 19 Feb 2002 04:46:54 -0000 1.12
@@ -20,6 +20,8 @@
import org.apache.stratum.jcs.engine.behavior.ICacheType;
import org.apache.stratum.jcs.engine.behavior.ICompositeCacheAttributes;
+
+import org.apache.stratum.jcs.engine.memory.shrinking.ShrinkerThread;
import org.apache.stratum.jcs.engine.memory.MemoryElementDescriptor;
import org.apache.stratum.jcs.engine.memory.behavior.IMemoryCache;
@@ -78,7 +80,12 @@
private int status = this.STATUS_ERROR;
// make configurable
- private int chunkSize = 5;
+ private int chunkSize = 2;
+
+ /**
+ * The background memory shrinker
+ */
+ private ShrinkerThread shrinker;
// for reflection
@@ -122,6 +129,23 @@
this.hub = hub;
status = this.STATUS_ALIVE;
log.info( "initialized LRUMemoryCache for " + cacheName );
+
+ if ( cattr.getUseMemoryShrinker() )
+ {
+ if ( shrinker == null )
+ {
+ synchronized ( LRUMemoryCache.class )
+ {
+ if ( shrinker == null )
+ {
+ shrinker = new ShrinkerThread( this );
+ shrinker.setPriority( shrinker.MIN_PRIORITY );
+ shrinker.start();
+ }
+ }
+ }
+ }
+
}
@@ -158,6 +182,7 @@
{
// asynchronisly create a MemoryElement
+ ce.getElementAttributes().setLastAccessTimeNow();
addFirst( ce );
MemoryElementDescriptor old = ( MemoryElementDescriptor ) map.put(
ce.getKey(), first );
@@ -339,6 +364,7 @@
try
{
+ ce.getElementAttributes().setLastAccessTimeNow();
makeFirst( me );
}
catch ( Exception e )
@@ -673,11 +699,16 @@
return;
}
- /** Puts an item to the cache. */
+ /**
+ * Puts an item to the cache.
+ *
+ * @param me
+ * @exception IOException
+ */
public void waterfal( MemoryElementDescriptor me )
throws IOException
{
- this.hub.spoolToDisk(me.ce);
+ this.hub.spoolToDisk( me.ce );
}
1.12 +10 -1 jakarta-turbine-stratum/src/conf/cache.ccf
Index: cache.ccf
===================================================================
RCS file: /home/cvs/jakarta-turbine-stratum/src/conf/cache.ccf,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- cache.ccf 18 Feb 2002 23:46:37 -0000 1.11
+++ cache.ccf 19 Feb 2002 04:46:54 -0000 1.12
@@ -5,6 +5,10 @@
jcs.default.cacheattributes=org.apache.stratum.jcs.engine.CompositeCacheAttributes
jcs.default.cacheattributes.MaxObjects=1000
jcs.default.cacheattributes.MemoryCacheName=org.apache.stratum.jcs.engine.memory.lru.LRUMemoryCache
+jcs.default.cacheattributes.cacheattributes.UseMemoryShrinker=true
+jcs.default.cacheattributes.cacheattributes.MaxMemoryIdleTimeSeconds=3600
+jcs.default.cacheattributes.cacheattributes.ShrinkerIntervalSeconds=60
+
# SYSTEM CACHE
# should be defined for the storage of group attribute list
@@ -21,15 +25,20 @@
jcs.region.testCache1.cacheattributes=org.apache.stratum.jcs.engine.CompositeCacheAttributes
jcs.region.testCache1.cacheattributes.MaxObjects=1000
jcs.region.testCache1.cacheattributes.MemoryCacheName=org.apache.stratum.jcs.engine.memory.lru.LRUMemoryCache
+jcs.region.testCache1.cacheattributes.UseMemoryShrinker=true
+jcs.region.testCache1.cacheattributes.MaxMemoryIdleTimeSeconds=3600
+jcs.region.testCache1.cacheattributes.ShrinkerIntervalSeconds=60
jcs.region.testCache2=DC,LTCP
jcs.region.testCache2.cacheattributes=org.apache.stratum.jcs.engine.CompositeCacheAttributes
jcs.region.testCache2.cacheattributes.MaxObjects=1000
jcs.region.testCache2.cacheattributes.MemoryCacheName=org.apache.stratum.jcs.engine.memory.lru.LRUMemoryCache
+jcs.region.testCache2.cacheattributes.UseMemoryShrinker=true
+jcs.region.testCache2.cacheattributes.MaxMemoryIdleTimeSeconds=3600
+jcs.region.testCache2.cacheattributes.ShrinkerIntervalSeconds=60
jcs.region.testCache3=DC
jcs.region.testCache3.cacheattributes=org.apache.stratum.jcs.engine.CompositeCacheAttributes
-jcs.region.testCache3.cacheattributes.MaxObjects=1000
jcs.region.testCache3.cacheattributes.MemoryCacheName=org.apache.stratum.jcs.engine.memory.shrinking.ShrinkingMemoryCache
jcs.region.testCache3.cacheattributes.UseMemoryShrinker=true
jcs.region.testCache3.cacheattributes.MaxMemoryIdleTimeSeconds=3600
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>