use of com.github.benmanes.caffeine.cache.stats.CacheStats in project caffeine by ben-manes.
the class HasStats method matchesSafely.
@Override
protected boolean matchesSafely(CacheContext context, Description description) {
if (!context.isRecordingStats()) {
return true;
}
CacheStats stats = context.stats();
desc = new DescriptionBuilder(description);
ForkJoinPool.commonPool().awaitQuiescence(10, TimeUnit.SECONDS);
switch(type) {
case HIT:
return desc.expectThat(type.name(), stats.hitCount(), is(count)).matches();
case MISS:
return desc.expectThat(type.name(), stats.missCount(), is(count)).matches();
case EVICTION_COUNT:
return desc.expectThat(type.name(), stats.evictionCount(), is(count)).matches();
case EVICTION_WEIGHT:
return desc.expectThat(type.name(), stats.evictionWeight(), is(count)).matches();
case LOAD_SUCCESS:
return desc.expectThat(type.name(), stats.loadSuccessCount(), is(count)).matches();
case LOAD_FAILURE:
return desc.expectThat(type.name(), stats.loadFailureCount(), is(count)).matches();
default:
throw new AssertionError("Unknown stats type");
}
}
use of com.github.benmanes.caffeine.cache.stats.CacheStats in project caffeine by ben-manes.
the class CacheStatsTest method testEmpty.
public void testEmpty() {
CacheStats stats = new CacheStats(0, 0, 0, 0, 0, 0, 0);
assertEquals(0, stats.requestCount());
assertEquals(0, stats.hitCount());
assertEquals(1.0, stats.hitRate());
assertEquals(0, stats.missCount());
assertEquals(0.0, stats.missRate());
assertEquals(0, stats.loadSuccessCount());
assertEquals(0, stats.loadFailureCount());
assertEquals(0.0, stats.loadFailureRate());
assertEquals(0, stats.loadCount());
assertEquals(0, stats.totalLoadTime());
assertEquals(0.0, stats.averageLoadPenalty());
assertEquals(0, stats.evictionCount());
}
use of com.github.benmanes.caffeine.cache.stats.CacheStats in project caffeine by ben-manes.
the class CacheStatsTest method testSingle.
public void testSingle() {
CacheStats stats = new CacheStats(11, 13, 17, 19, 23, 27, 54);
assertEquals(24, stats.requestCount());
assertEquals(11, stats.hitCount());
assertEquals(11.0 / 24, stats.hitRate());
assertEquals(13, stats.missCount());
assertEquals(13.0 / 24, stats.missRate());
assertEquals(17, stats.loadSuccessCount());
assertEquals(19, stats.loadFailureCount());
assertEquals(19.0 / 36, stats.loadFailureRate());
assertEquals(17 + 19, stats.loadCount());
assertEquals(23, stats.totalLoadTime());
assertEquals(23.0 / (17 + 19), stats.averageLoadPenalty());
assertEquals(27, stats.evictionCount());
assertEquals(54, stats.evictionWeight());
}
use of com.github.benmanes.caffeine.cache.stats.CacheStats in project narchy by automenta.
the class CaffeineMemoize method summary.
@Override
public String summary() {
CacheStats stats = cache.stats();
String a;
if (stats.hitCount() > 0)
a = n2(stats.hitRate() * 100f) + "% hits, ";
else
a = "";
return a + cache.estimatedSize() + " size";
}
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");
}
}
Aggregations