类com.google.common.cache.CacheStats源码实例Demo

下面列出了怎么用com.google.common.cache.CacheStats的API类实例代码及写法,或者点击链接到github查看源代码。

@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);
}
 
源代码2 项目: fdb-record-layer   文件: LocatableResolverTest.java
@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));
}
 
源代码3 项目: oneops   文件: OpampWsController.java
/**
 * 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;
}
 
源代码4 项目: oneops   文件: AntennaWsController.java
/**
 * 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;
}
 
源代码5 项目: sparql-generate   文件: QueryExecutor.java
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);
}
 
源代码6 项目: kylin   文件: AppendTrieDictionary.java
@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);
}
 
源代码7 项目: EVCache   文件: EVCacheInMemoryCache.java
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;
}
 
源代码8 项目: elexis-3-core   文件: MultiGuavaCache.java
@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("------------------------------------------");
	}
}
 
源代码9 项目: kylin-on-parquet-v2   文件: ColumnarStoreCache.java
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;
}
 
源代码10 项目: arcusplatform   文件: IrisMetricSet.java
@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;
}
 
源代码11 项目: micrometer   文件: GuavaCacheMetricsTest.java
@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());
}
 
源代码12 项目: meghanada-server   文件: GlobalCache.java
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(),
  };
}
 
源代码13 项目: siren-join   文件: FilterJoinCache.java
@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);
}
 
源代码14 项目: datacollector   文件: MetricsCache.java
@Override
public CacheStats stats() {
  try {
    return delegate.stats();
  } finally {
    updateGaugeMap();
  }
}
 
源代码15 项目: render   文件: ArgbRendererTest.java
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);
}
 
源代码16 项目: plog   文件: SimpleStatisticsReporter.java
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();
}
 
源代码17 项目: bazel   文件: CacheFileDigestsModule.java
@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.
  }
}
 
源代码18 项目: elexis-3-core   文件: GuavaCache.java
@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("------------------------------------------");
}
 
源代码19 项目: netcdf-java   文件: FileCacheGuava.java
@Override
public void showCache(Formatter f) {
  CacheStats stats = cache.stats();
  f.format("%n%s%n%s%n", name, stats);
}
 
源代码20 项目: netcdf-java   文件: FileCacheGuava.java
@Override
public void showStats(Formatter f) {
  CacheStats stats = cache.stats();
  f.format("%s", stats);
}
 
源代码21 项目: kylin-on-parquet-v2   文件: AppendTrieDictionary.java
public CacheStats getCacheStats() {
    return dictCache.stats();
}
 
源代码22 项目: fdb-record-layer   文件: FDBDatabase.java
public CacheStats getDirectoryCacheStats() {
    return directoryCache.stats();
}
 
源代码23 项目: qpid-broker-j   文件: NullCache.java
@Override
public CacheStats stats()
{
    throw new UnsupportedOperationException();
}
 
源代码24 项目: rubix   文件: ThrowingEmptyCache.java
@Override
public CacheStats stats()
{
  return STATS;
}
 
源代码25 项目: meghanada-server   文件: GlobalCache.java
public double[] getMemberDescriptorsRateStats() throws ExecutionException {
  CacheStats cacheStats = this.memberCache.stats();
  return new double[] {
    cacheStats.hitRate(), cacheStats.loadExceptionRate(), cacheStats.missRate(),
  };
}
 
源代码26 项目: raml-module-builder   文件: HttpModuleClient2.java
@Override
public CacheStats getCacheStats(){
  return cache.stats();
}
 
源代码27 项目: raml-module-builder   文件: HttpClientMock2.java
@Override
public CacheStats getCacheStats() {
  // TODO Auto-generated method stub
  return null;
}
 
源代码28 项目: dsl-devkit   文件: MapCache.java
/** {@inheritDoc} */
@Override
public CacheStatistics getStatistics() {
  CacheStats stats = backend.stats();
  return new CacheStatistics(backend.size(), stats.hitCount(), stats.missCount());
}
 
源代码29 项目: siren-join   文件: FilterJoinCache.java
public FilterJoinCacheStats(long size, CacheStats stats) {
  this.cacheStats = stats;
  this.size = size;
}
 
源代码30 项目: siren-join   文件: FilterJoinCache.java
public CacheStats getCacheStats() {
  return cacheStats;
}