Java -XX:+UseParallelGC 和 -XX:+UseParNewGC 的区别

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2101518/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 03:33:19  来源:igfitidea点击:

Difference between -XX:+UseParallelGC and -XX:+UseParNewGC

javajvm-arguments

提问by fglez

They are algorithms for the young generation garbage collection.

它们是年轻代垃圾收集的算法。

The second one (UseParNewGC) gets activated automatically with the concurrent tenured generation garbage collection (see Java Concurrent and Parallel GC) but, is there a difference between the two parallel algorithms?

第二个 (UseParNewGC) 通过并发的终身代垃圾收集自动激活(请参阅Java Concurrent 和 Parallel GC)但是,这两种并行算法之间有区别吗?

采纳答案by fglez

After a lot of searching, the best explanation I've found is from Java Performance Tuning website in Question of the month: 1.4.1 Garbage collection algorithms, January 29th, 2003

经过大量搜索,我找到的最佳解释来自 Java Performance Tuning 网站的本月问题:1.4.1 垃圾收集算法,2003 年 1 月 29 日

Young generation garbage collection algorithms

The (original) copying collector(Enabled by default). When this collector kicks in, all application threads are stopped, and the copying collection proceeds using one thread (which means only one CPU even if on a multi-CPU machine). This is known as a stop-the-world collection, because basically the JVM pauses everything else until the collection is completed.

The parallel copying collector(Enabled using -XX:+UseParNewGC). Like the original copying collector, this is a stop-the-world collector. However this collector parallelizes the copying collection over multiple threads, which is more efficient than the original single-thread copying collector for multi-CPU machines (though not for single-CPU machines). This algorithm potentially speeds up young generation collection by a factor equal to the number of CPUs available, when compared to the original singly-threaded copying collector.

The parallel scavenge collector(Enabled using -XX:UseParallelGC). This is like the previous parallel copying collector, but the algorithm is tuned for gigabyte heaps (over 10GB) on multi-CPU machines. This collection algorithm is designed to maximize throughput while minimizing pauses. It has an optional adaptive tuning policy which will automatically resize heap spaces. If you use this collector, you can only use the the original mark-sweep collector in the old generation (i.e. the newer old generation concurrent collector cannot work with this young generation collector).

年轻代垃圾收集算法

(原)复制收集器(默认启用)。当这个收集器启动时,所有应用程序线程都会停止,并且复制收集使用一个线程进行(这意味着即使在多 CPU 机器上也只有一个 CPU)。这被称为 stop-the-world 收集,因为基本上 JVM 会暂停所有其他操作,直到收集完成。

并行复制收集(使用-XX启用:+ UseParNewGC)。就像原来的复制收藏家一样,这是一个停止世界的收藏家。然而,这个收集器在多个线程上并行化了复制收集,这比用于多 CPU 机器的原始单线程复制收集器更有效(尽管不适用于单 CPU 机器)。与原始的单线程复制收集器相比,该算法可能会以等于可用 CPU 数量的因子来加速年轻代收集。

平行扫集电极(使用-XX启用:UseParallelGC)。这与之前的并行复制收集器类似,但该算法针对多 CPU 机器上的千兆字节堆(超过 10GB)进行了调整。此收集算法旨在最大限度地提高吞吐量,同时最大限度地减少停顿。它有一个可选的自适应调整策略,可以自动调整堆空间的大小。如果你使用这个收集器,你只能在老年代使用原来的标记-清除收集器(即较新的老年代并发收集器不能和这个年轻代收集器一起工作)。

From this information, it seems the main difference (apart from CMS cooperation) is that UseParallelGC supports ergonomics while UseParNewGC doesn't.

从这些信息来看,主要区别(除了 CMS 合作)似乎是 UseParallelGC 支持人体工程学,而 UseParNewGC 不支持。

回答by Suraj Chandran

UseParNewGC usually knowns as "parallel young generation collector" is same in all ways as the parallel garbage collector (-XX:+UseParallelGC), except that its more sophiscated and effiecient. Also it can be used with a "concurrent low pause collector".

UseParNewGC 通常被称为“并行年轻代收集器”,在所有方面都与并行垃圾收集器(-XX:+UseParallelGC)相同,只是它更复杂和更高效。它也可以与“并发低暂停收集器”一起使用。

See Java GC FAQ, question 22 for more information.

有关更多信息,请参阅Java GC 常见问题解答,问题 22。

Note that there are some known bugs with UseParNewGC

请注意,UseParNewGC 存在一些已知错误

回答by Avinash Ganta

Using -XX:+UseParNewGC along with -XX:+UseConcMarkSweepGC, will cause higher pause time for Minor GCs, when compared to -XX:+UseParallelGC.

与 -XX:+UseParallelGC 相比,使用 -XX:+UseParNewGC 和 -XX:+UseConcMarkSweepGC 会导致 Minor GC 的暂停时间更长。

This is because, promotion of objects from Young to Old Generation will require running a Best-Fit algorithm (due to old generation fragmentation) to find an address for this object.
Running such an algorithm is not required when using -XX:+UseParallelGC, as +UseParallelGC can be configured only with MarkandCompact Collector, in which case there is no fragmentation.

这是因为,将对象从年轻代提升到老年代将需要运行最佳拟合算法(由于老年代碎片)来找到该对象的地址。
使用 -XX:+UseParallelGC 时不需要运行这样的算法,因为 +UseParallelGC 只能使用 MarkandCompact Collector 配置,在这种情况下没有碎片。

回答by Ivan Herlambang

Parallel GC

并行GC

  • XX:+UseParallelGC Use parallel garbage collection for scavenges. (Introduced in 1.4.1)
  • XX:+UseParallelOldGC Use parallel garbage collection for the full collections. Enabling this option automatically sets -XX:+UseParallelGC. (Introduced in 5.0 update 6.)
  • XX:+UseParallelGC 使用并行垃圾收集进行清理。(在 1.4.1 中引入)
  • XX:+UseParallelOldGC 对完全收集使用并行垃圾收集。启用此选项会自动设置 -XX:+UseParallelGC。(在 5.0 更新 6 中引入。)

UseParNewGC

使用ParNewGC

UseParNewGCA parallel version of the young generation copying collector is used with the concurrent collector (i.e. 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).

UseParNewGC年轻代复制收集器的并行版本与并发收集器一起使用(即,如果 -XX:+ UseConcMarkSweepGC 在命令行上使用,则如果未在命令行上明确设置,则标志 UseParNewGC 也设置为 true )。

Perhaps the easiest way to understand was combinations of garbage collection algorithms made by Alexey Ragozin

也许最容易理解的方法是Alexey Ragozin提出的垃圾收集算法的组合

<table border="1" style="width:100%">
  <tr>
    <td align="center">Young collector</td>
    <td align="center">Old collector</td>
    <td align="center">JVM option</td>
  </tr>
  <tr>
    <td>Serial (DefNew)</td>
    <td>Serial Mark-Sweep-Compact</td>
    <td>-XX:+UseSerialGC</td>
  </tr>
  <tr>
    <td>Parallel scavenge (PSYoungGen)</td>
    <td>Serial Mark-Sweep-Compact (PSOldGen)</td>
    <td>-XX:+UseParallelGC</td>
  </tr>
  <tr>
    <td>Parallel scavenge (PSYoungGen)</td>
    <td>Parallel Mark-Sweep-Compact (ParOldGen)</td>
    <td>-XX:+UseParallelOldGC</td>
  </tr>
  <tr>
    <td>Serial (DefNew)</td>
    <td>Concurrent Mark Sweep</td>
    <td>
      <p>-XX:+UseConcMarkSweepGC</p>
      <p>-XX:-UseParNewGC</p>
    </td>
  </tr>
  <tr>
    <td>Parallel (ParNew)</td>
    <td>Concurrent Mark Sweep</td>
    <td>
      <p>-XX:+UseConcMarkSweepGC</p>
      <p>-XX:+UseParNewGC</p>
    </td>
  </tr>
  <tr>
    <td colspan="2">G1</td>
    <td>-XX:+UseG1GC</td>
  </tr>
</table>

Conclusion:

结论:

  1. Apply -XX:+UseParallelGC when you require parallel collection method over YOUNGgeneration ONLY, (butstill) use serial-mark-sweep method as OLDgeneration collection
  2. Apply -XX:+UseParallelOldGC when you require parallel collection method over YOUNGgeneration (automatically sets -XX:+UseParallelGC) ANDOLDgeneration collection
  3. Apply -XX:+UseParNewGC & -XX:+UseConcMarkSweepGC when you require parallel collection method over YOUNGgeneration ANDrequire CMS method as your collection over OLDgeneration memory
  4. You can't apply -XX:+UseParallelGC or -XX:+UseParallelOldGC with -XX:+UseConcMarkSweepGC simultaneously, that's why your require -XX:+UseParNewGC to be paired with CMS otherwise use -XX:+UseSerialGC explicitly OR-XX:-UseParNewGC if you wish to use serial method against young generation
  1. 应用-XX:+ UseParallelGC当你需要并行采集方法在年轻一代ONLY,(仍然)使用串行标记-清除方法,一代收藏
  2. 当您需要在年轻代(自动设置 -XX:+UseParallelGC)代收集上的并行收集方法时应用 -XX:+UseParallelOldGC
  3. 应用-XX:+ UseParNewGC和-XX:+ UseConcMarkSweepGC,当你需要在并行采集方法要求CMS方法您的收藏过代内存
  4. 您不能同时应用 -XX:+UseParallelGC 或 -XX:+UseParallelOldGC 和 -XX:+UseConcMarkSweepGC,这就是为什么您需要 -XX:+UseParNewGC 与 CMS 配对,否则明确使用 -XX:+UseSerialGC-XX:-UseParNewGC 如果你想对年轻代使用串行方法