When using the G1GC in JVM 8, Full GC (Allocation Failure) happens before memory is Exhausted. And it appear every 30 minutes, every time it stop the application 6-10 second, about 300-500 requests were timeout failure, that's badly for me.
I don't understand why [Full GC (Allocation Failure) 16G->13G(20G), 8.9794231 secs]
could happen. allocation request: 304 bytes
,but the heap actually still have 4G space, why can’t it be allocated?
I suspected it was a fragmentation problem, but I don't konw how to verify. Any verification method is welcome.
The last Full GC detail is:
2019-12-11T18:42:12.687+0800: 1312029.392: [GC pause (G1 Evacuation Pause) (young) (initial-mark)
Desired survivor size 67108864 bytes, new threshold 3 (max 3)
1312029.393: [G1Ergonomics (CSet Construction) start choosing CSet, _pending_cards: 37379, predicted base time: 20.39 ms, remaining time: 69.61 ms, target pause time: 90.00 ms]
1312029.393: [G1Ergonomics (CSet Construction) add young regions to CSet, eden: 0 regions, survivors: 0 regions, predicted young region time: 0.00 ms]
1312029.393: [G1Ergonomics (CSet Construction) finish choosing CSet, eden: 0 regions, survivors: 0 regions, old: 0 regions, predicted pause time: 20.39 ms, target pause time: 90.00 ms]
, 0.0180293 secs]
[Parallel Time: 12.8 ms, GC Workers: 16]
[GC Worker Start (ms): Min: 1312029393.4, Avg: 1312029393.5, Max: 1312029393.6, Diff: 0.2]
[Ext Root Scanning (ms): Min: 3.1, Avg: 3.9, Max: 11.9, Diff: 8.8, Sum: 62.0]
[Update RS (ms): Min: 0.0, Avg: 5.0, Max: 6.1, Diff: 6.1, Sum: 80.2]
[Processed Buffers: Min: 0, Avg: 9.2, Max: 14, Diff: 14, Sum: 148]
[Scan RS (ms): Min: 0.0, Avg: 0.0, Max: 0.0, Diff: 0.0, Sum: 0.0]
[Code Root Scanning (ms): Min: 0.0, Avg: 0.0, Max: 0.0, Diff: 0.0, Sum: 0.0]
[Object Copy (ms): Min: 0.2, Avg: 0.3, Max: 0.5, Diff: 0.3, Sum: 5.0]
[Termination (ms): Min: 0.0, Avg: 3.3, Max: 3.8, Diff: 3.8, Sum: 52.4]
[Termination Attempts: Min: 1, Avg: 1.0, Max: 1, Diff: 0, Sum: 16]
[GC Worker Other (ms): Min: 0.0, Avg: 0.0, Max: 0.0, Diff: 0.0, Sum: 0.2]
[GC Worker Total (ms): Min: 12.4, Avg: 12.5, Max: 12.6, Diff: 0.2, Sum: 199.9]
[GC Worker End (ms): Min: 1312029406.0, Avg: 1312029406.0, Max: 1312029406.0, Diff: 0.0]
[Code Root Fixup: 0.0 ms]
[Code Root Purge: 0.0 ms]
[Clear CT: 0.2 ms]
[Other: 5.0 ms]
[Choose CSet: 0.0 ms]
[Ref Proc: 2.4 ms]
[Ref Enq: 0.2 ms]
[Redirty Cards: 0.2 ms]
[Humongous Register: 0.4 ms]
[Humongous Reclaim: 0.0 ms]
[Free CSet: 0.0 ms]
[Eden: 0.0B(1024.0M)->0.0B(1024.0M) Survivors: 0.0B->0.0B Heap: 16.4G(20.0G)->16.4G(20.0G)]
Heap after GC invocations=452782 (full 1):
garbage-first heap total 20971520K, used 17217092K [0x00000002c0000000, 0x00000002c2001400, 0x00000007c0000000)
region size 32768K, 0 young (0K), 0 survivors (0K)
Metaspace used 60984K, capacity 61408K, committed 62156K, reserved 1105920K
class space used 6123K, capacity 6258K, committed 6400K, reserved 1048576K
}
[Times: user=0.00 sys=0.00, real=0.01 secs]
2019-12-11T18:42:12.705+0800: 1312029.411: [GC concurrent-root-region-scan-start]
2019-12-11T18:42:12.705+0800: 1312029.411: [GC concurrent-root-region-scan-end, 0.0000510 secs]
2019-12-11T18:42:12.705+0800: 1312029.411: [GC concurrent-mark-start]
2019-12-11T18:42:12.705+0800: 1312029.411: Total time for which application threads were stopped: 0.0282629 seconds, Stopping threads took: 0.0003029 seconds
2019-12-11T18:42:12.706+0800: 1312029.412: Application time: 0.0009042 seconds
1312029.419: [G1Ergonomics (Heap Sizing) attempt heap expansion, reason: allocation request failed, allocation request: 304 bytes]
1312029.419: [G1Ergonomics (Heap Sizing) expand the heap, requested expansion amount: 33554432 bytes, attempted expansion amount: 33554432 bytes]
1312029.419: [G1Ergonomics (Heap Sizing) did not expand the heap, reason: heap already fully expanded]
{Heap before GC invocations=452782 (full 1):
garbage-first heap total 20971520K, used 17217092K [0x00000002c0000000, 0x00000002c2001400, 0x00000007c0000000)
region size 32768K, 0 young (0K), 0 survivors (0K)
Metaspace used 60984K, capacity 61408K, committed 62156K, reserved 1105920K
class space used 6123K, capacity 6258K, committed 6400K, reserved 1048576K
2019-12-11T18:42:12.714+0800: 1312029.420: [Full GC (Allocation Failure) 16G->13G(20G), 8.9794231 secs]
[Eden: 0.0B(1024.0M)->0.0B(1248.0M) Survivors: 0.0B->0.0B Heap: 16.4G(20.0G)->13.1G(20.0G)], [Metaspace: 60984K->60984K(1105920K)]
Heap after GC invocations=452783 (full 2):
garbage-first heap total 20971520K, used 13750684K [0x00000002c0000000, 0x00000002c2001400, 0x00000007c0000000)
region size 32768K, 0 young (0K), 0 survivors (0K)
Metaspace used 60984K, capacity 61408K, committed 62156K, reserved 1105920K
class space used 6123K, capacity 6258K, committed 6400K, reserved 1048576K
}
[Times: user=6.25 sys=2.34, real=8.98 secs]
2019-12-11T18:42:21.694+0800: 1312038.400: Total time for which application threads were stopped: 8.9877650 seconds, Stopping threads took: 0.0001943 seconds
2019-12-11T18:42:21.695+0800: 1312038.400: [GC concurrent-mark-abort]
2019-12-11T18:42:21.931+0800: 1312038.637: Application time: 0.2366224 seconds
{Heap before GC invocations=452783 (full 2):
garbage-first heap total 20971520K, used 15028636K [0x00000002c0000000, 0x00000002c2001400, 0x00000007c0000000)
region size 32768K, 39 young (1277952K), 0 survivors (0K)
Metaspace used 60984K, capacity 61408K, committed 62156K, reserved 1105920K
class space used 6123K, capacity 6258K, committed 6400K, reserved 1048576K
The JVM GC arguments:
-XX:+UseG1GC
-Xmx20480m
-XX:+UnlockExperimentalVMOptions
-XX:MaxGCPauseMillis=90
-XX:ConcGCThreads=4
-XX:ParallelGCThreads=16
-XX:MaxTenuringThreshold=3
-XX:G1HeapRegionSize=32m
-XX:InitiatingHeapOccupancyPercent=70
-XX:G1NewSizePercent=5
-XX:G1MaxNewSizePercent=30
-XX:G1MixedGCCountTarget=16
-XX:G1OldCSetRegionThresholdPercent=3
-XX:G1HeapWastePercent=15
why this arguments is set up:
1. IHOP is 70%, because there are so many caches and requests in my program (about 65%);
2. MaxNewSizePercent can be smaller, but it should not causes full gc;
3. -XX:G1MixedGCCountTarget and -XX:G1OldCSetRegionThresholdPercent combined effect is that 16 collections occur in a mixed GC, each time 600M, Considering that there is 13G of resident memory, 9.6G each time is an acceptable number;
4. And -XX:G1HeapWastePercent is 15%, actually it bothers me too, there are many large objects (more than 16M) in my process,so the only reason for me to set it up is to avoid mixed gc too frequently.
But i can't find the reason why this full gc happen from argument above. Any advice or suggestion will be very appreciated!