Merge pull request #2957 from FOCONIS/detailed-evict-stats

ENH: add statistics trimmedByGC/LRU/TTL/Idle to ServerCacheStatistics?
This commit is contained in:
Rob Bygrave
2023-02-14 16:29:35 +13:00
committed by GitHub
2 changed files with 66 additions and 1 deletions
@@ -29,6 +29,11 @@ public class ServerCacheStatistics {
protected long evictCount;
protected long gcCount;
protected long idleCount;
protected long ttlCount;
protected long lruCount;
@Override
public String toString() {
//noinspection StringBufferReplaceableByString
@@ -43,6 +48,10 @@ public class ServerCacheStatistics {
sb.append(" remove:").append(removeCount);
sb.append(" clear:").append(clearCount);
sb.append(" evict:").append(evictCount);
sb.append(" gc:").append(gcCount);
sb.append(" idle:").append(idleCount);
sb.append(" ttl:").append(ttlCount);
sb.append(" lru:").append(lruCount);
return sb.toString();
}
@@ -191,4 +200,37 @@ public class ServerCacheStatistics {
return evictCount;
}
/**
* Set the count of entries removed by the garbage collection.
*/
public void setGcCount(long gcCount) {
this.gcCount = gcCount;
}
/**
* Return the count of entries removed by the garbage collection.
*/
public long getGcCount() {
return gcCount;
}
public void setIdleCount(long idleCount) {
this.idleCount = idleCount;
}
public long getIdleCount() {
return idleCount;
}
public void setTtlCount(long ttlCount) {
this.ttlCount = ttlCount;
}
public long getTtlCount() {
return ttlCount;
}
public void setLruCount(long lruCount) {
this.lruCount = lruCount;
}
}
@@ -44,7 +44,10 @@ public class DefaultServerCache implements ServerCache {
protected final CountMetric removeCount;
protected final CountMetric clearCount;
protected final CountMetric evictCount;
protected final CountMetric gcCount;
protected final CountMetric idleCount;
protected final CountMetric ttlCount;
protected final CountMetric lruCount;
protected final String name;
protected final String shortName;
protected final int maxSize;
@@ -55,6 +58,7 @@ public class DefaultServerCache implements ServerCache {
protected final ReentrantLock lock = new ReentrantLock();
protected final AtomicLong mutationCounter = new AtomicLong();
public DefaultServerCache(DefaultServerCacheConfig config) {
this.name = config.getName();
this.shortName = config.getShortName();
@@ -73,6 +77,11 @@ public class DefaultServerCache implements ServerCache {
this.removeCount = factory.createCountMetric(prefix + shortName + ".remove");
this.clearCount = factory.createCountMetric(prefix + shortName + ".clear");
this.evictCount = factory.createCountMetric(prefix + shortName + ".evict");
this.gcCount = factory.createCountMetric(prefix + shortName + ".gc");
this.idleCount = factory.createCountMetric(prefix + shortName + ".idle");
this.ttlCount = factory.createCountMetric(prefix + shortName + ".ttl");
this.lruCount = factory.createCountMetric(prefix + shortName + ".lru");
}
public void periodicTrim(BackgroundExecutor executor) {
@@ -90,6 +99,10 @@ public class DefaultServerCache implements ServerCache {
removeCount.visit(visitor);
clearCount.visit(visitor);
evictCount.visit(visitor);
gcCount.visit(visitor);
idleCount.visit(visitor);
ttlCount.visit(visitor);
lruCount.visit(visitor);
}
@Override
@@ -104,6 +117,10 @@ public class DefaultServerCache implements ServerCache {
cacheStats.setRemoveCount(removeCount.get(reset));
cacheStats.setClearCount(clearCount.get(reset));
cacheStats.setEvictCount(evictCount.get(reset));
cacheStats.setGcCount(gcCount.get(reset));
cacheStats.setIdleCount(idleCount.get(reset));
cacheStats.setTtlCount(ttlCount.get(reset));
cacheStats.setLruCount(lruCount.get(reset));
return cacheStats;
}
@@ -289,6 +306,12 @@ public class DefaultServerCache implements ServerCache {
evictCount.add(trimmedByGC);
evictCount.add(trimmedByTTL);
evictCount.add(trimmedByLRU);
gcCount.add(trimmedByGC);
idleCount.add(trimmedByIdle);
ttlCount.add(trimmedByTTL);
lruCount.add(trimmedByLRU);
if (logger.isLoggable(TRACE)) {
long exeMicros = TimeUnit.MICROSECONDS.convert(System.nanoTime() - startNanos, TimeUnit.NANOSECONDS);
logger.log(TRACE, "Executed trim of cache {0} in [{1}]millis idle[{2}] timeToLive[{3}] accessTime[{4}] gc[{5}]",