JVM NewRatio与SurvivorRatio

Introduction

-XX:NewRatio:新生代(Eden + 2*S)与老年代(不包括永久区)的比值。假如设置为4,4表示新生代:老年代 = 1:4,意思是老年代占 4/5。


-XX:SurvivorRatio:2个Survivor区和Eden区的比值,假如设置为8,8表示两个Survivor:Eden = 2:8,每个Survivor占 1/10。


如何确定 NewRatio 和 SurvivorRatio 的最优值

JVM Options:-server -Xmx4g -Xms4g -XX:+UseParNewGC -XX:+UseConcMarkSweepGC -XX:+ExplicitGCInvokesConcurrent -XX:NewRatio=1 -XX:SurvivorRatio=5 -XX:MetaspaceSize=32m -XX:+PrintGCDetails -XX:+PrintGCTimeStamps -verbose:gc -Xloggc:/opt/logs/gc/gc.lo

初始化GC

1
2
3
4
5
6
7
8
9
10
2.459: [CMS-concurrent-mark: 0.001/0.001 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
2.459: [CMS-concurrent-preclean-start]
2.462: [CMS-concurrent-preclean: 0.004/0.004 secs] [Times: user=0.02 sys=0.00, real=0.00 secs]
2.462: [CMS-concurrent-abortable-preclean-start]
CMS: abort preclean due to time 7.523: [CMS-concurrent-abortable-preclean: 0.325/5.061 secs] [Times: user=7.40 sys=3.62, real=5.07 secs]
7.524: [GC (CMS Final Remark) [YG occupancy: 1108516 K (1797568 K)]7.524: [Rescan (parallel) , 0.2107730 secs]7.735: [weak refs processing, 0.0000480 secs]7.735: [class unloading, 0.0094960 secs]7.744: [scrub symbol table, 0.0088638 secs]7.753: [scrub string table, 0.0007320 secs][1 CMS-remark: 0K(2097152K)] 1108516K(3894720K), 0.2317200 secs] [Times: user=1.71 sys=0.00, real=0.23 secs]
7.756: [CMS-concurrent-sweep-start]
7.756: [CMS-concurrent-sweep: 0.000/0.000 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
7.756: [CMS-concurrent-reset-start]
7.785: [CMS-concurrent-reset: 0.029/0.029 secs] [Times: user=0.01 sys=0.05, real=0.03 secs]
  • 新生代大小:1797568 KB = 1755.43 MB,当前已经占用 1108516 KB = 1082 MB;

[GC (Allocation Failure)

1
[GC (Allocation Failure) 938.900: [ParNew: 1507180K->7820K(1797568K), 0.0121347 secs] 1594391K->95047K(3894720K), 0.0122274 secs] [Times: user=0.05 sys=0.00, real=0.01 secs]
  • [GC与[Full GC:表示GC类型;
  • [ParNew: 1507180K->7820K(1797568K):[ParNew表示GC发生的区域,显示的区域与使用的GC收集器密切相关。1507180K 表示收集前该内存区域(新生代)已经使用的容量,820K(1797568K)表示GC后该内存区域已使用容量(该内存区域总容量)
  • 1594391K->95047K(3894720K):表示GC前堆已使用容量->GC后堆已使用容量(堆总容量)
  • 估算出老年大大小:3894720K - 1507180K = 2387540K = 2331.58 MB

433.231: [GC (Allocation Failure) 433.231: [ParNew: 2255562K->8497K(2696384K), 0.0112992 secs] 2342952K->95887K(3744960K), 0.0114044 secs] [Times: user=0.08 sys=0.00, real=0.01 secs]

老年代大小 = 1 GB


Reference

https://plumbr.io/handbook/gc-tuning-in-practice