0

I have a Openjdk 11.0.17 + Spring Boot application and this is my GC Configuration --XX:+UseG1GC -XX:MaxGCPauseMillis=1000 -Xms512m -Xmx8400m. When the application is running and the heap usage increases as per the incoming web traffic. But I am noticing that when there is no incoming traffic and no processing going on the total heap usage stays the same (high say 7gigs out of 8gig max heap) for longer times. When I take a heap dump the total usage reduces to less than 2% (say 512m). If the heap usage increases it kills the application with OOM (out of memory) error.

How to make G1GC garbage collector run more frequently ? or Is there a way to tune the GC to not make the application oom killed.

  • 1
    Can you explain why you decided to specify such a large max pause time? – Holger Jan 20 '23 at 15:41
  • How are you taking the heap dump? Usually that kind of tools force a FullGC before the heap dump process. Check your tool documentation to see if you are doing an undesired FullGC. That would explain mentioned memory reduction. – usuario Jan 20 '23 at 16:30
  • @Holger Do you think that longer GC pause time might be the reason for the delay in GC being run periodically ? – Vignesh Dhamodaran Jan 20 '23 at 16:47
  • @usuario HeapDump is taken using Jmap tool – Vignesh Dhamodaran Jan 20 '23 at 16:48
  • 1
    Well, there is an obvious relationship between shorter pause times and more frequent runs. But that doesn’t imply that this is relevant to your case of having no run when there’s no activity. There question was a different one. Why did you specify this option in the first place? – Holger Jan 20 '23 at 16:55

1 Answers1

2

But I am noticing that when there is no incoming traffic and no processing going on the total heap usage stays the same (high say 7gigs out of 8gig max heap) for longer times.

By default G1GC only triggers a collection when some of its regions exceed some thresholds, i.e. only tiggers while its allocating objects. Lowering the InitiatingHeapOccupancyPercent can trigger those earlier. Alternatively, if you upgrade to JDK12 or newer you can use G1PeriodicGCInterval for time-triggered collections in addition to allocation-triggered ones.

Another option is to switch to ZGC or Shenandoah which have options to trigger idle/background GCs to reduce heap size during idle periods.

or Is there a way to tune the GC to not make the application oom killed.

That problem generally is separate from high heap occupancy during idle periods. The GCs will try to perform emergency collections before issuing an OOM. So even if there was lots of floating garbage before the attempted allocation it would have been collected before throwing that error.

One possibility is that there's enough heap for steady-state operation but some load spike caused a large allocation that exceeded the available memory.

But you should enable GC logging to figure out the exact cause and what behavior lead up to it. There are multiple things that can cause OOMs, a few aren't even heap-related.

the8472
  • 40,999
  • 5
  • 70
  • 122