Video in progress

Strong Middle ⚙️ JVM and memory

What are these G1 log lines saying, and which one worries you?

[gc] GC(310) Pause Young (Normal) (G1 Evacuation Pause) 3021M->2890M(4096M) 35.112ms
[gc] GC(311) Pause Young (Concurrent Start) (G1 Humongous Allocation) 3102M->2950M(4096M) 41.870ms
[gc] GC(312) Concurrent Mark Cycle
[gc] GC(313) Pause Young (Normal) (G1 Evacuation Pause) (Evacuation Failure: Allocation) 3990M->4060M(4096M) 210.442ms
[gc] GC(314) Pause Full (G1 Compaction Pause) 4060M->2710M(4096M) 2840.311ms
[gc] GC(312) Concurrent Mark Cycle 1520.004ms

The young pauses are normal, but to-space exhausted and the Full GC after it mean the live objects the application produces don't fit in the heap. Now you need to check Old occupancy, the allocation rate and humongous allocations.

📖 Answer

Let's read the lines one by one.

3021M->2890M(4096M) 35ms: after the young GC, 2.9 GB remains in the heap. So the collection freed only 130 MB. That means the live part is big, the first signal.

(G1 Humongous Allocation): the GC started because of an attempt to create a big object. Someone is allocating an array larger than half a region.

(Evacuation Failure: Allocation): older JDKs logged this as "to-space exhausted". G1 couldn't find a free region to move the live objects into. The pause jumped to 210 ms, and the heap filled up.

Pause Full (G1 Compaction Pause) 2840ms: the worst line. Everything stopped, for almost 3 seconds. The result is 2.7 GB, so about 2.7 GB was really alive. For a 4 GB heap that is very dense.

And at the end, concurrent marking finished in 1.5 seconds, but too late. The application filled up Old before marking finished.

What I do:

  1. If the live set is 2.7 GB, making the heap 6-8 GB is the first quick fix.
  2. I look for humongous allocations (-Xlog:gc+humongous=debug, JFR), often collecting a whole response into a byte[].
  3. With a heap dump or class histogram I look at what is in that 2.7 GB. A cache with no bound, probably.
  4. Only after that do I think about flags like IHOP or ConcGCThreads.