【发布时间】:2017-11-16 18:28:05
【问题描述】:
我使用 EhCache Hibernate 二级缓存和查询缓存。 一切都很好,但是我通过 JMeter 拥有 100% 最多 10 个用户的 CPU。 如果禁用 EhCache,则 CPU 变得合适。 有人对此有任何意见吗? 因此,EhCache 并没有提高性能,而是加载了我的 CPU。
这是我的依赖:
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-ehcache</artifactId>
<version>4.3.8.Final</version>
</dependency>
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
>
【问题讨论】:
-
总的来说,这是个好消息,您已经达到了几乎理想的 CPU 利用率。 :) 但是,如果这会降低您的应用程序速度,那么您应该使用分析器对其进行调查,并根据您的发现更新问题。
-
我正在使用分析器 end find next snag.gy/kRpDI.jpg .
标签: hibernate caching cpu ehcache