public CacheStats stats() { return cache.stats(); }
/** * {@inheritDoc} */ @Override public CacheStats stats() { return new CacheStats(cache.stats(), bypassed); } }
private boolean updateCacheStats(boolean force) { final Cache<?, ?> cache = get(); if (cache == null) { return true; // GC'd } final long currentTimeNanos = ticker.read(); if (!force) { if (currentTimeNanos - lastStatsUpdateTime < UPDATE_INTERVAL_NANOS) { return false; // Not GC'd } } cacheStats = cache.stats(); estimatedSize = cache.estimatedSize(); // Write the volatile field last so that cacheStats and estimatedSize are visible // after reading the volatile field. lastStatsUpdateTime = currentTimeNanos; return false; // Not GC'd } }
@Override public CacheStats stats() { com.github.benmanes.caffeine.cache.stats.CacheStats stats = cache.stats(); return new CacheStats(stats.hitCount(), stats.missCount(), stats.loadSuccessCount(), stats.loadFailureCount(), stats.totalLoadTime(), stats.evictionCount()); }
@Override public org.apache.druid.client.cache.CacheStats getStats() { final CacheStats stats = cache.stats(); final long size = cache .policy().eviction() .map(eviction -> eviction.isWeighted() ? eviction.weightedSize() : OptionalLong.empty()) .orElse(OptionalLong.empty()).orElse(-1); return new org.apache.druid.client.cache.CacheStats( stats.hitCount(), stats.missCount(), cache.estimatedSize(), size, stats.evictionCount(), 0, stats.loadFailureCount() ); }
@CacheSpec @CheckNoWriter @CheckNoStats @Test(dataProvider = "caches") public void stats(Cache<Integer, Integer> cache, CacheContext context) { CacheStats stats = cache.stats() .plus(new CacheStats(1, 2, 3, 4, 5, 6, 7) .minus(new CacheStats(6, 5, 4, 3, 2, 1, 0))); assertThat(stats, is(new CacheStats(0, 0, 0, 1, 3, 5, 7))); assertThat(cache.policy().isRecordingStats(), is(context.isRecordingStats())); }
printStats(cache); assertThat(cache.stats().hitRate(), is(greaterThan(0.99d)));
@Override public void doMonitor(ServiceEmitter emitter) { final CacheStats oldStats = priorStats.get(); final CacheStats newStats = cache.stats(); final CacheStats deltaStats = newStats.minus(oldStats); final ServiceMetricEvent.Builder builder = ServiceMetricEvent.builder(); emitter.emit(builder.build("query/cache/caffeine/delta/requests", deltaStats.requestCount())); emitter.emit(builder.build("query/cache/caffeine/total/requests", newStats.requestCount())); emitter.emit(builder.build("query/cache/caffeine/delta/loadTime", deltaStats.totalLoadTime())); emitter.emit(builder.build("query/cache/caffeine/total/loadTime", newStats.totalLoadTime())); emitter.emit(builder.build("query/cache/caffeine/delta/evictionBytes", deltaStats.evictionWeight())); emitter.emit(builder.build("query/cache/caffeine/total/evictionBytes", newStats.evictionWeight())); if (!priorStats.compareAndSet(oldStats, newStats)) { // ISE for stack trace log.warn( new IllegalStateException("Multiple monitors"), "Multiple monitors on the same cache causing race conditions and unreliable stats reporting" ); } }
@Override public BlockCache.Stats getStats() { CacheStats stats = cache.stats(); return new BlockCache.Stats() { @Override public long hitCount() { return stats.hitCount(); } @Override public long requestCount() { return stats.requestCount(); } }; }
@Override public String toString() { StringBuilder sb = new StringBuilder(); long total = staticCacheHits + staticCacheMiss; if (total > 0) { sb.append(String.format("Static cache(size: %d) Hit rate: %.3f%n", staticCache.size(), 1.0 * (staticCacheHits) / (staticCacheHits + staticCacheMiss))); } sb.append(String.format("Dynamic cache hit rate: %.3f ", dynamicCache.stats().hitRate())); return sb.toString(); } }
private void logStats() { double maxMB = ((double) policy.getMaximum()) / ((double) (1024 * 1024)); double sizeMB = ((double) policy.weightedSize().getAsLong()) / ((double) (1024 * 1024)); double freeMB = maxMB - sizeMB; log.debug("Cache Size={}MB, Free={}MB, Max={}MB, Blocks={}", sizeMB, freeMB, maxMB, cache.estimatedSize()); log.debug(cache.stats().toString()); }
/** * Performs cache maintenance on both the active and expired caches. */ private void cacheMaintenance() { activeCache.cleanUp(); LOG.debug("Active cache maintenance triggered: cacheStats={}, size={}", activeCache.stats().toString(), activeCache.estimatedSize()); expiredCache.cleanUp(); LOG.debug("Expired cache maintenance triggered: cacheStats={}, size={}", expiredCache.stats().toString(), expiredCache.estimatedSize()); }
if(perfLog.isDebugEnabled() && !cacheStats.isEmpty()) { CacheStats before = cacheStats.get(strategy); CacheStats after = concurrencyContext.getCache().stats(); if(before != null && after != null) { CacheStats delta = after.minus(before);
CacheStats stats = c.getValue().stats();
/** * The cache should continue to hit, even if variables not used in the cached expression change. */ @Test public void testUnrelatedVariableChange() { // expect miss Object result = execute("TO_UPPER(name)", contextWithCache); assertEquals("BLAH", result); assertEquals(1, cache.stats().requestCount()); assertEquals(1, cache.stats().missCount()); assertEquals(0, cache.stats().hitCount()); // add an irrelevant variable that is not used in the expression fields.put("unrelated_var_1", "true"); fields.put("unrelated_var_2", 22); // still expect a hit result = execute("TO_UPPER(name)", contextWithCache); assertEquals("BLAH", result); assertEquals(2, cache.stats().requestCount()); assertEquals(1, cache.stats().missCount()); assertEquals(1, cache.stats().hitCount()); }
/** * Running the same expression multiple times should hit the cache. */ @Test public void testWithCache() { Object result = execute("TO_UPPER(name)", contextWithCache); assertEquals("BLAH", result); assertEquals(1, cache.stats().requestCount()); assertEquals(1, cache.stats().missCount()); assertEquals(0, cache.stats().hitCount()); result = execute("TO_UPPER(name)", contextWithCache); assertEquals("BLAH", result); assertEquals(2, cache.stats().requestCount()); assertEquals(1, cache.stats().missCount()); assertEquals(1, cache.stats().hitCount()); result = execute("TO_UPPER(name)", contextWithCache); assertEquals("BLAH", result); assertEquals(3, cache.stats().requestCount()); assertEquals(1, cache.stats().missCount()); assertEquals(2, cache.stats().hitCount()); }
public @Override String toString() { long size = L2Cache.estimatedSize(); long bytes = sizeTracker.size.get(); long avg = size == 0 ? 0 : bytes / size; return String.format("Size: %,d, bytes: %,d, avg: %,d bytes/entry, %s", size, bytes, avg, L2Cache.stats()); }
@Override public CacheStats stats() { com.github.benmanes.caffeine.cache.stats.CacheStats stats = cache.stats(); return new CacheStats(stats.hitCount(), stats.missCount(), stats.loadSuccessCount(), stats.loadFailureCount(), stats.totalLoadTime(), stats.evictionCount()); }