Caching Problem: out of memory

Problem: We have some set of tables that can be modified by anywhere and application doesnt have any control over it. We cache these tables and at a scheduled time we reload these tables. We are not loading tables one by one in the cache because tables are interdependent. We create another instance of entire cache and just swap the old instance with new instance. However, we are facing out of memory problem in production environment at reload time.

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?
[1597 byte] By [spandey1982] at [2007-11-20 11:35:03]
# 1 Re: Caching Problem: out of memory
At the risk of stating the obvious, unload the old cache before loading the new?

The cheapest, fastest, and most reliable components of a computer system are those that aren't there...
G. Bell
dlorde at 2007-11-10 2:14:05 >
# 2 Re: Caching Problem: out of memory
If we clean the old cache and start loading the new one then it will cause latency during reload. We don't want to lose any performance.
spandey1982 at 2007-11-10 2:15:07 >
# 3 Re: Caching Problem: out of memory
And I suppose assigning more memory to the application is also out of the question so you're left with either reloading and releasing in stages (unless all tables are ultimately dependant on all other tables) or reducing the reloading overhead which I can't advise on without knowing what you doing and how you are doing it.

What were your ideas?
keang at 2007-11-10 2:16:06 >