My application correctly runs correctly on a server with 16 processor and 64 GB of Ram. I have multiple process and I try to limit the maximum heap at 8 Gbyte for my process.
My problem is that I have some form of producer-consumer pattern and I have to limit the producing rate or I will run out of memory, because the garbage collection for old generation occurs too rarely.
Through JVisualVM I can see that 90% of my memory occupation is given by CMS Old Gen, how can I force the concurrent Mark sweep to run a little bit more frequently?
@PeterLawrey comment is very relevant, since my application runs on the top of an Application server which is designed for event-driven processing and data partitioning, such as Terracotta or Coherence. It is likely that the underlying implementation includes a queueing system for event-processing.
My problem is that limiting the heap size is not a solution, because as I had experienced, instead of having more frequent garbage collection, the application runs out of memory.
I think by setting lower initiating occupancy you can trigger frequent collections.
-XX:CMSInitiatingOccupancyFraction=<nn>