Hibernate 为什么在使用EhCache时,CPU达到100%?

Hibernate 为什么在使用EhCache时,CPU达到100%?,hibernate,caching,cpu,ehcache,Hibernate,Caching,Cpu,Ehcache,我使用EhCache Hibernate二级缓存进行查询和缓存。 一切都很好,但是我的CPU通过JMeter有100%到10个用户。 如果禁用EhCache,则CPU将变得合适。 有人对此有什么看法吗? 因此,EhCache没有提高性能,而是加载了我的CPU 这是我的依赖: <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-ehca

我使用EhCache Hibernate二级缓存进行查询和缓存。 一切都很好,但是我的CPU通过JMeter有100%到10个用户。 如果禁用EhCache,则CPU将变得合适。 有人对此有什么看法吗? 因此,EhCache没有提高性能,而是加载了我的CPU

这是我的依赖:

<dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-ehcache</artifactId>
        <version>4.3.8.Final</version>
    </dependency>

org.hibernate
休眠ehcache
4.3.8.最终版本
ehcache.xml

<?xml version="1.0" encoding="UTF-8"?>
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance "
         xsi:noNamespaceSchemaLocation="ehcache.xsd" updateCheck="true"
         name="cacheManager"
         monitoring="autodetect" dynamicConfig="true">

    <diskStore path="user.home/ehcacheEntriesStore" />

    <defaultCache maxEntriesLocalHeap="100" eternal="false"
                  timeToIdleSeconds="10" timeToLiveSeconds="10" diskSpoolBufferSizeMB="30"
                  maxEntriesLocalDisk="1000" diskExpiryThreadIntervalSeconds="1200"
                  memoryStoreEvictionPolicy="LRU" statistics="false">
        <persistence strategy="localTempSwap"/>
    </defaultCache>

    <cache name="serviceCache"
        maxBytesLocalHeap="500M"
        eternal="false"
        timeToIdleSeconds="300"
        overflowToDisk="true"
        maxElementsOnDisk="1000"
        memoryStoreEvictionPolicy="LRU"/>

    <cache  name="org.hibernate.cache.StandardQueryCache"
            maxEntriesLocalHeap="50000"
            eternal="false"
            timeToLiveSeconds="300">
        <persistence strategy="localTempSwap"/>
    </cache>
    <cache name="org.hibernate.cache.spi.UpdateTimestampsCache"
           maxEntriesLocalHeap="50000" eternal="true">
        <persistence strategy="localTempSwap"/>
    </cache>
</ehcache>

persistence.xml

<properties>
    <property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQL9Dialect"/>
    <property name="hibernate.transaction.jta.platform"
              value="org.hibernate.service.jta.platform.internal.JBossAppServerJtaPlatform"/>
    <property name="hibernate.hbm2ddl.auto" value="update"/>
    <property name="hibernate.show_sql" value="true"/>

    <property name="hibernate.cache.region.factory_class"
              value="org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory"/>
    <property name="hibernate.cache.use_second_level_cache" value="true"/>
    <property name="hibernate.cache.use_query_cache" value="true"/>
    <property name="net.sf.ehcache.configurationResourceName" value="ehcache.xml"/>
    <property name="hibernate.cache.default_cache_concurrency_strategy" value="transactional"/>
    <property name="hibernate.max_fetch_depth" value="4"/>
    <property name="hibernate.auto_close_session" value="true"/>
    <!--<property name="hibernate.transaction.flush_before_completion" value="true"/>-->
    <property name="hibernate.transaction.auto_close_session" value="true" />
    <property name="hibernate.c3p0.timeout" value="30" />

    <!--<property name="hibernate.generate_statistics" value="true"/>-->
    <!--<property name="hibernate.cache.use_structured_entries" value="true"/>-->

</properties


对于Ehcache 3.x来说,这是一个bug。 缓存统计信息线程池正在为每个统计信息创建一个新线程。因此线程本身所做的工作非常少,但是操作系统在创建线程时消耗了大部分CPU

它将在以后的版本中修复,但临时解决方法是将系统属性
org.ehcache.statisticsExecutor.poolSize
设置为
1


Ref:

总的来说,这是个好消息,您已经达到了近乎理想的CPU利用率。:)但是,如果这会减慢您的应用程序的速度,那么您应该使用探查器进行调查,并使用您的发现更新问题。