Marcus
Marcus

Reputation: 2103

JBoss EAP 7: increasing the second level cache size for a JPA application

Given JBoss 7 and an application with enabled second level caching in persistence.xml:

<property name="hibernate.cache.use_second_level_cache" value="true" />
<property name="hibernate.cache.use_query_cache" value="true" />
<property name="hibernate.cache.region.factory_class" value="org.hibernate.cache.infinispan.JndiInfinispanRegionFactory" />
<property name="hibernate.cache.infinispan.cachemanager" value="java:jboss/infinispan/container/hibernate" />
<property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.JBossTransactionManagerLookup" />
<property name="hibernate.cache.default_cache_concurrency_strategy" value="transactional" />

Given also @Cacheable on some entities and @org.hibernate.annotations.Cache(usage = CacheConcurrencyStrategy.TRANSACTIONAL) on some relations.

Because performance is bad I turned on

<property name="hibernate.generate_statistics" value="true" />

in persistence.xml.

In the JPA statistics I see lots of cache misses, even for entities I accessed seconds ago. So I assume the cache size is not big enough. How can I increase it?

I tried

<property name="hibernate.cache.infinispan.entity.eviction.max_entries" value="200000"/>
<property name="hibernate.cache.infinispan.entity.expiration.lifespan" value="1800000"/>
<property name="hibernate.cache.infinispan.entity.expiration.max_idle" value= "1200000"/>

in persistence.xml but still the same with the misses.

Clarification: Sorry, I meant JBoss EAP 7 (from 2016), not JBoss AS 7 (from 2011).

Upvotes: 0

Views: 775

Answers (1)

Radim Vansa
Radim Vansa

Reputation: 5888

Unless you use custom regions (through org.hibernate.annotations.Cache), setting hibernate.cache.infinispan.entity.eviction.max_entries is the correct approach. You can even disable eviction completely by setting that to -1.

You can see a cache miss after you've modified the entity; the cache is invalidated after each write and expects to be refilled upon next read. The other option is that something is calling evictEntityRegions or another operation that ends up calling evictAll or removeAll. You'd have to debug into these methods or install Byteman rules to find out the culprit if this is the case.

Upvotes: 2

Related Questions