0
votes

We have a JVM heap issue in the production server. When we took the heap dump and analyzed the report, we found that more than 80% of the heap size is exhausted by the Ehcache objects and server become slow. We have suspected that memory leak or accumulating the cache objects without clearing the old caches. The site is very high volume site hence the number of caches would have increased.

I want to review the meaning of this configurations and suggest if this has something to do with that issue:

<ehcache>
 <diskStore path="java.io.tmpdir" />
 <defaultCache maxElementsInMemory="10" eternal="false"
    timeToIdleSeconds="120" timeToLiveSeconds="120" overflowToDisk="true" />

  <cache name="name1" maxElementsInMemory="50" eternal="false" overflowToDisk="true" timeToIdleSeconds="0" timeToLiveSeconds="86400" />
  <cache name="name2" maxElementsInMemory="50" eternal="false" overflowToDisk="true" timeToIdleSeconds="0" timeToLiveSeconds="86400" />
  <cache name="name3" maxElementsInMemory="50000" eternal="true" overflowToDisk="true"/>
  <cache name="name4" maxElementsInMemory="500" eternal="true" overflowToDisk="true"/>
  <cache name="name5" maxElementsInMemory="500" eternal="true" overflowToDisk="true"/>
  <cache name="name6" maxElementsInMemory="50000" eternal="true" overflowToDisk="true"/>
  <cache name="name7" maxElementsInMemory="50000" eternal="true" overflowToDisk="true"/>
</ehcache>

In the Java class I have the following implementation:

 @Cacheable("name6")
    public ServiceResponse getQualifiedProducts(
            ValueObject parameterObject, List < Input > list)
    {
        return cachedService.getQualifiedProducts(parameterObject, list);
    }

Any suggestions would be thankful.

Update: What is the significance of overflowToDisk="true". I don't have any disk store configured. How it will impact the performance?

1
overflowToDisk="true" means that if the cache size becomes too big, some of the objects are going to be evicted to disk. The impact of performance is twofold. First, it's going to a have negative impact on the speed of accessing cache elements as reading from the disk can be 20-100 times slower then from memory. Second, the app performance may benefit because it's still reading from the cache. Try setting overflowToDisk="false" and see if this helps. If nothing works, you could give a shot to Cacheonix cacheonix.org that I'm a contributor to. - Slava Imeshev

1 Answers

1
votes

The example you gave of cache content is a ServiceResponse object. Do you know how big that object is? Does it contain references to types that are linked to the frameworks you use? Or is it pure business data?

This is the kind of investigation you need to perform in order to understand what ends up referenced by the cache and how this impacts your memory usage.

As a general advice, you want to cache objects that are yours, so that you can control their size precisely.

As for the overflowToDisk=true, it will be applied, as you have a disk store configured in the xml snippet you shared.

But while it says overflow for backwards dependency reasons, it no longer behaves like that since Ehcache 2.6.0 at least. The current Ehcache model is that all mappings exist in the slower store - disk here - to give you more predictable latency. And when a mapping is accessed, it is copied to heap for faster retrieval on subsequent hits.