-XX:+UseG1GC 是 -Xincgc 的正确替代品吗?
目前,我们通过在 java 命令中添加 -Xincgc
来使用增量垃圾收集器.在 JDK 8 中,此开关已弃用.那么它的等效替代品是什么?-XX:+UseG1GC
?
Currently, we are using the incremental garbage collector by adding -Xincgc
to the java command. In JDK 8 this switch is deprecated. So what's the equivalent replacement for it? -XX:+UseG1GC
?
背景:该应用程序有一个 8GB 的堆,并创建了许多短生命周期的对象.我注意到它经常暂停几秒钟来进行垃圾收集.出于好奇,我添加了 -Xincgc
,发现停顿消失了,整体性能提高了约 4 倍.
Background: The application has a heap of 8GB and creates a lot of short living objects. I noticed that it often paused for some seconds to do garbage collection. Out of curiosity I added the -Xincgc
and found that the pauses were gone and overall performance improved ~4 times.
不幸的是,我没有找到任何关于 -Xincgc
触发什么类型的垃圾收集器的信息.有 CMS(并发标记和扫描)和新的 G1(垃圾优先).但是 -Xincgc
我能得到什么?
Unfortunately, I did not find any information about what type of garbage collector the -Xincgc
triggers. There's the CMS (Concurrent mark and sweep) and the new G1 (Garbage first). But what do I get with -Xincgc
?
推荐答案
对于 Oracle/OpenJDK 8,大多数机器上的默认收集器是并行吞吐量收集器,除了一些 32bit windows 机器,它可以是 Serial GC.
For Oracle/OpenJDK 8 the default collector on most machines is the Parallel Throughput Collector, except for some 32bit windows machines where it can be the Serial GC.
Xincgc 是增量模式的 CMS.您看到的主要好处可能是从吞吐量收集器切换到 CMS,而不是从为单核 CPU 设计的增量模式切换.
Xincgc is CMS in incremental mode. The main benefit you're seeing probably is caused by switching from the Throughput Collector to CMS, not from the incremental mode, which is designed for single-core CPUs.
增量模式也已弃用,所以只需通过 -XX:+ 启用 CMS使用ConcMarkSweepGC
看看是否适合你.
Incremental Mode is also deprecated, so simply enable CMS via -XX:+UseConcMarkSweepGC
and see if that works for you.
当然你也可以试试 G1GC,它也是为达到低暂停时间目标而设计的,它的优点是它不会像 CMS 那样受到碎片的影响,因此不太可能遇到并发模式故障而导致单个-线程停止世界集合.
Of course you can also try G1GC, which is also designed to reach low pause time goals and has the advantage that it does not suffer from fragmentation like CMS does and thus is less likely to experience concurrent mode failures which result in a single-threaded stop the world collection.
所以,尝试两者并测量.
So, try both and measure.
另请参阅:Oracle 的 Java 8 GC 调优指南一个>
相关文章