Ehcache丢失计数和命中率统计信息 [英] Ehcache misses count and hitrate statistics

查看:829
本文介绍了Ehcache丢失计数和命中率统计信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我接下来将对Ehcache进行配置:

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

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

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

您会看到, missing!= inMemoryMisses + offHeapMisses + onDiskMisses .

问题是实际上 Statistics.getCacheMisses() 计数吗?

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

此外,自然地缓存hitrate = hits/(命中+未命中).那么知道Ehcache实例的实际命中率的正确方法是什么?

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

我在文档中以及关于 SampledCacheStatistics 目的没有发现有用的信息.

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

推荐答案

我也许应该阅读代码以确保确定,但是我会说我认为内存中正在发生的事情:缓存的缺失是针对内存的操作.找不到映射.作为层"未命中的地方是每个层上的个别未命中.因此,如果始终在较低的层中找到映射,则可能会有许多堆层未命中",而永远不会有单个缓存未命中.

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.

现在,我的答案可能会因您使用的Ehcache的确切版本而受污染,但是撇开某些奇怪之处,我希望这就是您所遇到的.

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.

这篇关于Ehcache丢失计数和命中率统计信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆