【问题标题】:Ehcache misses count and hitrate statisticsEhcache 未命中计数和命中率统计
【发布时间】:2014-03-23 03:35:19
【问题描述】:

我将 Ehcache 配置为下一个:

<cache name="test-cache"
       maxEntriesLocalHeap="50"
       maxEntriesLocalDisk="50"
       eternal="false"
       diskSpoolBufferSizeMB="10"
       timeToIdleSeconds="90"
       timeToLiveSeconds="60"
       memoryStoreEvictionPolicy="LFU"
       transactionalMode="off">
    <persistence strategy="localTempSwap"/>
</cache>

以及使用它的以下代码:

    Ehcache cache = CacheManager.getInstance().getCache("test-cache");
    cache.setStatisticsEnabled(true);
    cache.setStatisticsAccuracy(Statistics.STATISTICS_ACCURACY_GUARANTEED);

    /* put 100 elements */
    for (int i = 1; i <= 100; i++) {
        cache.put(new Element("key-"+i, "value-"+i));
    }

    /* hit 100 elements in cache 10000 times */
    for (int i = 1; i <= 100; i++) {
        for (int j = 1; j <= 100 ; j++) {
            cache.get("key-"+j);
        }
    }

    /* consider values of misses, onDiskMisses, inMemoryMisses */
    System.out.println("Statistics = " + cache.getStatistics().toString());

我准备了简单的一类演示,你可以运行https://github.com/Bezuhlyi/ehcahce-statistics-test

您可以看到,misses != inMemoryMisses + offHeapMisses + onDiskMisses

问题是Statistics.getCacheMisses() 到底是什么?

此外,自然缓存命中率 = hits / (hits + misses)。那么了解 Ehcache 实例的实际命中率的正确方法是什么?

我在文档中没有发现任何有用的信息,以及关于 SampledCacheStatistics 的用途。

【问题讨论】:

    标签: java caching ehcache terracotta


    【解决方案1】:

    我可能应该阅读代码来确定,但我会说出我认为从内存中发生的事情:缓存未命中是找不到映射的操作。其中“层”未命中是每一层的单个未命中。这样一来,如果始终在较低层中找到映射,您可能会遇到许多“堆层未命中”,而永远不会有单个缓存未命中。

    现在我的答案可能会受到您使用的 Ehcache 的确切版本的影响,但撇开某些奇怪的东西不谈,我希望这就是您所经历的。

    【讨论】:

    • cacheHits = 5180 inMemoryHits = 4664 onDiskHits = 516 misses = 4820 onDiskMisses = 4820 inMemoryMisses = 5336 现在,看到这些数字,我可以说你是对的。谢谢。
    • 什么时候我们可能需要SampledCacheStatistics 或者它的用例是什么?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-12
    • 2019-07-04
    • 1970-01-01
    • 2013-04-30
    • 2014-03-21
    • 2018-07-22
    相关资源
    最近更新 更多