`
carlosfu
  • 浏览: 576823 次
  • 性别: Icon_minigender_1
  • 来自: 北京
博客专栏
Ba8b5055-9c58-3ab0-8a1c-e710f0495d2c
BigMemory实战与理...
浏览量:30529
53b2087e-c637-34d2-b61d-257846f73ade
RedisCluster开...
浏览量:150211
C9f66038-7478-3388-8086-d20c1f535495
缓存的使用与设计
浏览量:123524
社区版块
存档分类
最新评论

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) 

  • 大小: 464 Bytes
分享到:
评论

相关推荐

    Ehcache 2.10.8(bigmemory-max-4.3.8.4.2.tar.gz)

    - Terracotta集群集成:bigmemory-max集成了Terracotta服务器,可以实现跨节点的分布式缓存和数据同步。 4. 压缩包内容解析: - 解压bigmemory-max-4.3.8.4.2.tar.gz,会得到Ehcache的相关库文件、配置示例、文档...

    ehcache-3.9.9-API文档-中英对照版.zip

    赠送jar包:ehcache-3.9.9.jar; 赠送原API文档:ehcache-3.9.9-javadoc.jar; 赠送源代码:ehcache-3.9.9-sources.jar; 赠送Maven依赖信息文件:ehcache-3.9.9.pom; 包含翻译后的API文档:ehcache-3.9.9-javadoc-...

    Ehcache 2.10.8 .tar.gz(bigmemory-max-4.3.8.4.2.tar.gz)

    Ehcache 2.x系列是其历史上的一个稳定版本,支持多种缓存策略,包括LRU(Least Recently Used)和LFU(Least Frequently Used)等,用于自动清理不常访问的数据。此外,Ehcache支持分布式缓存,可以在多台服务器之间...

    hibernate jar包:hibernate-commons-annotations-4.0.1.Final.jar等

    hibernate-ehcache-4.1.12.Final.jar hibernate-entitymanager-4.1.12.Final.jar hibernate-jpa-2.0-api-1.0.1.Final.jar hibernate-search-4.2.0.Final.jar hibernate-search-analyzers-4.2.0.Final.jar hibernate-...

    hibernate-ehcache-4.3.9.Final.jar

    该包是hibernate中所用的一个包,专门用来去处理特定的问题,它是和ehcache一起用的一个包

    ehcache-core-2.6.11-API文档-中英对照版.zip

    赠送jar包:ehcache-core-2.6.11.jar; 赠送原API文档:ehcache-core-2.6.11-javadoc.jar; 赠送源代码:ehcache-core-2.6.11-sources.jar; 赠送Maven依赖信息文件:ehcache-core-2.6.11.pom; 包含翻译后的API文档...

    ehcache缓存jar(ehcache-core-2.4.6.jar+ehcache-web-2.0.4.jar)

    ehcache缓存jar(ehcache-core-2.4.6.jar+ehcache-web-2.0.4.jar)

    mybatis-ehcache-1.0.2.jar

    mybatis-ehcache-1.0.2.jar META-INF/LICENSE META-INF/MANIFEST.MF META-INF/NOTICE META-INF/maven/org.mybatis.caches/mybatis-ehcache/pom.properties META-INF/maven/org.mybatis.caches/mybatis-ehcache/pom....

    ehcache-core-2.4.5.jar

    "ehcache-core-2.4.5.jar"是Ehcache的核心库,该版本为2.4.5,包含Ehcache的基本功能和API。在使用这个版本的Ehcache时,需要额外引入两个SLF4J(Simple Logging Facade for Java)的依赖,分别是"slf4j-api-1.6.1....

    ehcache.rar ehcache-core-2.6.10.jar依赖包

    ehcache-core-2.6.10.jar依赖包 MyBatiesEhCache二级缓存 Ehcache是一种广泛使用的开源Java分布式缓存。主要面向通用缓存,Java EE和轻量级容器。它具有内存和磁盘存储,缓存加载器,缓存扩展,缓存异常处理程序,一个...

    ehcache-core-2.5.0.jar

    jar包,官方版本,自测可用

    ehcache-2.7.3-distribution.tar.gz

    标题"ehcache-2.7.3-distribution.tar.gz"表明这是一个包含EHCache 2.7.3版本的发行版压缩包,格式为tar.gz,这是一种常见的Linux/Unix系统中用于打包和压缩文件的格式。这个版本的EHCache是Java缓存系统的一个版本...

    ehcache-1.6.2-distribution.tar.gz

    首先,我们来看"ehcache-1.6.2-distribution.tar.gz"。这个压缩包包含了Ehcache的1.6.2版本,它是一个重要的里程碑,因为每个版本的更新都会带来新的功能和改进。1.6.2版可能包括了增强的性能、错误修复以及对当时...

    hibernate-ehcache-4.1.0.Final.jar

    hibernate-ehcache-4.1.0.Final.jar 是hibernate4.1使用缓存的jar包

    cvc-complex-type.2.4.d: Invalid content was found

    XML Schema是一种用于定义XML文档结构和数据类型的规范,它为XML提供了严格的验证机制。当解析器在处理XML文档时,会检查文档是否符合Schema中定义的规则。`cvc-complex-type`是XML Schema验证过程中关于复杂类型的...

    ehcache-core-2.6.10.jar

    ehcache-core-2.6.10.jar专用包,欢迎下载 ehcache-core-2.6.10.jar ehcache-core-2.6.10.jar ehcache-core-2.6.10.jarehcache-core-2.6.10.jarehcache-core-2.6.10.jar

    cas-client-support-distributed-ehcache-3.2.0.jar

    cas-client-support-distributed-ehcache-3.2.0.jar

    hibernate-ehcache-3.3.2.GA.jar

    hibernate-ehcache-3.3.2.GA.jar

    ehcache-2.8.0-distribution.tar.gz

    Ehcache是一个开源的、高性能的Java缓存解决方案,它为应用程序提供了本地内存缓存的能力,从而提高了数据访问的速度和效率。在Ehcache 2.8.0版本中,这个分布式缓存系统引入了许多关键特性,使得它成为了Java开发者...

    ehcache监控工具ehcache-monitor-kit-1.0.3

    1.解压缩到目录下,复制ehcache-monitor-kit-...启动被监控的web application和ehcache-monitor-kit-1.0.0\bin目录下的startup.bat(在windows环境下) 5.在浏览器中输入 http://localhost:9889/monitor/即可开始监控。

Global site tag (gtag.js) - Google Analytics