Reputation: 1661
I have an application using EhCache with the following configuration
ehcache.strategy=localTempSwap
ehcache.maxBytesLocalHeap=100M
ehcache.maxBytesLocalDisk=1G
ehcache.setEternal=false
ehcache.timeToLiveSeconds=7200
ehcache.timeToIdleSeconds=1800
ehcache.sizeOfPolicyConfiguration.maxDepth=1000000
disk.store.enabled=true
ehcache.cachemanager.disk.store.dir=/tmp/ehcache/
My Cache is created as follows...
String maxBytesLocalHeap = configuration.getString("ehcache.maxBytesLocalHeap");
String maxBytesLocalDisk = configuration.getString("ehcache.maxBytesLocalDisk");
String strategy = configuration.getString("ehcache.strategy");
boolean eternal = configuration.getBoolean("ehcache.setEternal");
Long timeToLiveSeconds = configuration.getLong("ehcache.timeToLiveSeconds");
Integer maxDepth = configuration.getInt("ehcache.sizeOfPolicyConfiguration.maxDepth");
CacheConfiguration cacheConfiguration = new CacheConfiguration();
cacheConfiguration.setName("be_ehcache");
cacheConfiguration.setMaxBytesLocalHeap(maxBytesLocalHeap);
cacheConfiguration.setMaxBytesLocalDisk(maxBytesLocalDisk);
cacheConfiguration.setEternal(eternal);
cacheConfiguration.setTimeToLiveSeconds(timeToLiveSeconds);
cacheConfiguration.setMemoryStoreEvictionPolicyFromObject(MemoryStoreEvictionPolicy.LFU);
PersistenceConfiguration persistenceConfiguration = new PersistenceConfiguration();
persistenceConfiguration.strategy(strategy);
persistenceConfiguration.synchronousWrites(eternal);
cacheConfiguration.persistence(persistenceConfiguration);
SizeOfPolicyConfiguration sizeOfPolicyConfiguration = new SizeOfPolicyConfiguration();
sizeOfPolicyConfiguration.maxDepthExceededBehavior(MaxDepthExceededBehavior.ABORT);
sizeOfPolicyConfiguration.setMaxDepth(maxDepth);
cacheConfiguration.sizeOfPolicy(sizeOfPolicyConfiguration);
Cache cache = new Cache(cacheConfiguration);
My application runs with 1GB of memory (-Xmx1024m). My application crashes daily with OutOfMemoryErrors. When I look at the heap dump, I see an object net.sf.ehcache.store.cachingtier.PooledBasedBackEnd
when is generally 500MB in size (analyzed in VisualVM, calculating the Retained Size) and another object net.sf.ehcache.store.chm.SelectableConcurrentHashMap
which is generally right around 100MB.
We are currently running using ehcache-2.9.0 (yes, I know it's an old version...)
Why doesn't my configuration of the maximum storage on the heap work? Or better, how can I effectively limit the amount the total heap-size that ehcache will use for my cached data?
Upvotes: 0
Views: 228
Reputation: 1661
Found the root-cause. Another developer annotated the largest fields with @IgnoreSizeOf
. This had the result that for all practical purposes, we ignore allow ehcache (with our data-constellation) to consume memory without limits.
Upvotes: 1