Java CMS 被忽略,取而代之的是 Full GC

标签 java garbage-collection jvm

我正在运行一个使用 CMS 作为终身收集器的 Java 服务器。在负载测试下运行,我大约每 1 秒看到一次年轻 Collection ,大约每 5 米看到一次永久(并发)。这很好。

当我以大约 1/2 容量的实际流量运行时,我大约每 4 秒收集一次年轻集合,大约每 7 米收集一次终身收集(!并行,停止世界!)。为什么 JVM 决定进行完全停止世界收集而不是使用 CMS 收集器?

从 gc.log 中,您可以看到“Full GC”正在运行,并且需要 3 秒才能完成。这里没有并发模式故障。没有明确请求集合。

1350.596: [GC 1350.596: [ParNew
Desired survivor size 119275520 bytes, new threshold 3 (max 3)
- age   1:   34779376 bytes,   34779376 total
- age   2:   17072392 bytes,   51851768 total
- age   3:   24120992 bytes,   75972760 total
: 1765625K->116452K(1864192K), 0.1560370 secs] 3887120K->2277489K(5009920K), 0.1561920 secs] [Times: user=0.40 sys=0.04, real=0.16 secs] 
1355.106: [GC 1355.107: [ParNew
Desired survivor size 119275520 bytes, new threshold 3 (max 3)
- age   1:   44862680 bytes,   44862680 total
- age   2:   20363280 bytes,   65225960 total
- age   3:   16908840 bytes,   82134800 total
: 1747684K->123571K(1864192K), 0.1068880 secs] 3908721K->2307790K(5009920K), 0.1070130 secs] [Times: user=0.29 sys=0.04, real=0.11 secs] 
1356.106: [Full GC 1356.106: [CMS: 2184218K->1268401K(3145728K), 3.0678070 secs] 2682861K->1268401K(5009920K), [CMS Perm : 145090K->145060K(262144K)], 3.0679600 secs] [Times: user=3.05 sys=0.02, real=3.07 secs] 
1361.375: [GC 1361.375: [ParNew
Desired survivor size 119275520 bytes, new threshold 3 (max 3)
- age   1:   33708472 bytes,   33708472 total
: 1631232K->84465K(1864192K), 0.0189890 secs] 2899633K->1352866K(5009920K), 0.0191530 secs] [Times: user=0.19 sys=0.00, real=0.02 secs] 
1365.587: [GC 1365.587: [ParNew
Desired survivor size 119275520 bytes, new threshold 3 (max 3)
- age   1:   33475320 bytes,   33475320 total
- age   2:   22698536 bytes,   56173856 total
: 1715697K->67421K(1864192K), 0.0229540 secs] 2984098K->1335822K(5009920K), 0.0231240 secs] [Times: user=0.25 sys=0.00, real=0.03 secs] 

这里是 JVM 标志:

-server -Xss256K -Xms5120M -Xmx5120M -XX:NewSize=2048M -XX:MaxNewSize=2048M
-XX:SurvivorRatio=7 -XX:+UseConcMarkSweepGC -XX:+UseParNewGC
-XX:+CMSParallelRemarkEnabled -XX:CMSInitiatingOccupancyFraction=80
-XX:+UseCMSInitiatingOccupancyOnly -XX:CMSFullGCsBeforeCompaction=1
-XX:SoftRefLRUPolicyMSPerMB=73 -verbose:gc -XX:+PrintGCDetails
-XX:+PrintGCTimeStamps -XX:+PrintTenuringDistribution -Xloggc:logs/gc.log
-XX:MaxPermSize=256m -XX:PermSize=256m -XX:MaxTenuringThreshold=3

最佳答案

如果你的survivor space不够大,会触发Full GC。 (好像是在提示he survivor ratio)

要么您需要降低幸存者比率,要么更好的解决方案可能是增加您的 NewSize,以便从伊甸园空间中幸存下来的对象更少。我有一个 6 GB 的伊甸园空间;)

关于Java CMS 被忽略,取而代之的是 Full GC,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5719272/

相关文章:

java - 查找数组中单词之间的最小距离

java - 何时返回 Iterable<String> 而不是 List、Set、Collection?

java - 如何为每个正在执行的 Java 程序实现安全策略

garbage-collection - JNI 代码即与垃圾收集并发执行。

java - 在大型项目中编译单个java类会影响当前正在运行的应用程序

java - 如何在android中将时间戳转换为日期?

java - 连接池策略 : Good, 坏还是丑?

git - 安全运行 git gc

c# - 如何在 C# 中管理确定性终结?

objective-c - 是否收集了 Linux 上的 Objective-C 垃圾?