use of com.github.benmanes.caffeine.cache.stats.CacheStats in project caffeine by ben-manes.
the class CacheStatsTest method testMinus.
public void testMinus() {
CacheStats one = new CacheStats(11, 13, 17, 19, 23, 27, 54);
CacheStats two = new CacheStats(53, 47, 43, 41, 37, 31, 62);
CacheStats diff = two.minus(one);
assertEquals(76, diff.requestCount());
assertEquals(42, diff.hitCount());
assertEquals(42.0 / 76, diff.hitRate());
assertEquals(34, diff.missCount());
assertEquals(34.0 / 76, diff.missRate());
assertEquals(26, diff.loadSuccessCount());
assertEquals(22, diff.loadFailureCount());
assertEquals(22.0 / 48, diff.loadFailureRate());
assertEquals(26 + 22, diff.loadCount());
assertEquals(14, diff.totalLoadTime());
assertEquals(14.0 / (26 + 22), diff.averageLoadPenalty());
assertEquals(4, diff.evictionCount());
assertEquals(8, diff.evictionWeight());
assertEquals(new CacheStats(0, 0, 0, 0, 0, 0, 0), one.minus(two));
}
use of com.github.benmanes.caffeine.cache.stats.CacheStats in project druid by druid-io.
the class CaffeineCache method doMonitor.
@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");
}
}
use of com.github.benmanes.caffeine.cache.stats.CacheStats in project spring-boot by spring-projects.
the class CaffeineCacheStatisticsProvider method getCacheStatistics.
@Override
public CacheStatistics getCacheStatistics(CacheManager cacheManager, CaffeineCache cache) {
DefaultCacheStatistics statistics = new DefaultCacheStatistics();
statistics.setSize(cache.getNativeCache().estimatedSize());
CacheStats caffeineStatistics = cache.getNativeCache().stats();
if (caffeineStatistics.requestCount() > 0) {
statistics.setHitRatio(caffeineStatistics.hitRate());
statistics.setMissRatio(caffeineStatistics.missRate());
}
return statistics;
}
Aggregations