本文建议使用-XX:+UseParNewGC
“To enable a parallel young generation GC with the concurrent GC”。
我的困惑是,为了同时启用并行和并发 GC,我应该
- 使用
-XX:+UseParNewGC
或 - 同时使用
-XX:+UseParNewGC
和-XX:+UseConcMarkSweepGC
?
附言
我正在使用 JVM 6。
本文建议使用-XX:+UseParNewGC
“To enable a parallel young generation GC with the concurrent GC”。
我的困惑是,为了同时启用并行和并发 GC,我应该
-XX:+UseParNewGC
或-XX:+UseParNewGC
和 -XX:+UseConcMarkSweepGC
?我正在使用 JVM 6。
由于您链接的文档是针对 1.4.2 VM 的,因此我假设您正在使用它(JVM 5 和 6 的行为不同)。
来自http://java.sun.com/docs/hotspot/gc1.4.2/
如果在命令行上使用 -XX:+UseConcMarkSweepGC 则标志 UseParNewGC 也设置为 true,如果它没有在命令行上显式设置
所以答案是你只需要使用 -XX:+UseConcMarkSweepGC 就可以启用并发收集器和并行年轻代收集器。
编辑:对于 Java 6,相同的标志 (-XX:+UseConcMarkSweepGC) 启用并发收集器。你想要的收集器的选择取决于几件事,你应该测试不同的配置。但是有一些非常一般的指导方针。如果您有单处理器、单线程机器,那么您应该使用串行收集器(某些配置的默认设置,可以使用 -XX:+UseSerialGC 显式启用)。对于您的工作负载基本上受 CPU 限制的多处理器机器,请使用并行收集器。如果您使用 -server 标志,默认情况下会启用它,或者您可以使用 -XX:+UseParallelGC 显式启用它。如果您宁愿以减少 GC 总 CPU 时间为代价来缩短 GC 暂停时间,并且您拥有多个 CPU,则可以使用并发收集器 (-XX:+UseConcMarkSweepGC)。
This blog entry has a nice breakdown of the different collectors, and which options are valid: http://blogs.oracle.com/jonthecollector/entry/our_collectors
java/JDK 6 GC tuning : http://www.oracle.com/technetwork/java/javase/gc-tuning-6-140523.html. This is from SUN (now Oracle). The full stuff.
Also, see
http://kirk.blog-city.com/is_your_concurrent_collector_failing_you.htm
http://www.javaperformancetuning.com/
Java GC tuning is basically a dark art, but in my application (runs with a 50+GB heap, and 16 physical cores) the ConcMarkSweep collector resulted in a 3x speedup over the -server default, and a 2.2x speedup over ParallelOldGC.
If you aren't sharing the machine with other processes (so idle cores are just wasted) use the ConcMarkSweepGC.
ParNew is the default young generation collector when CMS is used.You just have to specify -XX:+UseConcMarkSweepGC to use CMS and ParNew will be used by default. CMS is a good collector if avoiding GC jitters is of higher priority but if throughput is more important for eg for a batch like job the default SUN parallel collector does a better job.
You cannot enable two GC options at the same time. I would suggest you to use CMS which is better than and next generation GC compare to UseParNewGC. and if you use Java 1.7 or later and heap size is relatively bigger (like > 4GB) consider using G1.