/** * Get the current WatchedByAttributeCache status. Returns the cumulative status of * <ul> * <li>hitCount * <li>missCount; * <li>loadSuccessCount; * <li>loadExceptionCount; * <li>totalLoadTime; * <li>evictionCount; * </ul> * * @return cache status map. */ @RequestMapping(value = "/cache/stats", method = RequestMethod.GET) @ResponseBody public Map<String, Object> getCacheStats() { Map<String, Object> stat = new LinkedHashMap<>(5); stat.put("status", "ok"); stat.put("maxSize", cache.getMaxSize()); stat.put("currentSize", cache.instance().size()); stat.put("timeout", cache.getTimeout()); CacheStats cs = cache.instance().stats(); stat.put("hitCount", cs.hitCount()); stat.put("missCount", cs.missCount()); stat.put("loadSuccessCount", cs.loadSuccessCount()); stat.put("totalLoadTime", TimeUnit.SECONDS.convert(cs.totalLoadTime(), TimeUnit.NANOSECONDS)); stat.put("loadExceptionCount", cs.loadExceptionCount()); stat.put("evictionCount", cs.evictionCount()); return stat; }
/** * Get the current sink cache status. Returns the cumulative status of * <ul> * <li>hitCount * <li>missCount; * <li>loadSuccessCount; * <li>loadExceptionCount; * <li>totalLoadTime; * <li>evictionCount; * </ul> * * @return cache status map. */ @RequestMapping(value = "/cache/stats", method = GET) @ResponseBody public Map<String, Object> getCacheStats() { Map<String, Object> stat = new LinkedHashMap<>(5); stat.put("status", "ok"); stat.put("maxSize", cache.getMaxSize()); stat.put("currentSize", cache.instance().size()); stat.put("timeout", cache.getTimeout()); CacheStats cs = cache.instance().stats(); stat.put("hitCount", cs.hitCount()); stat.put("missCount", cs.missCount()); stat.put("loadSuccessCount", cs.loadSuccessCount()); stat.put("totalLoadTime", SECONDS.convert(cs.totalLoadTime(), NANOSECONDS)); stat.put("loadExceptionCount", cs.loadExceptionCount()); stat.put("evictionCount", cs.evictionCount()); return stat; }
@Override public void applyMetrics(Map<String, Object> map) { CacheStats stats = cache.stats(); map.put(prefix + "averageLoadPenalty", stats.averageLoadPenalty()); map.put(prefix + "evictionCount", stats.evictionCount()); map.put(prefix + "hitCount", stats.hitCount()); map.put(prefix + "hitRate", stats.hitRate()); map.put(prefix + "hitCount", stats.hitCount()); map.put(prefix + "loadExceptionCount", stats.loadExceptionCount()); map.put(prefix + "loadExceptionRate", stats.loadExceptionRate()); map.put(prefix + "loadSuccessCount", stats.loadSuccessCount()); map.put(prefix + "missCount", stats.missCount()); map.put(prefix + "missRate", stats.missRate()); map.put(prefix + "requestCount", stats.requestCount()); map.put(prefix + "totalLoadTime", stats.totalLoadTime()); }
@Test public void test_reset() { Assert.assertEquals("LoadedServicesCount", 0, Services.getLoadedServicesCount()); Services.get(IMockedSingletonService.class); Assert.assertEquals("LoadedServicesCount", 1, Services.getLoadedServicesCount()); Services.clear(); Assert.assertEquals("LoadedServicesCount", 0, Services.getLoadedServicesCount()); // // Check implementation specifics final Cache<Class<? extends IService>, Object> servicesMap = getServicesInternalMap(); final CacheStats cacheStats = servicesMap.stats(); Assert.assertEquals("ServicesMap - size", 0, servicesMap.size()); Assert.assertEquals("ServicesMap - Stats - loadCount", 0, cacheStats.loadCount()); Assert.assertEquals("ServicesMap - Stats - hitCount", 0, cacheStats.hitCount()); Assert.assertEquals("ServicesMap - Stats - missCount", 0, cacheStats.missCount()); }
public CacheInfo(String name, Cache<?, ?> cache) { this.name = name; CacheStats stat = cache.stats(); entries = new EntriesInfo(); entries.setMem(cache.size()); averageGet = duration(stat.averageLoadPenalty()); hitRatio = new HitRatioInfo(); hitRatio.setMem(stat.hitCount(), stat.requestCount()); if (cache instanceof PersistentCache) { type = CacheType.DISK; PersistentCache.DiskStats diskStats = ((PersistentCache) cache).diskStats(); entries.setDisk(diskStats.size()); entries.setSpace(diskStats.space()); hitRatio.setDisk(diskStats.hitCount(), diskStats.requestCount()); } else { type = CacheType.MEM; } }
@SuppressWarnings("unchecked") public SchemaCache(long versionAtCreation, CacheLimits limits, PreparedStatementPlanCache thePstmtCache) { CacheSegment[] values = CacheSegment.values(); tloaded = (Cache<SchemaCacheKey<?>, Object>[]) Array.newInstance(Cache/*<SchemaCacheKey<?>,Object>*/.class, values.length); tloaded_baseline = new CacheStats[values.length]; for(CacheSegment cs : values) { if (cs == CacheSegment.PLAN) continue; tloaded[cs.ordinal()] = buildCache(limits.getLimit(cs)); tloaded_baseline[cs.ordinal()] = null; } planCache = new GlobalPlanCache(limits); pstmtCache = thePstmtCache; version = versionAtCreation; }
@Override public void stat(){ if (STAT_ENABLED) { CacheStats shortStats = shortTermCache.stats(); CacheStats longStats = longTermCache.stats(); System.out.println("--------- GUAVA CACHE Statistics ---------"); System.out.println("|>--- SHORT-TERM"); System.out.println("| Hits (count/rate): " + shortStats.hitCount() + " / " + String.format("%.2f%%", shortStats.hitRate() * 100)); System.out.println("| Misses (count/rate): " + shortStats.missCount() + " / " + String.format("%.2f%%", shortStats.missRate() * 100)); System.out.println("|>--- LONG-TERM "); System.out.println("| Hits (count/rate): " + longStats.hitCount() + " / " + String.format("%.2f%%", longStats.hitRate() * 100)); System.out.println("| Misses (count/rate): " + longStats.missCount() + " / " + String.format("%.2f%%", longStats.missRate() * 100)); System.out.println("------------------------------------------"); } }
private Map<String, Object> buildStats(String name, Cache<Object, Object> cache) { Map<String, Object> map = new LinkedHashMap<>(); map.put("name", name); map.put("status", "UP"); map.put("size", cache.size()); CacheStats stats = cache.stats(); map.put("hitRate", stats.hitRate()); map.put("hitCount", stats.hitCount()); map.put("missCount", stats.missRate()); map.put("loadSuccessCount", stats.loadSuccessCount()); map.put("loadExceptionCount", stats.loadExceptionCount()); map.put("totalLoadTime", stats.totalLoadTime()); map.put("evictionCount", stats.evictionCount()); return map; }
/** * Short description of the cache configuration for display in admin interface * @return String containing all relevant configuration parameters. */ @Override public String getCacheStatus() { CacheStats stats = cache.stats(); return Objects.toStringHelper("Guava-CacheStats") .add("size", cache.size()) .add("hitCount", stats.hitCount()) .add("missCount", stats.missCount()) .add("loadSuccessCount", stats.loadSuccessCount()) .add("loadExceptionCount", stats.loadExceptionCount()) .add("totalLoadTime", stats.totalLoadTime()) .add("evictionCount", stats.evictionCount()) .toString(); }
@Override public void clear() { CacheStats cacheStats = cache.unwrap(GuavaCache.class).stats(); snapshot = new CacheStats(cacheStats.hitCount(), cacheStats.missCount(), cacheStats.loadSuccessCount(), cacheStats.loadExceptionCount(), cacheStats.totalLoadTime(), cacheStats.evictionCount()); }
@Override public CacheStatistics getCacheStatistics(CacheManager cacheManager, GuavaCache cache) { DefaultCacheStatistics statistics = new DefaultCacheStatistics(); statistics.setSize(cache.getNativeCache().size()); CacheStats guavaStats = cache.getNativeCache().stats(); if (guavaStats.requestCount() > 0) { statistics.setHitRatio(guavaStats.hitRate()); statistics.setMissRatio(guavaStats.missRate()); } return statistics; }
/** * {@inheritDoc} * @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet() */ @Override public void afterPropertiesSet() throws Exception { configDir = new File(configDirName).getAbsoluteFile(); appDir = new File(appDirName).getAbsoluteFile(); if(!configDir.isDirectory()) throw new IllegalArgumentException("The configuration directory [" + configDirName + "] is invalid"); if(!appDir.exists()) { appDir.mkdirs(); } if(!appDir.isDirectory()) throw new IllegalArgumentException("The app directory [" + appDirName + "] is invalid"); log.info("Configuration Directory: [{}]", configDir); if(!cacheSpec.contains("recordStats")) cacheSpec = cacheSpec + ",recordStats"; configCache = CacheBuilder.from(cacheSpec).build(configCacheLoader); configCacheStats = new CachedGauge<CacheStats>(5, TimeUnit.SECONDS) { @Override protected CacheStats loadValue() { return configCache.stats(); } }; appJarCache = CacheBuilder.from(cacheSpec).build(appJarCacheLoader); appJarCacheStats = new CachedGauge<CacheStats>(5, TimeUnit.SECONDS) { @Override protected CacheStats loadValue() { return appJarCache.stats(); } }; reloadConfigCache(); log.info("Loaded [{}] App Configurations", configCache.size()); reloadAppJarCache(); log.info("Loaded [{}] App Jar Sets", appJarCache.size()); }
@Test public void testGetCacheStats() throws Exception { TradeAccount expectedTradeAccount = new TradeAccount.Builder().build(); when(cacheLoader.load("223")).thenReturn(expectedTradeAccount); when(cacheLoader.load("000")).thenThrow(new RuntimeException("Bad Value")); LoadingCache<String, TradeAccount> tradeAccountCache = CacheBuilder.newBuilder() .maximumSize(5000L) .expireAfterAccess(10l, TimeUnit.MILLISECONDS) .recordStats() .build(cacheLoader); TradeAccount tradeAccount = tradeAccountCache.get("223"); assertThat(tradeAccount, is(expectedTradeAccount)); TradeAccount tradeAccount1 = tradeAccountCache.get("223"); assertThat(tradeAccount1, is(expectedTradeAccount)); Thread.sleep(20); TradeAccount tradeAccount2 = tradeAccountCache.get("223"); assertThat(tradeAccount2, is(expectedTradeAccount)); try{ tradeAccountCache.get("000"); }catch (RuntimeException e){ //Ignore expected } CacheStats stats = tradeAccountCache.stats(); assertThat(stats.evictionCount(),is(1l)); assertThat(stats.hitCount(),is(1l)); assertThat(stats.missCount(),is(3l)); assertThat(stats.hitRate(),is((double)1/4)); assertThat(stats.loadExceptionCount(),is(1l)); assertThat(stats.loadExceptionRate(),is((double)1/3)); assertThat(stats.loadSuccessCount(),is(2l)); verify(cacheLoader, times(2)).load("223"); }
/** Package-private constructor. */ ClientStats(final long num_connections_created, final long root_lookups, final long meta_lookups_with_permit, final long meta_lookups_wo_permit, final long num_flushes, final long num_nsres, final long num_nsre_rpcs, final long num_multi_rpcs, final long num_gets, final long num_scanners_opened, final long num_scans, final long num_puts, final long num_appends, final long num_row_locks, final long num_deletes, final long num_atomic_increments, final CacheStats increment_buffer_stats) { // JAVA Y U NO HAVE CASE CLASS LIKE SCALA?! FFFFFUUUUUUU!! this.num_connections_created = num_connections_created; this.root_lookups = root_lookups; this.meta_lookups_with_permit = meta_lookups_with_permit; this.meta_lookups_wo_permit = meta_lookups_wo_permit; this.num_flushes = num_flushes; this.num_nsres = num_nsres; this.num_nsre_rpcs = num_nsre_rpcs; this.num_multi_rpcs = num_multi_rpcs; this.num_gets = num_gets; this.num_scanners_opened = num_scanners_opened; this.num_scans = num_scans; this.num_puts = num_puts; this.num_appends = num_appends; this.num_row_locks = num_row_locks; this.num_deletes = num_deletes; this.num_atomic_increments = num_atomic_increments; this.increment_buffer_stats = increment_buffer_stats; }
@Override public void readFrom(StreamInput in) throws IOException { size = in.readVLong(); long hitCount = in.readVLong(); long misscount = in.readVLong(); long loadSuccessCount = in.readVLong(); long loadExceptionCount = in.readVLong(); long totalLoadTime = in.readVLong(); long evictionCount = in.readVLong(); cacheStats = new CacheStats(hitCount, misscount, loadSuccessCount, loadExceptionCount, totalLoadTime, evictionCount); }
public Map<FoxCache.Statistic, Number> getStatistics() { HashMap<FoxCache.Statistic, Number> lResult = new HashMap<FoxCache.Statistic, Number>(); CacheStats lStats = mCache.stats(); lResult.put(FoxCache.Statistic.CURRENT_SIZE, mCache.size()); lResult.put(FoxCache.Statistic.CAPACITY, mCapacity); lResult.put(FoxCache.Statistic.HIT_RATE, lStats.hitRate()); lResult.put(FoxCache.Statistic.HIT_COUNT, lStats.hitCount()); lResult.put(FoxCache.Statistic.MISS_COUNT, lStats.missCount()); return lResult; }
private CCacheStats(final long cacheId, final String name, final long size, CacheStats guavaStats) { super(); this.cacheId = cacheId; this.name = name; this.size = size; this.guavaStats = guavaStats; }
public Map<String, Object> getStats () { // Get Cache Stats: requestCount, hitRate Map<String, Object> map = Maps.newHashMap(); CacheStats stats = cache.stats(); Long reqCount = stats.requestCount(); Double hitRate = stats.hitRate(); map.put ("requestCount", reqCount); map.put ("hitRate", hitRate); return map; }
@Override public CacheStats stats() { try { return delegate.stats(); } finally { updateGaugeMap(); } }
private void validateCacheRender(final String context, final RenderParameters params, final ImageProcessorCache imageProcessorCache, final int expectedCacheSize, final int expectedHitCount, final String expectedDigestString) throws Exception { final BufferedImage targetImage = params.openTargetImage(); ArgbRenderer.render(params, targetImage, imageProcessorCache); Assert.assertEquals(context + ": invalid number of items in cache", expectedCacheSize, imageProcessorCache.size()); final CacheStats stats = imageProcessorCache.getStats(); Assert.assertEquals(context + ": invalid number of cache hits", expectedHitCount, stats.hitCount()); Utils.saveImage(targetImage, outputFile.getAbsolutePath(), Utils.JPEG_FORMAT, params.isConvertToGray(), params.getQuality()); final String actualDigestString = getDigestString(outputFile); Assert.assertEquals(context + ": stitched file MD5 hash differs from expected result", expectedDigestString, actualDigestString); }
public final String toJSON() { final JsonObject result = new JsonObject() .add("version", getPlogVersion()) .add("uptime", System.currentTimeMillis() - startTime) .add("udp_simple_messages", udpSimpleMessages.get()) .add("udp_invalid_version", udpInvalidVersion.get()) .add("v0_invalid_type", v0InvalidType.get()) .add("v0_invalid_multipart_header", v0InvalidMultipartHeader.get()) .add("unknown_command", unknownCommand.get()) .add("v0_commands", v0Commands.get()) .add("exceptions", exceptions.get()) .add("unhandled_objects", unhandledObjects.get()) .add("holes_from_dead_port", holesFromDeadPort.get()) .add("holes_from_new_message", holesFromNewMessage.get()) .add("v0_fragments", arrayForLogStats(v0MultipartMessageFragments)) .add("v0_invalid_checksum", arrayForLogStats(v0InvalidChecksum)) .add("v0_invalid_fragments", arrayForLogLogStats(invalidFragments)) .add("dropped_fragments", arrayForLogLogStats(droppedFragments)); if (defragmenter != null) { final CacheStats cacheStats = defragmenter.getCacheStats(); result.add("defragmenter", new JsonObject() .add("evictions", cacheStats.evictionCount()) .add("hits", cacheStats.hitCount()) .add("misses", cacheStats.missCount())); } final JsonArray handlersStats = new JsonArray(); result.add("handlers", handlersStats); for (Handler handler : handlers) { final JsonObject statsCandidate = handler.getStats(); final JsonObject stats = (statsCandidate == null) ? new JsonObject() : statsCandidate; handlersStats.add(stats.set("name", handler.getName())); } return result.toString(); }
/** * Adds a line to the log with cache statistics. * * @param message message to prefix to the written line * @param stats the cache statistics to be logged */ private static void logStats(String message, CacheStats stats) { logger.info( message + ": hit count=" + stats.hitCount() + ", miss count=" + stats.missCount() + ", hit rate=" + stats.hitRate() + ", eviction count=" + stats.evictionCount()); }
@Override public void afterCommand() { super.afterCommand(); if (stats != null) { CacheStats newStats = DigestUtils.getCacheStats(); Preconditions.checkNotNull(newStats, "The cache is enabled so we must get some stats back"); logStats("Accumulated cache stats after command", newStats); logStats("Cache stats for finished command", newStats.minus(stats)); stats = null; // Silence stats until next command that uses the executor. } }
@Override public CacheStats getMainStats() { if(baselineStats != null) return planCache.stats().minus(baselineStats); return planCache.stats(); }
private void writeCacheStatsToLog() { for (Entry<String, Cache<?, ?>> e : caches.entrySet()) { String name = e.getKey(); CacheStats stats = e.getValue().stats(); double averageLoadPenalty = stats.averageLoadPenalty(); double hitRate = stats.hitRate(); String message = String.format("%s hitRate=%.2f averageLoadPenalty=%.2f %s", name, hitRate, averageLoadPenalty, stats.toString()); logger.log(Level.INFO, message); } }
/** * Method to get the stats about the cache. * * @return */ public String getStats() { StringBuilder stringBuilder = new StringBuilder(); CacheStats cacheStats = cacheResource.getCacheStats().minus(relativeCacheStats); stringBuilder.append(String.format("Total succesful loaded values: %d %n", cacheStats.loadSuccessCount())); stringBuilder.append(String.format("Total requests: %d %n", cacheStats.requestCount())); stringBuilder.append(String.format("Hits ratio: %d/%d - %.3f %n", cacheStats.hitCount(), cacheStats.missCount(), cacheStats.hitRate())); stringBuilder.append(String.format("Average time spent loading new values (nanoseconds): %.3f %n", cacheStats.averageLoadPenalty())); stringBuilder.append(String.format("Number of cache evictions: %d %n", cacheStats.evictionCount())); return stringBuilder.toString(); }
@Override public CacheStats stats() { return new CacheStats( cacheHitCount.get(), cacheMissCount.get(), cacheLoadSuccessCount.get(), cacheLoadExceptionCount.get(), cacheTotalLoadTime.get(), cacheEvictionCount.get()); }
@Override public void stat(){ CacheStats shortStats = shortTermCache.stats(); System.out.println("--------- GUAVA CACHE Statistics ---------"); System.out.println("Hits (count/rate): " + shortStats.hitCount() + " / " + String.format("%.2f%%", shortStats.hitRate() * 100)); System.out.println("Misses (count/rate): " + shortStats.missCount() + " / " + String.format("%.2f%%", shortStats.missRate() * 100)); System.out.println("------------------------------------------"); }
public CacheStats stats() { return cache.stats(); }
public CacheStats getStats() { return cache.stats(); }
public CacheStats getCacheStats(){ return cache.stats(); }
@Override public CacheStats getCacheStats(){ return cache.stats(); }
@Override public CacheStats getCacheStats() { // TODO Auto-generated method stub return null; }
/** {@inheritDoc} */ @Override public CacheStatistics getStatistics() { CacheStats stats = backend.stats(); return new CacheStatistics(backend.size(), stats.hitCount(), stats.missCount()); }
/** Returns statistics from the buffer used to coalesce increments. */ public CacheStats incrementBufferStats() { return increment_buffer_stats; }
@Override public CacheStats stats() { throw new UnsupportedOperationException("stats not supported"); }