jtaylor 2002/07/22 10:35:13
Modified: src/java/org/apache/jcs/admin/servlet JCSAdminServlet.java
JCSAdminServletDefault.vm
src/java/org/apache/jcs/engine/control CompositeCache.java
Log:
Added more hit/miss tracking to CompositeCache, and made those counts available
via the admin servlet (perhaps JMX someday).
Also, removed DCL from dispose, and tried to comment what is going on there
(still not entirely sure =)
Revision Changes Path
1.4 +11 -25
jakarta-turbine-jcs/src/java/org/apache/jcs/admin/servlet/JCSAdminServlet.java
Index: JCSAdminServlet.java
===================================================================
RCS file:
/home/cvs/jakarta-turbine-jcs/src/java/org/apache/jcs/admin/servlet/JCSAdminServlet.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- JCSAdminServlet.java 6 Jun 2002 05:35:02 -0000 1.3
+++ JCSAdminServlet.java 22 Jul 2002 17:35:12 -0000 1.4
@@ -176,10 +176,8 @@
regionInfo = new CacheRegionInfo();
- regionInfo.name = cache.getCacheName();
- regionInfo.itemCount = cache.getSize();
+ regionInfo.cache = cache;
regionInfo.byteCount = getByteCount( cache );
- regionInfo.status = statusAsString( cache );
cacheInfo.add( regionInfo );
}
@@ -210,16 +208,6 @@
return counter.getCount() - 4;
}
- private String statusAsString( ICache cache )
- {
- int status = cache.getStatus();
-
- return ( status == CacheConstants.STATUS_ALIVE ? "ALIVE"
- : status == CacheConstants.STATUS_DISPOSED ? "DISPOSED"
- : status == CacheConstants.STATUS_ERROR ? "ERROR"
- : "UNKNOWN" );
- }
-
private void clearAllRegions() throws IOException
{
String[] names = cacheHub.getCacheNames();
@@ -243,19 +231,12 @@
/** Stores info on a cache region for the template */
public class CacheRegionInfo
{
- String name = null;
- long itemCount = 0;
+ CompositeCache cache = null;
long byteCount = 0;
- String status = null;
- public String getName()
+ public CompositeCache getCache()
{
- return name;
- }
-
- public long getItemCount()
- {
- return itemCount;
+ return cache;
}
public long getByteCount()
@@ -265,7 +246,12 @@
public String getStatus()
{
- return status;
+ int status = cache.getStatus();
+
+ return ( status == CacheConstants.STATUS_ALIVE ? "ALIVE"
+ : status == CacheConstants.STATUS_DISPOSED ? "DISPOSED"
+ : status == CacheConstants.STATUS_ERROR ? "ERROR"
+ : "UNKNOWN" );
}
}
1.2 +12 -4
jakarta-turbine-jcs/src/java/org/apache/jcs/admin/servlet/JCSAdminServletDefault.vm
Index: JCSAdminServletDefault.vm
===================================================================
RCS file:
/home/cvs/jakarta-turbine-jcs/src/java/org/apache/jcs/admin/servlet/JCSAdminServletDefault.vm,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- JCSAdminServletDefault.vm 20 May 2002 17:05:23 -0000 1.1
+++ JCSAdminServletDefault.vm 22 Jul 2002 17:35:12 -0000 1.2
@@ -18,14 +18,22 @@
<th> Items </th>
<th> Bytes </th>
<th> Status </th>
+ <th> Memory Hits </th>
+ <th> Aux Hits </th>
+ <th> Not Found Misses </th>
+ <th> Expired Misses </th>
</tr>
#foreach ( $record in $cacheInfoRecords )
<tr>
- <td> $record.Name </td>
- <td> $record.ItemCount </td>
- <td> $record.ByteCount </td>
- <td> $record.Status </td>
+ <td> $record.cache.cacheName </td>
+ <td> $record.cache.size </td>
+ <td> $record.byteCount </td>
+ <td> $record.status </td>
+ <td> $record.cache.hitCountRam </td>
+ <td> $record.cache.hitCountAux </td>
+ <td> $record.cache.missCountNotFound </td>
+ <td> $record.cache.missCountExpired </td>
<td>
<a href="?action=detail&cacheName=${record.Name}"> Detail </a>
| <a href="?action=clearRegion&cacheName=${record.Name}"> Remove
all </a>
1.4 +165 -87
jakarta-turbine-jcs/src/java/org/apache/jcs/engine/control/CompositeCache.java
Index: CompositeCache.java
===================================================================
RCS file:
/home/cvs/jakarta-turbine-jcs/src/java/org/apache/jcs/engine/control/CompositeCache.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- CompositeCache.java 6 Jun 2002 05:35:02 -0000 1.3
+++ CompositeCache.java 22 Jul 2002 17:35:13 -0000 1.4
@@ -98,8 +98,6 @@
// Auxiliary caches.
private AuxiliaryCache[] auxCaches;
- // track hit counts for each
- private int[] auxHit;
private boolean alive = true;
@@ -122,12 +120,21 @@
public IElementEventQueue elementEventQ;
// Statistics
- // FIXME: Provide accessors for these for instrumentation
- private static int numInstances;
+ /** Memory cache hit count */
+ private int hitCountRam;
- private int ramHit;
- private int miss;
+ /** Auxiliary cache hit count (number of times found in ANY auxiliary) */
+ private int hitCountAux;
+
+ /** Auxiliary hit counts broken down by auxiliary */
+ private int[] auxHitCountByIndex;
+
+ /** Count of misses where element was not found */
+ private int missCountNotFound = 0;
+
+ /** Count of misses where element was expired */
+ private int missCountExpired = 0;
/**
* The cache hub can only have one memory cache. This could be made more
@@ -149,15 +156,13 @@
ICompositeCacheAttributes cattr,
IElementAttributes attr )
{
- numInstances++;
-
this.cacheName = cacheName;
this.auxCaches = auxCaches;
if ( auxCaches != null )
{
- this.auxHit = new int[auxCaches.length];
+ this.auxHitCountByIndex = new int[auxCaches.length];
}
this.attr = attr;
@@ -455,7 +460,35 @@
element = memCache.get( key );
- if ( element == null )
+ if ( element != null )
+ {
+ // Found in memory cache
+
+ if ( isExpired( element ) )
+ {
+ if ( log.isDebugEnabled() )
+ {
+ log.debug( cacheName +
+ " - Memory cache hit, but element expired" );
+ }
+
+ missCountExpired++;
+
+ remove( element );
+ }
+ else
+ {
+ if ( log.isDebugEnabled() )
+ {
+ log.debug( cacheName + " - Memory cache hit" );
+ }
+
+ // Update counters
+
+ hitCountRam++;
+ }
+ }
+ else
{
// Item not found in memory. If local invocation look in aux
// caches, even if not local look in disk auxiliaries
@@ -495,29 +528,44 @@
if ( element != null )
{
- log.debug(
- cacheName + " - Aux cache[" + i + "] hit" );
// Item found in one of the auxiliary caches.
- auxHit[i]++;
- // Spool the item back into memory
- memCache.update( element );
+ if ( isExpired( element ) )
+ {
+ if ( log.isDebugEnabled() )
+ {
+ log.debug( cacheName + " - Aux cache[" + i
+ + "] hit, but element expired" );
+ }
+
+ missCountExpired++;
+
+ remove( element );
+ }
+ else
+ {
+ if ( log.isDebugEnabled() )
+ {
+ log.debug( cacheName +
+ " - Aux cache[" + i + "] hit" );
+ }
+
+ // Update counters
+
+ hitCountAux++;
+ auxHitCountByIndex[ i ]++;
+
+ // Spool the item back into memory
+
+ memCache.update( element );
+ }
break;
}
}
}
}
- else
- {
- ramHit++;
-
- if ( log.isDebugEnabled() )
- {
- log.debug( cacheName + " - Memory cache hit" );
- }
- }
}
catch ( Exception e )
@@ -527,7 +575,7 @@
if ( element == null )
{
- miss++;
+ missCountNotFound++;
if ( log.isDebugEnabled() )
{
@@ -537,8 +585,11 @@
return null;
}
- // If an element was found, we still need to deal with expiration.
+ return element;
+ }
+ private boolean isExpired( ICacheElement element )
+ {
try
{
IElementAttributes attributes = element.getElementAttributes();
@@ -560,9 +611,7 @@
log.debug( "Exceeded maxLife: " + element.getKey() );
}
- remove( key );
-
- return null;
+ return true;
}
else
{
@@ -580,21 +629,19 @@
log.info( "Exceeded maxIdle: " + element.getKey() );
}
- remove( key );
-
- return null;
+ return true;
}
}
}
-
}
catch ( Exception e )
{
- log.error( "Error determining expiration period", e );
- return null;
+ log.error( "Error determining expiration period, expiring", e );
+
+ return true;
}
- return element;
+ return false;
}
/**
@@ -760,72 +807,81 @@
*
*@param fromRemote
*/
- protected void dispose( boolean fromRemote )
+ protected synchronized void dispose( boolean fromRemote )
{
- if ( !alive )
+ // If already disposed, return immediately
+
+ if ( ! alive )
{
return;
}
- synchronized ( this )
+
+ alive = false;
+
+ // Dispose of each auxilliary cache, Remote auxilliaries will be
+ // skipped if 'fromRemote' is true.
+
+ for ( int i = 0; i < auxCaches.length; i++ )
{
- if ( !alive )
+ try
{
- return;
- }
- alive = false;
+ ICache aux = auxCaches[i];
- for ( int i = 0; i < auxCaches.length; i++ )
- {
- try
- {
- ICache aux = auxCaches[i];
+ // Skip this auxilliary if:
+ // - The auxilliary is null
+ // - The auxilliary is not alive
+ // - The auxilliary is remote and the invocation was remote
- if ( aux == null || fromRemote && aux.getCacheType() ==
REMOTE_CACHE )
- {
- continue;
- }
- if ( aux.getStatus() == CacheConstants.STATUS_ALIVE )
- {
+ if ( aux == null
+ || aux.getStatus() == CacheConstants.STATUS_ALIVE
+ || fromRemote && aux.getCacheType() == REMOTE_CACHE )
+ {
+ continue;
+ }
- if ( log.isDebugEnabled() )
- {
- log.debug( "size = " + memCache.getSize() );
- }
+ // If the auxilliary is not a lateral, or the cache attributes
+ // have 'getUseLateral' set, all the elements currently in
+ // memory are written to the lateral before disposing
- if ( !( aux.getCacheType() == ICacheType.LATERAL_CACHE &&
!this.cacheAttr.getUseLateral() ) )
- {
+ if ( aux.getCacheType() != ICacheType.LATERAL_CACHE
+ || this.cacheAttr.getUseLateral() )
+ {
+ Iterator itr = memCache.getIterator();
- Iterator itr = memCache.getIterator();
+ while ( itr.hasNext() )
+ {
+ Map.Entry entry = ( Map.Entry ) itr.next();
- while ( itr.hasNext() )
+ ICacheElement ce = (ICacheElement) entry.getValue();
+ try
+ {
+ if ( aux.getCacheType() == ICacheType.LATERAL_CACHE
+ && !ce.getElementAttributes().getIsLateral() )
{
- Map.Entry entry = ( Map.Entry ) itr.next();
-
- ICacheElement ce = (ICacheElement) entry.getValue();
- try
- {
- if ( aux.getCacheType() ==
ICacheType.LATERAL_CACHE && !ce.getElementAttributes().getIsLateral() )
- {
- continue;
- }
- aux.update( ce );
- }
- catch ( Exception e )
- {
- log.error( e );
- }
+ continue;
}
+ aux.update( ce );
}
- if ( aux.getCacheType() == ICache.DISK_CACHE )
+ catch ( Exception e )
{
- aux.dispose();
+ log.error( e );
}
}
}
- catch ( IOException ex )
+
+ // Only call the dispose method for disk auxilliaries
+
+ // FIXME: Why not always call it?
+
+ if ( aux.getCacheType() == ICache.DISK_CACHE )
{
- log.error( "Failure disposing of aux", ex );
+ aux.dispose();
}
+
+ }
+ catch ( IOException ex )
+ {
+ log.error( "Failure disposing of aux", ex );
}
}
@@ -1040,13 +1096,35 @@
}
}
- /**
- * Access to the memory cache for instrumentation.
- *
- *@return The memoryCache value
- */
+ // ---------------------------------------------------- For Instrumentation
+
+ /** Access to the memory cache for instrumentation. */
public MemoryCache getMemoryCache()
{
return memCache;
+ }
+
+ /** Number of times a requested item was found in the memory cache */
+ public int getHitCountRam()
+ {
+ return hitCountRam;
+ }
+
+ /** Number of times a requested item was found in and auxiliary cache */
+ public int getHitCountAux()
+ {
+ return hitCountAux;
+ }
+
+ /** Number of times a requested element was not found */
+ public int getMissCountNotFound()
+ {
+ return missCountNotFound;
+ }
+
+ /** Number of times a requested element was found but was expired */
+ public int getMissCountExpired()
+ {
+ return missCountExpired;
}
}
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>