com.google.common.cache.CacheStats Java Examples

The following examples show how to use com.google.common.cache.CacheStats. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AppendTrieDictionary.java    From kylin-on-parquet-v2 with Apache License 2.0 6 votes vote down vote up
@Override
public int getIdFromValueBytesWithoutCache(byte[] value, int offset, int len, int roundingFlag) {
    byte[] val = Arrays.copyOfRange(value, offset, offset + len);
    AppendDictSliceKey sliceKey = metadata.sliceFileMap.floorKey(AppendDictSliceKey.wrap(val));
    if (sliceKey == null) {
        sliceKey = metadata.sliceFileMap.firstKey();
    }
    AppendDictSlice slice;
    try {
        slice = dictCache.get(sliceKey);
    } catch (ExecutionException e) {
        throw new IllegalStateException("Failed to load slice with key " + sliceKey, e.getCause());
    }
    CacheStats stats = dictCache.stats();
    if (evictionThreshold > 0 && stats.evictionCount() > evictionThreshold * metadata.sliceFileMap.size()
            && stats.loadCount() > (evictionThreshold + 1) * metadata.sliceFileMap.size()) {
        logger.warn(
                "Too many dict slice evictions and reloads, maybe the memory is not enough to hold all the dictionary");
        throw new RuntimeException("Too many dict slice evictions: " + stats + " for "
                + metadata.sliceFileMap.size() + " dict slices. "
                + "Maybe the memory is not enough to hold all the dictionary, try to enlarge the mapreduce/spark executor memory.");
    }
    return slice.getIdFromValueBytesImpl(value, offset, len, roundingFlag);
}
 
Example #2
Source File: AppendTrieDictionary.java    From kylin with Apache License 2.0 6 votes vote down vote up
@Override
public int getIdFromValueBytesWithoutCache(byte[] value, int offset, int len, int roundingFlag) {
    byte[] val = Arrays.copyOfRange(value, offset, offset + len);
    AppendDictSliceKey sliceKey = metadata.sliceFileMap.floorKey(AppendDictSliceKey.wrap(val));
    if (sliceKey == null) {
        sliceKey = metadata.sliceFileMap.firstKey();
    }
    AppendDictSlice slice;
    try {
        slice = dictCache.get(sliceKey);
    } catch (ExecutionException e) {
        throw new IllegalStateException("Failed to load slice with key " + sliceKey, e.getCause());
    }
    CacheStats stats = dictCache.stats();
    if (evictionThreshold > 0 && stats.evictionCount() > evictionThreshold * metadata.sliceFileMap.size()
            && stats.loadCount() > (evictionThreshold + 1) * metadata.sliceFileMap.size()) {
        logger.warn(
                "Too many dict slice evictions and reloads, maybe the memory is not enough to hold all the dictionary");
        throw new RuntimeException("Too many dict slice evictions: " + stats + " for "
                + metadata.sliceFileMap.size() + " dict slices. "
                + "Maybe the memory is not enough to hold all the dictionary, try to enlarge the mapreduce/spark executor memory.");
    }
    return slice.getIdFromValueBytesImpl(value, offset, len, roundingFlag);
}
 
Example #3
Source File: QueryExecutor.java    From sparql-generate with Apache License 2.0 6 votes vote down vote up
public void execSelectPlan(
        final RootPlan plan,
        final List<Binding> newValues,
        final Context context) {
    Objects.nonNull(ContextUtils.getSelectOutput(context));
    final ExecutionKey key = new ExecutionKey(plan, newValues);
    if (++nbselect % 2000 == 00) {
        CacheStats stats = selectExecutions.stats();

        LOG.info("call select " + nbselect + " count " + stats.loadCount() + " - hit count " + stats.hitCount() + " - rate " + stats.hitRate());
    }
    ResultSetRewindable resultSet = selectExecutions.getIfPresent(key);
    if (resultSet != null) {
        resultSet.reset();
    } else {
        ResultSet memResultSet = plan.execSelect(newValues, context);
        resultSet = ResultSetFactory.copyResults(memResultSet);
        selectExecutions.put(key, resultSet);
    }
    ContextUtils.getSelectOutput(context).accept(resultSet);
}
 
Example #4
Source File: LocatableResolverTest.java    From fdb-record-layer with Apache License 2.0 6 votes vote down vote up
@Test
public void testLookupCaching() {
    KeySpace keySpace = new KeySpace(new KeySpaceDirectory("path", KeyType.STRING, "path"));

    ResolvedKeySpacePath path1;
    try (FDBRecordContext context = database.openContext()) {
        path1 = keySpace.resolveFromKey(context, Tuple.from("path"));
    }
    LocatableResolver resolver = scopedDirectoryGenerator.apply(database, path1);

    Long value = resolver.resolve("foo").join();

    for (int i = 0; i < 5; i++) {
        Long fetched = resolver.resolve("foo").join();
        assertThat("we should always get the original value", fetched, is(value));
    }
    CacheStats stats = database.getDirectoryCacheStats();
    assertThat("subsequent lookups should hit the cache", stats.hitCount(), is(5L));
}
 
Example #5
Source File: MultiGuavaCache.java    From elexis-3-core with Eclipse Public License 1.0 6 votes vote down vote up
@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("------------------------------------------");
	}
}
 
Example #6
Source File: OpampWsController.java    From oneops with Apache License 2.0 6 votes vote down vote up
/**
 * 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;
}
 
Example #7
Source File: AntennaWsController.java    From oneops with Apache License 2.0 6 votes vote down vote up
/**
 * 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;
}
 
Example #8
Source File: EVCacheInMemoryCache.java    From EVCache with Apache License 2.0 6 votes vote down vote up
private long getSize() {
    final long size = cache.size();
    final CacheStats stats = cache.stats();

    getCounter("hits").increment(stats.hitCount());
    getCounter("miss").increment(stats.missCount());
    getCounter("evictions").increment(stats.evictionCount());
    getCounter("requests").increment(stats.requestCount());

    getCounter("loadExceptionCount").increment(stats.loadExceptionCount());
    getCounter("loadCount").increment(stats.loadCount());
    getCounter("loadSuccessCount").increment(stats.loadSuccessCount());
    getCounter("totalLoadTime-ms").increment(cache.stats().totalLoadTime()/1000000);

    getGauge("hitrate").set(stats.hitRate());
    getGauge("loadExceptionRate").set(stats.loadExceptionRate());
    getGauge("averageLoadTime-ms").set(stats.averageLoadPenalty()/1000000);
    return size;
}
 
Example #9
Source File: SimpleStatisticsReporter.java    From plog with Apache License 2.0 5 votes vote down vote up
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();
}
 
Example #10
Source File: CacheFileDigestsModule.java    From bazel with Apache License 2.0 5 votes vote down vote up
@Override
public void commandComplete() {
  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.
  }
}
 
Example #11
Source File: ArgbRendererTest.java    From render with GNU General Public License v2.0 5 votes vote down vote up
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);
}
 
Example #12
Source File: FilterJoinCache.java    From siren-join with GNU Affero General Public License v3.0 5 votes vote down vote up
@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);
}
 
Example #13
Source File: GlobalCache.java    From meghanada-server with GNU General Public License v3.0 5 votes vote down vote up
public long[] getMemberDescriptorsCountStats() throws ExecutionException {
  CacheStats cacheStats = this.memberCache.stats();
  return new long[] {
    cacheStats.hitCount(),
    cacheStats.loadCount(),
    cacheStats.loadExceptionCount(),
    cacheStats.loadSuccessCount(),
    cacheStats.missCount(),
    cacheStats.requestCount(),
  };
}
 
Example #14
Source File: MetricsCache.java    From datacollector with Apache License 2.0 5 votes vote down vote up
@Override
public CacheStats stats() {
  try {
    return delegate.stats();
  } finally {
    updateGaugeMap();
  }
}
 
Example #15
Source File: GuavaCacheMetricsTest.java    From micrometer with Apache License 2.0 5 votes vote down vote up
@Test
void reportExpectedMetrics() {
    MeterRegistry registry = new SimpleMeterRegistry();
    metrics.bindTo(registry);

    verifyCommonCacheMetrics(registry, metrics);

    // common metrics
    Gauge cacheSize = fetch(registry, "cache.size").gauge();
    assertThat(cacheSize.value()).isEqualTo(cache.size());

    FunctionCounter hitCount = fetch(registry, "cache.gets", Tags.of("result", "hit")).functionCounter();
    assertThat(hitCount.count()).isEqualTo(metrics.hitCount());

    FunctionCounter missCount = fetch(registry, "cache.gets", Tags.of("result", "miss")).functionCounter();
    assertThat(missCount.count()).isEqualTo(metrics.missCount().doubleValue());

    FunctionCounter cachePuts = fetch(registry, "cache.puts").functionCounter();
    assertThat(cachePuts.count()).isEqualTo(metrics.putCount());

    FunctionCounter cacheEviction = fetch(registry, "cache.evictions").functionCounter();
    assertThat(cacheEviction.count()).isEqualTo(metrics.evictionCount().doubleValue());

    CacheStats stats = cache.stats();
    TimeGauge loadDuration = fetch(registry, "cache.load.duration").timeGauge();
    assertThat(loadDuration.value()).isEqualTo(stats.totalLoadTime());

    FunctionCounter successfulLoad = fetch(registry, "cache.load", Tags.of("result", "success")).functionCounter();
    assertThat(successfulLoad.count()).isEqualTo(stats.loadSuccessCount());

    FunctionCounter failedLoad = fetch(registry, "cache.load", Tags.of("result", "failure")).functionCounter();
    assertThat(failedLoad.count()).isEqualTo(stats.loadExceptionCount());
}
 
Example #16
Source File: GuavaCache.java    From elexis-3-core with Eclipse Public License 1.0 5 votes vote down vote up
@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("------------------------------------------");
}
 
Example #17
Source File: IrisMetricSet.java    From arcusplatform with Apache License 2.0 5 votes vote down vote up
@Override
public Map<String, Object> getValue() {
   CacheStats stats = cache.stats();
   Map<String, Object> values = new LinkedHashMap<String, Object>(6);
   values.put("size", cache.size());
   values.put("count", stats.requestCount());
   values.put("hits", stats.hitCount());
   values.put("misses", stats.missCount());
   values.put("load.count", stats.loadCount());
   values.put("load.time", stats.totalLoadTime());
   return values;
}
 
Example #18
Source File: ColumnarStoreCache.java    From kylin-on-parquet-v2 with Apache License 2.0 5 votes vote down vote up
public ColumnarStoreCacheStats getCacheStats() {
    ColumnarStoreCacheStats stats = new ColumnarStoreCacheStats();
    CacheStats cacheStats = fragmentDataCache.stats();

    stats.setHitCount(cacheStats.hitCount());
    stats.setMissCount(cacheStats.missCount());
    stats.setEvictionCount(cacheStats.evictionCount());
    stats.setLoadSuccessCount(cacheStats.loadSuccessCount());
    stats.setLoadExceptionCount(cacheStats.loadExceptionCount());
    stats.setTotalLoadTime(cacheStats.totalLoadTime());

    stats.setCacheEntriesNum(fragmentDataCache.size());
    stats.setCachedDataBufferSize(currentBufferedSize.get());
    return stats;
}
 
Example #19
Source File: LocalCacheStatsMXBean.java    From glowroot with Apache License 2.0 4 votes vote down vote up
LocalCacheStatsWrapper(CacheStats cacheStats) {
    this.cacheStats = cacheStats;
}
 
Example #20
Source File: CanvasDataCache.java    From render with GNU General Public License v2.0 4 votes vote down vote up
/**
 * @return a current snapshot of this cache's cumulative statistics.
 */
public CacheStats stats() {
    return canvasIdToDataCache.stats();
}
 
Example #21
Source File: KeyTransformingLoadingCache.java    From brooklyn-server with Apache License 2.0 4 votes vote down vote up
@Override
public CacheStats stats() {
    return delegate().stats();
}
 
Example #22
Source File: CacheManager.java    From elasticactors with Apache License 2.0 4 votes vote down vote up
@Override
public CacheStats stats() {
    return backingCache.stats();
}
 
Example #23
Source File: TokenCache.java    From nifi with Apache License 2.0 4 votes vote down vote up
@Override
public CacheStats stats() {
    return internalCache.stats();
}
 
Example #24
Source File: CacheMetricsCollector.java    From client_java with Apache License 2.0 4 votes vote down vote up
@Override
public List<MetricFamilySamples> collect() {
    List<MetricFamilySamples> mfs = new ArrayList<MetricFamilySamples>();
    List<String> labelNames = Arrays.asList("cache");

    CounterMetricFamily cacheHitTotal = new CounterMetricFamily("guava_cache_hit_total",
            "Cache hit totals", labelNames);
    mfs.add(cacheHitTotal);

    CounterMetricFamily cacheMissTotal = new CounterMetricFamily("guava_cache_miss_total",
            "Cache miss totals", labelNames);
    mfs.add(cacheMissTotal);

    CounterMetricFamily cacheRequestsTotal = new CounterMetricFamily("guava_cache_requests_total",
            "Cache request totals, hits + misses", labelNames);
    mfs.add(cacheRequestsTotal);

    CounterMetricFamily cacheEvictionTotal = new CounterMetricFamily("guava_cache_eviction_total",
            "Cache eviction totals, doesn't include manually removed entries", labelNames);
    mfs.add(cacheEvictionTotal);

    CounterMetricFamily cacheLoadFailure = new CounterMetricFamily("guava_cache_load_failure_total",
            "Cache load failures", labelNames);
    mfs.add(cacheLoadFailure);

    CounterMetricFamily cacheLoadTotal = new CounterMetricFamily("guava_cache_loads_total",
            "Cache loads: both success and failures", labelNames);
    mfs.add(cacheLoadTotal);

    GaugeMetricFamily cacheSize = new GaugeMetricFamily("guava_cache_size",
            "Cache size", labelNames);
    mfs.add(cacheSize);

    SummaryMetricFamily cacheLoadSummary = new SummaryMetricFamily("guava_cache_load_duration_seconds",
            "Cache load duration: both success and failures", labelNames);
    mfs.add(cacheLoadSummary);

    for(Map.Entry<String, Cache> c: children.entrySet()) {
        List<String> cacheName = Arrays.asList(c.getKey());
        CacheStats stats = c.getValue().stats();

        cacheHitTotal.addMetric(cacheName, stats.hitCount());
        cacheMissTotal.addMetric(cacheName, stats.missCount());
        cacheRequestsTotal.addMetric(cacheName, stats.requestCount());
        cacheEvictionTotal.addMetric(cacheName, stats.evictionCount());
        cacheSize.addMetric(cacheName, c.getValue().size());

        if(c.getValue() instanceof LoadingCache) {
            cacheLoadFailure.addMetric(cacheName, stats.loadExceptionCount());
            cacheLoadTotal.addMetric(cacheName, stats.loadCount());

            cacheLoadSummary.addMetric(cacheName, stats.loadCount(), stats.totalLoadTime() / Collector.NANOSECONDS_PER_SECOND);
        }
    }
    return mfs;
}
 
Example #25
Source File: MetadataCache.java    From blueflood with Apache License 2.0 4 votes vote down vote up
@Override
public CacheStats getStats() {
    return cache.stats();
}
 
Example #26
Source File: TransferPool.java    From multiway-pool with Apache License 2.0 4 votes vote down vote up
@Override
public CacheStats stats() {
  return null;//cache.stats();
}
 
Example #27
Source File: ReservationCache.java    From usergrid with Apache License 2.0 4 votes vote down vote up
public CacheStats getStats() {
    return cache.stats();
}
 
Example #28
Source File: MultiwayPool.java    From multiway-pool with Apache License 2.0 4 votes vote down vote up
/** Returns a current snapshot of this pool's cumulative cache statistics, if enabled. */
CacheStats stats();
 
Example #29
Source File: FileCacheGuava.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void showCache(Formatter f) {
  CacheStats stats = cache.stats();
  f.format("%n%s%n%s%n", name, stats);
}
 
Example #30
Source File: HttpClientMock2.java    From raml-module-builder with Apache License 2.0 4 votes vote down vote up
@Override
public CacheStats getCacheStats() {
  // TODO Auto-generated method stub
  return null;
}