Ehcache misses count and hitrate statistics

流过昼夜 提交于 2019-12-25 02:07:43

问题


I have configuration for Ehcache as next:

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

And the following code that use it:

    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());

I've prepared simple one-class demo you can run https://github.com/Bezuhlyi/ehcahce-statistics-test

You can see, that misses != inMemoryMisses + offHeapMisses + onDiskMisses.

The question is what actually Statistics.getCacheMisses() counts?

Also, naturally cache hitrate = hits / (hits + misses). And what is a correct way to know actual hitrate of Ehcache instance then?

I haven't found nothing useful about it in docs, as well as about SampledCacheStatistics purpose.


回答1:


I probably should read the code to tell for sure, but I'll say what I think is happening from memory: The misses for the caches are the operations for which no mapping could be found. Where as the "tier" misses are the individual misses on each tier. So that you could have many "heap tier misses", while never have a single cache miss, should the mapping always be found in a lower tier.

Now my answer could be tainted by the exact version of Ehcache you use, but leaving certain oddities aside, I expect that's what you are experiencing.



来源:https://stackoverflow.com/questions/21937512/ehcache-misses-count-and-hitrate-statistics

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!