一次服务启动gc优化
默认启动:
nohup java -XX:+PrintGCDetails -Xloggc:gc.txt -jar xgzt-main-1.0.2.jar --spring.profiles.active=dev &

14次younggc,2次fullgc
gc.txt:

jinfo:

=========================分析=========================
可以看到:
堆的最大最小值不一样,导致频繁gc扩容
两次fullgc,老年代未明显下降,仅是元空间gc
新生代初始 22M,最大357M,使用230M
堆初始 67M, 最大1G,使用255M
元空间 初始值根据经验可能20m,最大1g,使用34M
措施:
加大堆和新生代初始值
追加元空间初始值
====================================================
-Xmx1200m -Xms1200m -Xmn600m -XX:MetaspaceSize=64m XX:MaxMetaspaceSize=64m
nohup java -XX:+PrintGCDetails -Xmx1200m -Xms1200m -Xmn600m -XX:MetaspaceSize=64m -XX:MaxMetaspaceSize=64m -Xloggc:gc.txt -jar xgzt-main-1.0.2.jar --spring.profiles.active=dev &

2次younggc,0次fullgc
gc.txt:

jinfo:

ps:若用-Xmx600m -Xms600m -Xmn300m
5次young gc 0次full gc
若用-Xmx300m -Xms300m -Xmn150m
10次ygc 0 fgc
2.788: [GC (Allocation Failure) [PSYoungGen: 115712K->10008K(134656K)] 115712K->10080K(288256K), 0.0191347 secs] [Times: user=0.04 sys=0.01, real=0.02 secs]
3.934: [GC (Allocation Failure) [PSYoungGen: 125720K->10225K(134656K)] 125792K->10321K(288256K), 0.0181796 secs] [Times: user=0.04 sys=0.01, real=0.02 secs]
5.060: [GC (Allocation Failure) [PSYoungGen: 125937K->12179K(134656K)] 126033K->12283K(288256K), 0.0306665 secs] [Times: user=0.07 sys=0.01, real=0.03 secs]
6.090: [GC (Allocation Failure) [PSYoungGen: 127891K->12716K(134656K)] 127995K->12836K(288256K), 0.0216041 secs] [Times: user=0.04 sys=0.00, real=0.02 secs]
7.888: [GC (Allocation Failure) [PSYoungGen: 128428K->18942K(134656K)] 128548K->19965K(288256K), 0.0299145 secs] [Times: user=0.09 sys=0.01, real=0.03 secs]
9.286: [GC (Allocation Failure) [PSYoungGen: 134654K->18927K(125440K)] 135677K->23147K(279040K), 0.0563967 secs] [Times: user=0.12 sys=0.00, real=0.05 secs]
10.229: [GC (Allocation Failure) [PSYoungGen: 125423K->16467K(130048K)] 129643K->26405K(283648K), 0.0407241 secs] [Times: user=0.11 sys=0.00, real=0.04 secs]
10.869: [GC (Allocation Failure) [PSYoungGen: 122963K->14942K(131584K)] 132901K->28230K(285184K), 0.0214642 secs] [Times: user=0.08 sys=0.01, real=0.02 secs]
11.536: [GC (Allocation Failure) [PSYoungGen: 123486K->7502K(130560K)] 136774K->30447K(284160K), 0.0335069 secs] [Times: user=0.09 sys=0.01, real=0.03 secs]
15.261: [GC (Allocation Failure) [PSYoungGen: 116046K->11386K(131072K)] 138991K->38314K(284672K), 0.0176902 secs] [Times: user=0.05 sys=0.01, real=0.02 secs]
xx参考启动后服务实际使用情况和注释1
永久带参考书155p和注释2
参考:
JVM内存设置多大合适?Xmx和Xmn如何设置?
https://blog.csdn.net/losetowin/article/details/78569001
fullgc问题解决:Full GC (Metadata GC Threshold)
https://blog.csdn.net/liubenlong007/article/details/78143285
浙公网安备 33010602011771号