BigMemory系列文章--5. Ehcache配置和统计数据

一、使用状态:

  1. Name: 缓存名
  2. Status: 状态 
  3. TerracottaClustered: 是否是bigmemory集群模式(bigmemory max)

二、配置信息:

(对应到ehcache.xml中的自定义配置和默认配置)

  1. DiskExpiryThreadIntervalSeconds: 每xx秒检查硬盘的数据是否有过期的
  2. DiskPersistent: 是否做硬盘持久化
  3. DiskSpoolBufferSizedMB: 硬盘缓存区尺寸(单位:MB)
  4. Eternal: 对象是否永久,如果是true的话,TimeToIdleSeconds和TimeToLiveSeconds的配置都会无效。
  5. LoggingEnabled: 是否启动日志
  6. MaxBytesLocalDisk: 硬盘最大存储量(单位是字节)
  7. MaxBytesLocalHeap: 堆内最大存储量(单位是字节)
  8. MaxMemoryOffHeapInBytes: 设置对外内存的最大尺寸(单位是字节)
  9. MaxBytesLocalOffHeap: 堆外最大存储量(单位是字节)(8和9貌似是一样的)
  10. MaxElementsInMemory:   内存最大Elements个数
  11. MaxElementsOnDisk: 硬盘最大Elements个数
  12. MaxEntriesLocalDisk: 硬盘最大Entries个数 
  13. MaxEntriesLocalHeap: 堆内最大Entries个数 
  14. TimeToIdleSeconds: 对象最大空闲时间(超过空闲时间且超过设置的Max,可能参与到对象的删除策略中)
  15. TimeToLiveSeconds: 对象的最大存活时间,也就是对象的过期时间。
  16. OverflowToDisk: OffHeap如果满了,是否flow到硬盘。(默认是false, 如果为false,所有和硬盘相关的配置都不生效)
  17. OverflowToOffHeap: Heap如果满了,是否flow到OffHeap。
  18. Name: 缓存名
  19. TerracottaClustered: 是否是bigmemory集群模式(bigmemory max)
  20. MemoryStoreEvictionPolicy: 堆内Eviction策略(默认是LRU) 
MaxEntries和MaxBytes,一般来说是不共用的。
如果能预估对象个数,但是容量不确定,可以用MaxEntries
如果能预估容量,但是对象个数不确定,可以用MaxBytes
 

三、统计信息:

1. AssociatedCachedName: cache的名称,对应ehcache.xml中的<cache name="mobilServiceOffHeap".../>
2. CacheHitPercentage: 总缓存命中率 
3. CacheHits: 总缓存命中数 
4. CacheMissPercentage: 总缓存丢失率 
5. CacheMisses: 总缓存丢失数 
6. DiskStoreObjectCount: 硬盘中存储的对象个数 (配置中DiskPersistent必须为true)
7. InMemoryHitPercentage: 堆内命中率 
8. InMemoryHits: 堆内命中数 
9. InMemoryMisses: 堆内丢失数
11. MemoryStoreObjectCount: 堆内存储对象个数
11. OffHeapStoreObjectCount: 堆外存储对象个数
12. OffHeapHitPercentage: 堆外命中率 
13. OffHeapHits: 堆外命中数
14. OffHeapMisses: 堆外丢失数 
15. OnDiskHitPercentage: 堆外命中率
16. OnDiskHits: 堆外命中数
17. OnDiskMisses: 堆外丢失数
18. ObjectCount: 总对象个数 

如果当前cache是offheapCache,那么总对象数 = OffHeapStoreObjectCount + DiskStoreObjectCount (可能InMemory是Offheap的热点数据,认为是一个对象)

如果当前cache是heapCache,那么总对象数 = InMemoryStoreObjectCount + DiskStoreObjectCount

19. WriterMaxQueueSize: the maximum size of the write-behind queue (应该是写硬盘的线程,用到的队列)
20. WriteQueueLength:  the size of the write-behind queue(应该是写硬盘的线程,用到的队列)

 

四、自定义统计信息

1. 除了默认的统计信息,可以调用ehcache api获取更加全面的统计信息,实现自己来定制统计。
package com.sohu.tv.mobil.common.jmx;
import java.util.List;

public interface EhcacheExtendWatcherMBean {
    /**
     * 获取延迟结果
     * 
     * @return
     */
    List<String> getGlobalResult();
    /**
     * 获取剔除数量
     * 
     * @return
     */
    long getEvictedCount();
    /**
     * 获取超时数量
     * 
     * @return
     */
    long getExpiredCount();
    /**
     * 获取未命中统计
     * 
     * @return
     */
    List<String> getMissStatisticsMap();
}

 

package com.sohu.tv.mobil.common.jmx.impl;
import com.sohu.tv.mobil.common.jmx.EhcacheExtendWatcherMBean;
import net.sf.ehcache.Ehcache;
import net.sf.ehcache.statistics.StatisticsGateway;
import net.sf.ehcache.statistics.extended.ExtendedStatistics;
import java.util.ArrayList;
import java.util.List;

public class EhcacheExtendWatcher implements EhcacheExtendWatcherMBean {
    private Ehcache ehcache;
    @Override
    public List<String> getGlobalResult() {
        ExtendedStatistics extendedStatistics = ehcache.getStatistics().getExtended();
        ExtendedStatistics.Result getResult = extendedStatistics.allGet();
        ExtendedStatistics.Result putResult = extendedStatistics.allPut();
        ExtendedStatistics.Result missResult = extendedStatistics.allMiss();
        List<String> resultList = new ArrayList<String>();
        String getStr =
                "allGet:count=" + getResult.count().value() + ";rate=" + getResult.rate().value()
                        + ";latency:average=" + getResult.latency().average().value() + ";minimum="
                        + getResult.latency().minimum().value() + ";maximum=" + getResult.latency()
                                .maximum().value();
        String putStr =
                "allPut:count=" + putResult.count().value() + ";rate=" + putResult.rate().value()
                        + ";latency:average=" + putResult.latency().average().value() + ";minimum="
                        + putResult.latency().minimum().value() + ";maximum=" + putResult.latency()
                                .maximum().value();
        String missStr =
                "allMiss:count=" + missResult.count().value() + ";rate=" + missResult.rate().value()
                        + ";latency:average=" + missResult.latency().average().value() + ";minimum="
                        + missResult.latency().minimum().value() + ";maximum=" + missResult.latency()
                                .maximum().value();
        resultList.add(getStr);
        resultList.add(putStr);
        resultList.add(missStr);
        return resultList;
    }
    @Override
    public long getEvictedCount() {
        StatisticsGateway statisticsGateway = ehcache.getStatistics();
        return statisticsGateway.cacheEvictedCount();
    }
    @Override
    public long getExpiredCount() {
        StatisticsGateway statisticsGateway = ehcache.getStatistics();
        return statisticsGateway.cacheExpiredCount();
    }
    @Override
    public List<String> getMissStatisticsMap() {
        StatisticsGateway statisticsGateway = ehcache.getStatistics();
        ExtendedStatistics.Result missResult = statisticsGateway.cacheMissOperation();
        ExtendedStatistics.Result missExpiredResult = statisticsGateway.cacheMissExpiredOperation();
        ExtendedStatistics.Result missMissNotFoundResult =
                statisticsGateway.cacheMissNotFoundOperation();
        String missResultStr =
                "missResult:count=" + missResult.count().value() + ";rate=" + missResult.rate().value()
                        + ";latency:average=" + missResult.latency().average().value() + ";minimum="
                        + missResult.latency().minimum().value() + ";maximum=" + missResult.latency()
                                .maximum().value();
        String missExpiredResultStr =
                "missExpiredResult:count=" + missExpiredResult.count().value() + ";rate="
                        + missExpiredResult.rate().value() + ";latency:average=" + missExpiredResult
                                .latency().average().value() + ";minimum=" + missExpiredResult.latency().minimum()
                                .value() + ";maximum=" + missExpiredResult.latency().maximum().value();
        String missMissNotFoundResultStr =
                "missMissNotFoundResult:count=" + missMissNotFoundResult.count().value() + ";rate="
                        + missMissNotFoundResult.rate().value() + ";latency:average="
                        + missMissNotFoundResult.latency().average().value() + ";minimum="
                        + missMissNotFoundResult.latency().minimum().value() + ";maximum="
                        + missMissNotFoundResult.latency().maximum().value();
        List<String> resultList = new ArrayList<String>();
        resultList.add(missResultStr);
        resultList.add(missExpiredResultStr);
        resultList.add(missMissNotFoundResultStr);
        return resultList;
    }
    public void setEhcache(Ehcache ehcache) {
        this.ehcache = ehcache;
    }
}

 

2. 实现效果:

3. 重要统计说明:

EvictedCount: 剔除个数(内存满之后) 

ExpiredCount: 过期个数 (如果设置了单个KEY的过期时间或者全局的TimeToLive就会出现) 

GlobalResult: 包含各个命令的调用次数,各种响应时间,QPS(rate) 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值