Caching Problem: out of memory
I have performed code profiling to check for any memory leak and memory usage behavior. I have used JConsole tool for code profiling and observed the following behavior:
Average JVM memory: ~220Mb
JVM memory during reload: ~580 Mb
This means, there is a surge of almost 160%-200% during cache reload. Attached herewith is the Heap Memory Usage graph for multiple reloads. I dont see any kind of memory leak. However, as we make one more copy of cache during reload, before swapping the instances, application consumes/requires lots of memory during reload.
Why OutOfMemory is coming during reload?
Suppose 1 GB is the memory assigned to JVM in production. On an average, 300Mb is consumed by cache and 400 by rest of the application. Now, at the time of reload cache memory usages will raise by 480Mb. Hence total memory required = 300 + 480 + 400 = 1180 Mb = OutOfMemory.
Conclusion: We need to improve the cache reload such that it should not require such big chunk of memory during reload. I have few approaches in my mind but none of them are foolproof. Could someone suggest anything?

