Java 并发和并行 GC
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/220388/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Java Concurrent and Parallel GC
提问by pdeva
This article heresuggests to use -XX:+UseParNewGC
"To enable a parallel young generation GC with the concurrent GC".
本文在这里建议使用-XX:+UseParNewGC
“为了使与并发GC并行年轻一代的GC”。
My confusion is that in order to enable both parallel and concurrent GC, should I
我的困惑是,为了同时启用并行和并发 GC,我应该
- use
-XX:+UseParNewGC
or - use both
-XX:+UseParNewGC
and-XX:+UseConcMarkSweepGC
?
- 使用
-XX:+UseParNewGC
或 - 使用
-XX:+UseParNewGC
和-XX:+UseConcMarkSweepGC
?
PS
聚苯乙烯
I am using JVM 6.
我正在使用 JVM 6。
采纳答案by sk.
Since the document you linked was for a 1.4.2 VM that's what I'll assume you're using (JVMs 5 and 6 behave differently).
由于您链接的文档是针对 1.4.2 虚拟机的,因此我假设您正在使用该虚拟机(JVM 5 和 6 的行为不同)。
From http://java.sun.com/docs/hotspot/gc1.4.2/
来自http://java.sun.com/docs/hotspot/gc1.4.2/
if -XX:+UseConcMarkSweepGC is used on the command line then the flag UseParNewGC is also set to true if it is not otherwise explicitly set on the command line
如果在命令行上使用了 -XX:+UseConcMarkSweepGC 则标志 UseParNewGC 也被设置为 true 如果它没有在命令行上明确设置
So the answer is you only need to use -XX:+UseConcMarkSweepGC and it will enable the concurrent collector with the parallel young generation collector.
所以答案是你只需要使用 -XX:+UseConcMarkSweepGC 它将启用并发收集器和并行年轻代收集器。
Edit: for Java 6, the same flag (-XX:+UseConcMarkSweepGC) enables the concurrent collector. The choice of collector you want depends on a few things, and you should test different configurations. But there are some very general guidelines. If you have a single processor, single thread machine then you should use the serial collector (default for some configurations, can be enabled explicitly for with -XX:+UseSerialGC). For multiprocessor machines where your workload is basically CPU bound, use the parallel collector. This is enabled by default if you use the -server flag, or you can enable it explicitly with -XX:+UseParallelGC. If you'd rather keep the GC pauses shorter at the expense of using more total CPU time for GC, and you have more than one CPU, you can use the concurrent collector (-XX:+UseConcMarkSweepGC). Note that the concurrent collector tends to require more RAM allocated to the JVM than the serial or parallel collectors for a given workload because some memory fragmentation can occur.
编辑:对于 Java 6,相同的标志 (-XX:+UseConcMarkSweepGC) 启用并发收集器。您想要的收集器的选择取决于一些事情,您应该测试不同的配置。但是有一些非常通用的指导方针。如果您有一个单处理器、单线程机器,那么您应该使用串行收集器(某些配置的默认值,可以使用 -XX:+UseSerialGC 显式启用)。对于工作负载基本上受 CPU 限制的多处理器机器,请使用并行收集器。如果您使用 -server 标志,则默认启用此功能,或者您可以使用 -XX:+UseParallelGC 显式启用它。如果您希望以为 GC 使用更多 CPU 总时间为代价来缩短 GC 暂停时间,并且您有多个 CPU,则可以使用并发收集器 (-XX:+UseConcMarkSweepGC)。
回答by tpoindex
This blog entry has a nice breakdown of the different collectors, and which options are valid: http://blogs.oracle.com/jonthecollector/entry/our_collectors
此博客条目对不同的收集器进行了很好的细分,以及哪些选项有效:http: //blogs.oracle.com/jonthecollector/entry/our_collectors
回答by anjanb
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.
java/JDK 6 GC 调优:http: //www.oracle.com/technetwork/java/javase/gc-tuning-6-140523.html。这是来自 SUN(现在是 Oracle)。完整的东西。
Also, see
http://kirk.blog-city.com/is_your_concurrent_collector_failing_you.htm
http://www.javaperformancetuning.com/
另请参阅
http://kirk.blog-city.com/is_your_concurrent_collector_failing_you.htm
http://www.javaperformancetuning.com/
回答by Charles Munger
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.
Java GC 调优基本上是一门黑暗艺术,但在我的应用程序中(运行 50+GB 堆和 16 个物理内核),ConcMarkSweep 收集器比 -server 默认值提高了 3 倍,比 ParallelOldGC 提高了 2.2 倍。
If you aren't sharing the machine with other processes (so idle cores are just wasted) use the ConcMarkSweepGC.
如果您不与其他进程共享机器(因此空闲核心只是浪费),请使用 ConcMarkSweepGC。
回答by Deven
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.
ParNew 是使用 CMS 时默认的年轻代收集器。您只需指定 -XX:+UseConcMarkSweepGC 即可使用 CMS,默认使用 ParNew。如果避免 GC 抖动具有更高的优先级,则 CMS 是一个很好的收集器,但如果吞吐量对于例如类似批处理的作业更重要,则默认的 SUN 并行收集器会做得更好。
回答by Shyamal Madura Patabendige
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.
您不能同时启用两个 GC 选项。我建议你使用比 UseParNewGC 更好的 CMS 和下一代 GC。如果您使用 Java 1.7 或更高版本并且堆大小相对较大(例如 > 4GB),请考虑使用 G1。