JDK11的ZGC小试牛刀

Posted 码匠的流水账

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了JDK11的ZGC小试牛刀相关的知识,希望对你有一定的参考价值。

本文主要试一下JDK11的ZGC

ZGC

ZGC全称是Z Garbage Collector,是一款可伸缩(scalable)的低延迟(low latency garbage)、并发(concurrent)垃圾回收器,旨在实现以下几个目标:

  • 停顿时间不超过10ms
  • 停顿时间不随heap大小或存活对象大小增大而增大
  • 可以处理从几百兆到几T的内存大小

设置

-server -XX:+UnlockExperimentalVMOptions -XX:+UseZGC -Xlog:age*,gc*=info:file=gc-%t.log:time,tid,tags:filecount=3,filesize=20m -Djava.io.tmpdir=/tmp'

log实例

[2018-07-22T13:17:59.526+0000][7][gc,init] Initializing The Z Garbage Collector
[2018-07-22T13:17:59.526+0000][7][gc,init] Version: 11-ea+22 (release)
[2018-07-22T13:17:59.526+0000][7][gc,init] NUMA Support: Disabled
[2018-07-22T13:17:59.526+0000][7][gc,init] CPUs: 2 total, 2 available
[2018-07-22T13:17:59.530+0000][7][gc,init] Memory: 2001M
[2018-07-22T13:17:59.530+0000][7][gc,init] Large Page Support: Disabled
[2018-07-22T13:17:59.530+0000][7][gc,init] Workers: 4 parallel, 4 concurrent
[2018-07-22T13:17:59.531+0000][7][gc,init] Heap backed by file: /memfd:java_heap
[2018-07-22T13:17:59.532+0000][7][gc,init] Available space on backing filesystem: N/A
[2018-07-22T13:17:59.540+0000][7][gc,init] Pre-touching: Disabled
[2018-07-22T13:17:59.540+0000][7][gc,init] Pre-mapping: 32M
[2018-07-22T13:17:59.576+0000][7][gc,init] Runtime Workers: 4 parallel
[2018-07-22T13:17:59.584+0000][7][gc     ] Using The Z Garbage Collector
[2018-07-22T13:18:01.071+0000][13][gc,start] GC(0) Garbage Collection (Warmup)
[2018-07-22T13:18:01.072+0000][19][gc,phases] GC(0) Pause Mark Start 0.370ms
[2018-07-22T13:18:01.102+0000][13][gc,phases] GC(0) Concurrent Mark 29.459ms
[2018-07-22T13:18:01.102+0000][19][gc,phases] GC(0) Pause Mark End 0.513ms
[2018-07-22T13:18:01.103+0000][13][gc,phases] GC(0) Concurrent Process Non-Strong References 0.410ms
[2018-07-22T13:18:01.103+0000][13][gc,phases] GC(0) Concurrent Reset Relocation Set 0.000ms
[2018-07-22T13:18:01.103+0000][13][gc,phases] GC(0) Concurrent Destroy Detached Pages 0.000ms
[2018-07-22T13:18:01.105+0000][13][gc,phases] GC(0) Concurrent Select Relocation Set 1.739ms
[2018-07-22T13:18:01.105+0000][13][gc,phases] GC(0) Concurrent Prepare Relocation Set 0.342ms
[2018-07-22T13:18:01.112+0000][19][gc,phases] GC(0) Pause Relocate Start 7.167ms
[2018-07-22T13:18:01.126+0000][13][gc,phases] GC(0) Concurrent Relocate 9.600ms
[2018-07-22T13:18:01.126+0000][13][gc,load  ] GC(0) Load: 0.09/0.43/0.23
[2018-07-22T13:18:01.128+0000][13][gc,mmu   ] GC(0) MMU: 2ms/0.0%, 5ms/0.0%, 10ms/27.3%, 20ms/61.6%, 50ms/83.9%, 100ms/92.0%
[2018-07-22T13:18:01.129+0000][13][gc,marking] GC(0) Mark: 4 stripe(s), 1 proactive flush(es), 2 terminate flush(es), 1 completion(s), 0 continuation(s) 
[2018-07-22T13:18:01.129+0000][13][gc,reloc  ] GC(0) Relocation: Successful, 3M relocated
[2018-07-22T13:18:01.129+0000][13][gc,nmethod] GC(0) NMethods: 379 registered, 0 unregistered
[2018-07-22T13:18:01.129+0000][13][gc,metaspace] GC(0) Metaspace: 14M used, 14M capacity, 14M committed, 16M reserved
[2018-07-22T13:18:01.129+0000][13][gc,ref      ] GC(0) Soft: 491 encountered, 0 discovered, 0 enqueued
[2018-07-22T13:18:01.129+0000][13][gc,ref      ] GC(0) Weak: 477 encountered, 334 discovered, 102 enqueued
[2018-07-22T13:18:01.129+0000][13][gc,ref      ] GC(0) Final: 57 encountered, 0 discovered, 0 enqueued
[2018-07-22T13:18:01.129+0000][13][gc,ref      ] GC(0) Phantom: 1229 encountered, 1227 discovered, 1223 enqueued
[2018-07-22T13:18:01.129+0000][13][gc,heap     ] GC(0)                Mark Start          Mark End        Relocate Start      Relocate End           High               Low         
[2018-07-22T13:18:01.129+0000][13][gc,heap     ] GC(0)  Capacity:       92M (18%)          96M (19%)          96M (19%)         102M (20%)         102M (20%)          92M (18%)    
[2018-07-22T13:18:01.129+0000][13][gc,heap     ] GC(0)   Reserve:       40M (8%)           40M (8%)           40M (8%)           40M (8%)           40M (8%)           40M (8%)     
[2018-07-22T13:18:01.129+0000][13][gc,heap     ] GC(0)      Free:      410M (82%)         406M (81%)         406M (81%)         448M (89%)         448M (89%)         400M (80%)    
[2018-07-22T13:18:01.129+0000][13][gc,heap     ] GC(0)      Used:       52M (10%)          56M (11%)          56M (11%)          14M (3%)           62M (12%)          14M (3%)     
[2018-07-22T13:18:01.129+0000][13][gc,heap     ] GC(0)      Live:         -                 3M (1%)            3M (1%)            3M (1%)             -                  -          
[2018-07-22T13:18:01.129+0000][13][gc,heap     ] GC(0) Allocated:         -                 4M (1%)            4M (1%)           12M (2%)             -                  -          
[2018-07-22T13:18:01.132+0000][13][gc,heap     ] GC(0)   Garbage:         -                48M (10%)          48M (10%)           4M (1%)             -                  -          
[2018-07-22T13:18:01.132+0000][13][gc,heap     ] GC(0) Reclaimed:         -                  -                 0M (0%)           44M (9%)             -                  -          
[2018-07-22T13:18:01.132+0000][13][gc          ] GC(0) Garbage Collection (Warmup) 52M(10%)->14M(3%)
[2018-07-22T13:18:02.172+0000][13][gc,start    ] GC(1) Garbage Collection (Warmup)
[2018-07-22T13:18:02.173+0000][19][gc,phases   ] GC(1) Pause Mark Start 0.776ms
[2018-07-22T13:18:02.198+0000][13][gc,phases   ] GC(1) Concurrent Mark 24.883ms
[2018-07-22T13:18:02.198+0000][19][gc,phases   ] GC(1) Pause Mark End 0.256ms
[2018-07-22T13:18:02.205+0000][13][gc,phases   ] GC(1) Concurrent Process Non-Strong References 6.484ms
[2018-07-22T13:18:02.205+0000][13][gc,phases   ] GC(1) Concurrent Reset Relocation Set 0.005ms
[2018-07-22T13:18:02.205+0000][13][gc,phases   ] GC(1) Concurrent Destroy Detached Pages 0.000ms
[2018-07-22T13:18:02.206+0000][13][gc,phases   ] GC(1) Concurrent Select Relocation Set 1.104ms
[2018-07-22T13:18:02.210+0000][13][gc,phases   ] GC(1) Concurrent Prepare Relocation Set 3.879ms
[2018-07-22T13:18:02.220+0000][19][gc,phases   ] GC(1) Pause Relocate Start 9.183ms
[2018-07-22T13:18:02.229+0000][13][gc,phases   ] GC(1) Concurrent Relocate 8.888ms
[2018-07-22T13:18:02.229+0000][13][gc,load     ] GC(1) Load: 0.09/0.43/0.23
[2018-07-22T13:18:02.229+0000][13][gc,mmu      ] GC(1) MMU: 2ms/0.0%, 5ms/0.0%, 10ms/8.2%, 20ms/54.1%, 50ms/79.6%, 100ms/89.8%
[2018-07-22T13:18:02.229+0000][13][gc,marking  ] GC(1) Mark: 4 stripe(s), 3 proactive flush(es), 1 terminate flush(es), 1 completion(s), 0 continuation(s) 
[2018-07-22T13:18:02.229+0000][13][gc,reloc    ] GC(1) Relocation: Successful, 6M relocated
[2018-07-22T13:18:02.229+0000][13][gc,nmethod  ] GC(1) NMethods: 572 registered, 0 unregistered
[2018-07-22T13:18:02.229+0000][13][gc,metaspace] GC(1) Metaspace: 22M used, 22M capacity, 23M committed, 24M reserved
[2018-07-22T13:18:02.229+0000][13][gc,ref      ] GC(1) Soft: 838 encountered, 0 discovered, 0 enqueued
[2018-07-22T13:18:02.229+0000][13][gc,ref      ] GC(1) Weak: 875 encountered, 259 discovered, 154 enqueued
[2018-07-22T13:18:02.229+0000][13][gc,ref      ] GC(1) Final: 57 encountered, 46 discovered, 0 enqueued
[2018-07-22T13:18:02.229+0000][13][gc,ref      ] GC(1) Phantom: 2544 encountered, 2541 discovered, 2536 enqueued
[2018-07-22T13:18:02.229+0000][13][gc,heap     ] GC(1)                Mark Start          Mark End        Relocate Start      Relocate End           High               Low         
[2018-07-22T13:18:02.229+0000][13][gc,heap     ] GC(1)  Capacity:      148M (29%)         152M (30%)         152M (30%)         158M (31%)         158M (31%)         148M (29%)    
[2018-07-22T13:18:02.229+0000][13][gc,heap     ] GC(1)   Reserve:       40M (8%)           40M (8%)           40M (8%)           40M (8%)           40M (8%)           40M (8%)     
[2018-07-22T13:18:02.229+0000][13][gc,heap     ] GC(1)      Free:      354M (71%)         350M (70%)         350M (70%)         448M (89%)         448M (89%)         344M (69%)    
[2018-07-22T13:18:02.229+0000][13][gc,heap     ] GC(1)      Used:      108M (22%)         112M (22%)         112M (22%)          14M (3%)          118M (24%)          14M (3%)     
[2018-07-22T13:18:02.229+0000][13][gc,heap     ] GC(1)      Live:         -                 6M (1%)            6M (1%)            6M (1%)             -                  -          
[2018-07-22T13:18:02.229+0000][13][gc,heap     ] GC(1) Allocated:         -                 4M (1%)            4M (1%)           14M (3%)             -                  -          
[2018-07-22T13:18:02.229+0000][13][gc,heap     ] GC(1)   Garbage:         -               101M (20%)         101M (20%)           3M (1%)             -                  -          
[2018-07-22T13:18:02.229+0000][13][gc,heap     ] GC(1) Reclaimed:         -                  -                 0M (0%)           98M (20%)            -                  -          
[2018-07-22T13:18:02.229+0000][13][gc          ] GC(1) Garbage Collection (Warmup) 108M(22%)->14M(3%)
[2018-07-22T13:18:03.670+0000][13][gc,start    ] GC(2) Garbage Collection (Warmup)
[2018-07-22T13:18:03.671+0000][19][gc,phases   ] GC(2) Pause Mark Start 0.676ms
[2018-07-22T13:18:03.731+0000][13][gc,phases   ] GC(2) Concurrent Mark 59.720ms
[2018-07-22T13:18:03.732+0000][19][gc,phases   ] GC(2) Pause Mark End 0.344ms
[2018-07-22T13:18:03.733+0000][13][gc,phases   ] GC(2) Concurrent Process Non-Strong References 1.265ms
[2018-07-22T13:18:03.733+0000][13][gc,phases   ] GC(2) Concurrent Reset Relocation Set 0.151ms
[2018-07-22T13:18:03.733+0000][13][gc,phases   ] GC(2) Concurrent Destroy Detached Pages 0.000ms
[2018-07-22T13:18:03.734+0000][13][gc,phases   ] GC(2) Concurrent Select Relocation Set 1.317ms
[2018-07-22T13:18:03.735+0000][13][gc,phases   ] GC(2) Concurrent Prepare Relocation Set 0.768ms
[2018-07-22T13:18:03.749+0000][19][gc,phases   ] GC(2) Pause Relocate Start 13.753ms
[2018-07-22T13:18:03.776+0000][13][gc,phases   ] GC(2) Concurrent Relocate 26.811ms
[2018-07-22T13:18:03.776+0000][13][gc,load     ] GC(2) Load: 0.33/0.47/0.25
[2018-07-22T13:18:03.776+0000][13][gc,mmu      ] GC(2) MMU: 2ms/0.0%, 5ms/0.0%, 10ms/0.0%, 20ms/29.5%, 50ms/71.8%, 100ms/85.2%
[2018-07-22T13:18:03.776+0000][13][gc,marking  ] GC(2) Mark: 4 stripe(s), 3 proactive flush(es), 1 terminate flush(es), 0 completion(s), 0 continuation(s) 
[2018-07-22T13:18:03.776+0000][13][gc,reloc    ] GC(2) Relocation: Successful, 8M relocated
[2018-07-22T13:18:03.776+0000][13][gc,nmethod  ] GC(2) NMethods: 1316 registered, 0 unregistered
[2018-07-22T13:18:03.776+0000][13][gc,metaspace] GC(2) Metaspace: 29M used, 29M capacity, 29M committed, 30M reserved
[2018-07-22T13:18:03.776+0000][13][gc,ref      ] GC(2) Soft: 1822 encountered, 0 discovered, 0 enqueued
[2018-07-22T13:18:03.776+0000][13][gc,ref      ] GC(2) Weak: 1354 encountered, 493 discovered, 51 enqueued
[2018-07-22T13:18:03.776+0000][13][gc,ref      ] GC(2) Final: 57 encountered, 0 discovered, 0 enqueued
[2018-07-22T13:18:03.776+0000][13][gc,ref      ] GC(2) Phantom: 2712 encountered, 2709 discovered, 2704 enqueued
[2018-07-22T13:18:03.776+0000][13][gc,heap     ] GC(2)                Mark Start          Mark End        Relocate Start      Relocate End           High               Low         
[2018-07-22T13:18:03.776+0000][13][gc,heap     ] GC(2)  Capacity:      196M (39%)         198M (39%)         198M (39%)         210M (42%)         210M (42%)         196M (39%)    
[2018-07-22T13:18:03.776+0000][13][gc,heap     ] GC(2)   Reserve:       40M (8%)           40M (8%)           40M (8%)           40M (8%)           40M (8%)           40M (8%)     
[2018-07-22T13:18:03.776+0000][13][gc,heap     ] GC(2)      Free:      306M (61%)         304M (61%)         304M (61%)         436M (87%)         436M (87%)         292M (58%)    
[2018-07-22T13:18:03.776+0000][13][gc,heap     ] GC(2)      Used:      156M (31%)         158M (31%)         158M (31%)          26M (5%)          170M (34%)          26M (5%)     
[2018-07-22T13:18:03.776+0000][13][gc,heap     ] GC(2)      Live:         -                12M (3%)           12M (3%)           12M (3%)             -                  -          
[2018-07-22T13:18:03.777+0000][13][gc,heap     ] GC(2) Allocated:         -                 2M (0%)            2M (0%)           18M (4%)             -                  -          
[2018-07-22T13:18:03.777+0000][13][gc,heap     ] GC(2)   Garbage:         -               143M (29%)         143M (29%)          11M (2%)             -                  -          
[2018-07-22T13:18:03.777+0000][13][gc,heap     ] GC(2) Reclaimed:         -                  -                 0M (0%)          132M (26%)            -                  -          
[2018-07-22T13:18:03.777+0000][13][gc          ] GC(2) Garbage Collection (Warmup) 156M(31%)->26M(5%)

小结

ZGC在如下几个阶段是concurrent的:

  • Marking
  • Relocation/Compaction
  • Relocation Set Selection
  • Reference Processing
  • JNI WeakRefs Cleaning

doc

  • openjdk zgc wiki
  • ZGC - Oracle’s Large-Heap Garbage Collector