@Override public long getEvictionCount() { return lruCacheStats.getEvictionCount() + bucketCacheStats.getEvictionCount(); }
public double evictedPerEviction() { double evictionCount = getEvictionCount(); if (evictionCount == 0) { return 0; } return getEvictedCount() / evictionCount; }
private void __jamon_innerUnit__evictions_tmpl(final java.io.Writer jamonWriter, final BlockCache bc) throws java.io.IOException { // 171, 1 AgeSnapshot ageAtEvictionSnapshot = bc.getStats().getAgeAtEvictionSnapshot(); // Only show if non-zero mean and stddev as is the case in combinedblockcache // 175, 5 jamonWriter.write("<tr>\n <td>Evicted</td>\n <td>"); // 177, 13 org.jamon.escaping.Escaping.HTML.write(org.jamon.emit.StandardEmitter.valueOf(String.format("%,d", bc.getStats().getEvictedCount())), jamonWriter); // 177, 72 jamonWriter.write("</td>\n <td>The total number of blocks evicted</td>\n </tr>\n <tr>\n <td>Evictions</td>\n <td>"); // 182, 13 org.jamon.escaping.Escaping.HTML.write(org.jamon.emit.StandardEmitter.valueOf(String.format("%,d", bc.getStats().getEvictionCount())), jamonWriter); // 182, 73 jamonWriter.write("</td>\n <td>The total number of times an eviction has occurred</td>\n </tr>\n <tr>\n <td>Mean</td>\n <td>"); // 187, 13 org.jamon.escaping.Escaping.HTML.write(org.jamon.emit.StandardEmitter.valueOf(String.format("%,d", (long)ageAtEvictionSnapshot.getMean())), jamonWriter); // 187, 78 jamonWriter.write("</td>\n <td>Mean age of Blocks at eviction time (seconds)</td>\n </tr>\n"); }
@Override public String toString() { AgeSnapshot snapshot = getAgeAtEvictionSnapshot(); return "hitCount=" + getHitCount() + ", hitCachingCount=" + getHitCachingCount() + ", missCount=" + getMissCount() + ", missCachingCount=" + getMissCachingCount() + ", evictionCount=" + getEvictionCount() + ", evictedBlockCount=" + getEvictedCount() + ", primaryMissCount=" + getPrimaryMissCount() + ", primaryHitCount=" + getPrimaryHitCount() + ", evictedAgeMean=" + snapshot.getMean(); }
public void logStats() { // Log size long totalSize = heapSize(); long freeSize = maxSize - totalSize; LruBlockCache.LOG.info("totalSize=" + StringUtils.byteDesc(totalSize) + ", " + "freeSize=" + StringUtils.byteDesc(freeSize) + ", " + "max=" + StringUtils.byteDesc(this.maxSize) + ", " + "blockCount=" + getBlockCount() + ", " + "accesses=" + stats.getRequestCount() + ", " + "hits=" + stats.getHitCount() + ", " + "hitRatio=" + (stats.getHitCount() == 0 ? "0" : (StringUtils.formatPercent(stats.getHitRatio(), 2)+ ", ")) + ", " + "cachingAccesses=" + stats.getRequestCachingCount() + ", " + "cachingHits=" + stats.getHitCachingCount() + ", " + "cachingHitsRatio=" + (stats.getHitCachingCount() == 0 ? "0,": (StringUtils.formatPercent(stats.getHitCachingRatio(), 2) + ", ")) + "evictions=" + stats.getEvictionCount() + ", " + "evicted=" + stats.getEvictedCount() + ", " + "evictedPerRun=" + stats.evictedPerEviction()); }
while(cache.getStats().getEvictionCount() == 0) { Thread.sleep(200); assertTrue("Eviction never happened.", n++ < 20); long evictionCount = cache.getStats().getEvictionCount(); assertTrue(evictionCount >= 1); System.out.println("Background Evictions run: " + evictionCount);
assertEquals(1, cache.getStats().getEvictionCount()); assertEquals(4, cache.getStats().getEvictionCount()); assertEquals(16, cache.getStats().getEvictedCount());
assertEquals(0, cache.getStats().getEvictionCount()); assertEquals(1, cache.getStats().getEvictionCount());
assertEquals(0, cache.getStats().getEvictionCount()); assertEquals(1, cache.getStats().getEvictionCount()); assertEquals(1, cache.getStats().getEvictedCount()); assertEquals(2, cache.getStats().getEvictionCount()); assertEquals(2, cache.getStats().getEvictedCount()); assertEquals(3, cache.getStats().getEvictionCount()); assertEquals(3, cache.getStats().getEvictedCount()); assertEquals(4, cache.getStats().getEvictionCount()); assertEquals(6, cache.getStats().getEvictedCount()); assertEquals(5, cache.getStats().getEvictionCount()); assertEquals(9, cache.getStats().getEvictedCount()); assertEquals(6, cache.getStats().getEvictionCount()); assertEquals(12, cache.getStats().getEvictedCount());
expectedCacheSize += singleBlocks[4].cacheBlockHeapSize(); assertEquals(0, cache.getStats().getEvictionCount()); assertEquals(1, cache.getStats().getEvictionCount()); assertEquals(1, cache.getStats().getEvictedCount()); assertEquals(2, cache.getStats().getEvictionCount()); assertEquals(2, cache.getStats().getEvictedCount()); cache.cacheBlock(memoryBlocks[5].cacheKey, memoryBlocks[5], true); assertEquals(6, cache.getStats().getEvictionCount()); assertEquals(6, cache.getStats().getEvictedCount()); cache.cacheBlock(memoryBlocks[8].cacheKey, memoryBlocks[8], true); assertEquals(9, cache.getStats().getEvictionCount()); assertEquals(9, cache.getStats().getEvictedCount()); assertEquals(10, cache.getStats().getEvictionCount()); assertEquals(10, cache.getStats().getEvictedCount()); assertEquals(11, cache.getStats().getEvictionCount()); assertEquals(11, cache.getStats().getEvictedCount());
@Test public void testCacheEvictionSimple() throws Exception { long maxSize = 100000; long blockSize = calculateBlockSizeDefault(maxSize, 10); LruBlockCache cache = new LruBlockCache(maxSize,blockSize,false); CachedItem [] blocks = generateFixedBlocks(10, blockSize, "block"); long expectedCacheSize = cache.heapSize(); // Add all the blocks for (CachedItem block : blocks) { cache.cacheBlock(block.cacheKey, block); expectedCacheSize += block.cacheBlockHeapSize(); } // A single eviction run should have occurred assertEquals(1, cache.getStats().getEvictionCount()); // Our expected size overruns acceptable limit assertTrue(expectedCacheSize > (maxSize * LruBlockCache.DEFAULT_ACCEPTABLE_FACTOR)); // But the cache did not grow beyond max assertTrue(cache.heapSize() < maxSize); // And is still below the acceptable limit assertTrue(cache.heapSize() < (maxSize * LruBlockCache.DEFAULT_ACCEPTABLE_FACTOR)); // All blocks except block 0 should be in the cache assertTrue(cache.getBlock(blocks[0].cacheKey, true, false, true) == null); for(int i=1;i<blocks.length;i++) { assertEquals(cache.getBlock(blocks[i].cacheKey, true, false, true), blocks[i]); } }
assertEquals(0, cache.getStats().getEvictionCount()); Thread t = new LruBlockCache.StatisticsThread(cache); t.start();
assertEquals(1, cache.getStats().getEvictionCount());
/** * Get the number of eviction runs that have occurred */ public long getEvictionCount() { return this.stats.getEvictionCount(); }
@Override public long getEvictionCount() { return lruCacheStats.getEvictionCount() + bucketCacheStats.getEvictionCount(); }
public double evictedPerEviction() { return ((float)getEvictedCount()/(float)getEvictionCount()); }
public double evictedPerEviction() { return ((float)getEvictedCount()/(float)getEvictionCount()); }
@Override public String toString() { AgeSnapshot snapshot = getAgeAtEvictionSnapshot(); return "hitCount=" + getHitCount() + ", hitCachingCount=" + getHitCachingCount() + ", missCount=" + getMissCount() + ", missCachingCount=" + getMissCachingCount() + ", evictionCount=" + getEvictionCount() + ", evictedBlockCount=" + getEvictedCount() + ", primaryMissCount=" + getPrimaryMissCount() + ", primaryHitCount=" + getPrimaryHitCount() + ", evictedAgeMean=" + snapshot.getMean() + ", evictedAgeStdDev=" + snapshot.getStdDev(); }
public void logStats() { // Log size long totalSize = heapSize(); long freeSize = maxSize - totalSize; LruBlockCache.LOG.info("totalSize=" + StringUtils.byteDesc(totalSize) + ", " + "freeSize=" + StringUtils.byteDesc(freeSize) + ", " + "max=" + StringUtils.byteDesc(this.maxSize) + ", " + "blockCount=" + getBlockCount() + ", " + "accesses=" + stats.getRequestCount() + ", " + "hits=" + stats.getHitCount() + ", " + "hitRatio=" + (stats.getHitCount() == 0 ? "0" : (StringUtils.formatPercent(stats.getHitRatio(), 2)+ ", ")) + ", " + "cachingAccesses=" + stats.getRequestCachingCount() + ", " + "cachingHits=" + stats.getHitCachingCount() + ", " + "cachingHitsRatio=" + (stats.getHitCachingCount() == 0 ? "0,": (StringUtils.formatPercent(stats.getHitCachingRatio(), 2) + ", ")) + "evictions=" + stats.getEvictionCount() + ", " + "evicted=" + stats.getEvictedCount() + ", " + "evictedPerRun=" + stats.evictedPerEviction()); }
@Test public void testCacheEvictionSimple() throws Exception { long maxSize = 100000; long blockSize = calculateBlockSizeDefault(maxSize, 10); LruBlockCache cache = new LruBlockCache(maxSize,blockSize,false); CachedItem [] blocks = generateFixedBlocks(10, blockSize, "block"); long expectedCacheSize = cache.heapSize(); // Add all the blocks for (CachedItem block : blocks) { cache.cacheBlock(block.cacheKey, block); expectedCacheSize += block.cacheBlockHeapSize(); } // A single eviction run should have occurred assertEquals(1, cache.getStats().getEvictionCount()); // Our expected size overruns acceptable limit assertTrue(expectedCacheSize > (maxSize * LruBlockCache.DEFAULT_ACCEPTABLE_FACTOR)); // But the cache did not grow beyond max assertTrue(cache.heapSize() < maxSize); // And is still below the acceptable limit assertTrue(cache.heapSize() < (maxSize * LruBlockCache.DEFAULT_ACCEPTABLE_FACTOR)); // All blocks except block 0 should be in the cache assertTrue(cache.getBlock(blocks[0].cacheKey, true, false, true) == null); for(int i=1;i<blocks.length;i++) { assertEquals(cache.getBlock(blocks[i].cacheKey, true, false, true), blocks[i]); } }