-XX:UseParallelGC和-XX:+UseParNewGC之间的差异

时间:2022-05-18 17:20:01

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)自动激活,但是,这两个并行算法之间有区别吗?

4 个解决方案

#1


110  

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性能优化网站的一个月: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.

复制收集器(默认启用)。当这个收集器启动时,所有应用程序线程都停止,复制收集使用一个线程(这意味着即使在多CPU机器上,也只有一个CPU)。这就是所谓的“停止-世界”集合,因为基本上JVM会暂停其他所有内容,直到集合完成。

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.

并行复制收集器(启用-XX:+UseParNewGC)。像原始的复制收集器一样,这是一个停止世界的收集器。但是,该收集器将复制收集在多个线程上并行化,这比原来的单线程复制收集器在多cpu机器上(尽管对单cpu机器来说不是这样)效率更高。与原始的单线程复制收集器相比,该算法可以将年轻代收集的速度提高到可用cpu数量的一个因数。

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).

并行清除收集器(使用-XX: useparallel elgc启用)。这与以前的并行复制收集器类似,但是算法在多cpu机器上为gb级(超过10GB)的堆进行了调优。这个集合算法的设计目的是最大化吞吐量,同时最小化停顿。它有一个可选的自适应调优策略,可以自动调整堆空间的大小。如果使用此收集器,则只能使用旧代中的原始标记-清除收集器(即新一代并发收集器不能与新一代收集器一起工作)。

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

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

#2


15  

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通常知道“parallel young generation collector”与并行垃圾收集器(-XX:+ useparallel elgc)在所有方面都是一样的,只不过它更加复杂和实用。它还可以与“并发低暂停收集器”一起使用。

See Java GC FAQ, question 22 for more information.

有关更多信息,请参阅Java GC FAQ,问题22。

Note that there are some known bugs with UseParNewGC

请注意,在UseParNewGC中有一些已知的错误。

#3


15  

Parallel GC

平行GC

  • XX:+UseParallelGC Use parallel garbage collection for scavenges. (Introduced in 1.4.1)
  • XX:+使用并行垃圾收集清除垃圾。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:+ useparallel eloldgc将并行垃圾收集用于完整的收集。启用此选项将自动设置-XX:+ useparallel elgc。(在5.0更新6中引入)

UseParNewGC

UseParNewGC

UseParNewGC A 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).

使用一个并行版本的年轻一代复制收集器用于并发收集器(例如,如果在命令行中使用-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 YOUNG generation ONLY, (but still) use serial-mark-sweep method as OLD generation collection
  2. 当您只需要在年轻代上使用并行收集方法时,(但仍然)使用串行标记-清除方法作为老代收集
  3. Apply -XX:+UseParallelOldGC when you require parallel collection method over YOUNG generation (automatically sets -XX:+UseParallelGC) AND OLD generation collection
  4. 当需要对年轻代(自动设置-XX:+ useparallel eloldgc)和老代集合进行并行收集时,应用-XX:+ useparallel eloldgc
  5. Apply -XX:+UseParNewGC & -XX:+UseConcMarkSweepGC when you require parallel collection method over YOUNG generation AND require CMS method as your collection over OLD generation memory
  6. 应用-XX:+UseParNewGC & -XX:+UseConcMarkSweepGC在年轻代时需要并行收集方法,在年老代内存时需要CMS方法作为收集
  7. 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
  8. 您不能同时应用-XX:+UseParallelGC或-XX:+UseParallelOldGC with -XX:+UseConcMarkSweepGC,这就是为什么您需要-XX:+UseParNewGC与CMS配对,否则显式使用-XX:+UseSerialGC或-XX:-UseParNewGC,如果您希望对年轻一代使用串行方法的话

#4


3  

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

使用-XX:+UseParNewGC和-XX:+UseConcMarkSweepGC,与-XX:+UseParallelGC相比,会导致较小的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:+ useparallel elgc时,不需要运行这样的算法,因为+UseParallelGC只能使用MarkandCompact收集器进行配置,在这种情况下不存在分段。

#1


110  

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性能优化网站的一个月: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.

复制收集器(默认启用)。当这个收集器启动时,所有应用程序线程都停止,复制收集使用一个线程(这意味着即使在多CPU机器上,也只有一个CPU)。这就是所谓的“停止-世界”集合,因为基本上JVM会暂停其他所有内容,直到集合完成。

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.

并行复制收集器(启用-XX:+UseParNewGC)。像原始的复制收集器一样,这是一个停止世界的收集器。但是,该收集器将复制收集在多个线程上并行化,这比原来的单线程复制收集器在多cpu机器上(尽管对单cpu机器来说不是这样)效率更高。与原始的单线程复制收集器相比,该算法可以将年轻代收集的速度提高到可用cpu数量的一个因数。

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).

并行清除收集器(使用-XX: useparallel elgc启用)。这与以前的并行复制收集器类似,但是算法在多cpu机器上为gb级(超过10GB)的堆进行了调优。这个集合算法的设计目的是最大化吞吐量,同时最小化停顿。它有一个可选的自适应调优策略,可以自动调整堆空间的大小。如果使用此收集器,则只能使用旧代中的原始标记-清除收集器(即新一代并发收集器不能与新一代收集器一起工作)。

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

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

#2


15  

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通常知道“parallel young generation collector”与并行垃圾收集器(-XX:+ useparallel elgc)在所有方面都是一样的,只不过它更加复杂和实用。它还可以与“并发低暂停收集器”一起使用。

See Java GC FAQ, question 22 for more information.

有关更多信息,请参阅Java GC FAQ,问题22。

Note that there are some known bugs with UseParNewGC

请注意,在UseParNewGC中有一些已知的错误。

#3


15  

Parallel GC

平行GC

  • XX:+UseParallelGC Use parallel garbage collection for scavenges. (Introduced in 1.4.1)
  • XX:+使用并行垃圾收集清除垃圾。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:+ useparallel eloldgc将并行垃圾收集用于完整的收集。启用此选项将自动设置-XX:+ useparallel elgc。(在5.0更新6中引入)

UseParNewGC

UseParNewGC

UseParNewGC A 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).

使用一个并行版本的年轻一代复制收集器用于并发收集器(例如,如果在命令行中使用-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 YOUNG generation ONLY, (but still) use serial-mark-sweep method as OLD generation collection
  2. 当您只需要在年轻代上使用并行收集方法时,(但仍然)使用串行标记-清除方法作为老代收集
  3. Apply -XX:+UseParallelOldGC when you require parallel collection method over YOUNG generation (automatically sets -XX:+UseParallelGC) AND OLD generation collection
  4. 当需要对年轻代(自动设置-XX:+ useparallel eloldgc)和老代集合进行并行收集时,应用-XX:+ useparallel eloldgc
  5. Apply -XX:+UseParNewGC & -XX:+UseConcMarkSweepGC when you require parallel collection method over YOUNG generation AND require CMS method as your collection over OLD generation memory
  6. 应用-XX:+UseParNewGC & -XX:+UseConcMarkSweepGC在年轻代时需要并行收集方法,在年老代内存时需要CMS方法作为收集
  7. 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
  8. 您不能同时应用-XX:+UseParallelGC或-XX:+UseParallelOldGC with -XX:+UseConcMarkSweepGC,这就是为什么您需要-XX:+UseParNewGC与CMS配对,否则显式使用-XX:+UseSerialGC或-XX:-UseParNewGC,如果您希望对年轻一代使用串行方法的话

#4


3  

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

使用-XX:+UseParNewGC和-XX:+UseConcMarkSweepGC,与-XX:+UseParallelGC相比,会导致较小的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:+ useparallel elgc时,不需要运行这样的算法,因为+UseParallelGC只能使用MarkandCompact收集器进行配置,在这种情况下不存在分段。