Search code examples
javagarbage-collectionconcurrent-mark-sweep

Concurrent Mark Sweep Collection occurring not often enough


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.

  • When I monitor my application, I can see that after being running for 4 hours I have spent 7 minutes in ParNEW and 0.775 seconds in ConcurrentMarkSweep.
  • My heap occupation gets up to around 6GB then drops to 1GB then slowly start going up to 6GB then drop down again. The cycles are approximately of 10 minutes

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.


Solution

  • I think by setting lower initiating occupancy you can trigger frequent collections.

    -XX:CMSInitiatingOccupancyFraction=<nn>