We are using ehcache 2.10.9.2 in our application. Recently we increased the total max entries in local heap for few caches from 5 Million to 5.5 Million.
The entries in the respective caches hit the max limit all the time, ehcache has to evict the LRU entries from the caches. During the eviction process, we have observed increase in CPU usage. Increase in CPU usage observed earlier also but its more visible with split of the Caches and increase of maximum entries in the Cache. Can someone explain why the CPU spikes are more visible now and application is unresponsive due to this.
Earlier Cache Configuration
<cache name="cache1"
maxEntriesLocalHeap="3000000"
eternal="false"
memoryStoreEvictionPolicy="off">
<persistence strategy="none"/>
</cache>
<cache name="cache2"
maxEntriesLocalHeap="2000000"
eternal="false"
memoryStoreEvictionPolicy="off">
<persistence strategy="none"/>
</cache>
Cache is separated as two different caches. Below is the recent Cache configuration
<cache name="cache1"
maxEntriesLocalHeap="3000000"
eternal="false"
memoryStoreEvictionPolicy="off">
<persistence strategy="none"/>
</cache>
<cache name="cache2"
maxEntriesLocalHeap="1500000"
eternal="false"
memoryStoreEvictionPolicy="off">
<persistence strategy="none"/>
</cache>
<cache name="cache3"
maxEntriesLocalHeap="1000000"
eternal="false"
memoryStoreEvictionPolicy="off">
<persistence strategy="none"/>
</cache>
The CPU spikes occur because increasing maxEntriesLocalHeap raises memory pressure and makes eviction (LRU management) more expensive. When caches constantly hit their limits, Ehcache must frequently scan and evict entries, causing higher GC activity and CPU usage. Splitting caches adds overhead from multiple eviction threads and metadata management, making the spikes more visible and the application less responsive.