简体   繁体   English

有关G1的并行完整GC的说明

[英]Explanation needed about Parallel Full GC for G1

As part of the java JDK10 JEP307 was Parallel Full GC for G1 realsed. 作为Java JDK10的一部分,JEP307是用于G1实现的并行完整GC

I've tried to grasp its description, but I am still not confident that I got the idea properly. 我试图理解它的描述,但我仍然不相信我的想法是正确的。

my doubt was is it related to Concurrent Garbage 我的疑问是它与Concurrent Garbage有关

As a simplified explanation - garbage collectors have two possible collection types, "incremental" and "full". 作为简化的解释 - 垃圾收集器有两种可能的集合类型,“增量”和“完整”。 Incremental collection is the better of the two for staying out the way, as it'll do a little bit of work every so often. 增量收集是最好的两种方式,因为它会经常做一些工作。 Full collection is often more disruptive, as it takes longer and often has to halt the entire program execution while it's running. 完全收集通常更具破坏性,因为它需要更长的时间并且通常必须在运行时停止整个程序执行。

Because of this, most modern GCs (including G1) will generally try to ensure that in normal circumstances, the incremental collection will be enough and a full collection will never be required. 因此,大多数现代GC(包括G1)通常会尝试确保在正常情况下,增量收集就足够了,永远不需要完整的收集。 However, if lots of objects across different generations are being made eligible for garbage collection in unpredictable ways, then occasionally a full GC may be inevitable. 但是,如果不同世代的大量对象有可能以不可预测的方式进行垃圾收集,那么偶尔完整的GC可能是不可避免的。

At present, the G1 full collection implementation is only single threaded. 目前,G1完整集合实现只是单线程。 And that's where that JEP comes in - it aims to parallelize it, so that when a full GC does occur it's faster on systems that can support parallel execution. 这就是JEP的用武之地 - 它旨在并行化它,这样当一个完整的GC确实发生时,它可以在支持并行执行的系统上更快。

Finally I understood about Parallel Full GC for G1 最后,我了解了G1的Parallel Full GC

在此输入图像描述

Made the default in JDK 9 and Introduced in JDK 7 在JDK 9中作为默认值并在JDK 7中引入

Efficiently and concurrently deal with heaps fails on Full Garbage Collection some times full Garbage Collection is inevitable.It efficiently and concurrently deal with very large heaps Normal GC would divide the heap into young (eden and survivor) and old generation (logical separation) G1 splits heap into many small regions. 有效地同时处理堆完全垃圾收集失败有时完全垃圾收集是不可避免的。它有效并同时处理非常大的堆正常GC将堆分成年轻(伊甸园和幸存者)和老一代(逻辑分离)G1分裂堆积成许多小区域。 This splitting enables G1 to select a small region to collect and finish quickly. 这种分裂使G1能够选择一个小区域来快速收集和完成。

In JDK9 uses single thread for full GC 在JDK9中使用单线程进行完整GC

In JDK 10 uses multi thread(parallel) for Garbage Collection' 在JDK 10中使用多线程(并行)进行垃圾收集'

The G1 garbage collector was infamous for doing a single-threaded full GC cycle. G1垃圾收集器因进行单线程完整GC循环而臭名昭着。 At the time when you need all the hardware that you can muster to scrounge for unused objects, we bottlenecked on a single thread. 当您需要所有可以为未使用的对象进行搜索的硬件时,我们会在单个线程上遇到瓶颈。 In Java 10 they fixed this. 在Java 10中他们解决了这个问题。 The full GC now runs with all the resources that we throw at it. 完整的GC现在运行我们投入的所有资源。 To demonstrate this, I wrote ObjectChurner, which creates a bunch of different sized byte arrays. 为了证明这一点,我编写了ObjectChurner,它创建了一堆不同大小的字节数组。 It holds onto the objects for some time. 它保留了一段时间的物体。 The sizes are randomized, but in a controlled, repeatable way. 尺寸是随机的,但是以可控,可重复的方式。

Java 10 reduces Full GC pause times by iteratively improving on its existing algorithm. Java 10通过迭代改进其现有算法来减少Full GC暂停时间。 Until Java 10 G1 Full GCs ran in a single thread. 直到Java 10 G1 Full GC在单个线程中运行。 That's right - your 32 core server and it's 128GB will stop and pause until a single thread takes out the garbage. 那是对的 - 你的32核心服务器和它的128GB将停止并暂停,直到一个线程取出垃圾。 In Java 10 this has been improved to run in Parallel. 在Java 10中,这已被改进为并行运行。 This means that the Full GCs will be on multiple threads in parallel, albeit still pausing the JVM's progress whilst it completes. 这意味着Full GCs将并行处于多个线程上,尽管在完成时仍然会暂停JVM的进度。 The number of threads can be optionally configured using -XX:ParallelGCThreads . 可以使用-XX:ParallelGCThreads选择性地配置线程数。

This is a nice improvement to the G1 algorithm in Java 10 that should reduce worst case pause times for most users. 这是对Java 10中G1算法的一个很好的改进,它可以减少大多数用户的最坏情况暂停时间。 Does that mean that Java GC pauses are a thing of the past? 这是否意味着Java GC暂停已成为过去? No - it reduces the problem but since G1 doesn't run its collection cycles concurrently with your application it will still pause the application periodically and Full GC pauses still increase with larger heap sizes. 否 - 它减少了问题,但由于G1不会与您的应用程序同时运行其收集周期,因此它仍将定期暂停应用程序,并且Full GC暂停仍会随着堆大小的增加而增加。 We've talked about some other Garbage Collectors in our last blog post that may solve this problem in future. 我们在上一篇博文中谈到了其他一些垃圾收集器,可能会在将来解决这个问题。

G1 Collector G1收藏家
Another beautiful optimization which was just out with Java 8 update 20 for is the G1 Collector String deduplication. 使用Java 8更新20的另一个漂亮的优化是G1收集器字符串重复数据删除。 Since strings (and their internal char[] arrays) takes much of our heap, a new optimization has been made that enables the G1 collector to identify strings which are duplicated more than once across your heap and correct them to point into the same internal char[] array, to avoid multiple copies of the same string from residing inefficiently within the heap. 由于字符串(及其内部char []数组)占用了我们的大部分堆,因此进行了一项新的优化,使G1收集器能够识别在堆中多次复制的字符串,并将它们更正为指向相同的内部字符串[]数组,以避免相同字符串的多个副本在堆内无效地驻留。 You can use the -XX:+UseStringDeduplicationJVM argument to try this out. 您可以使用-XX:+UseStringDeduplicationJVM参数来尝试此操作。

Parallel Full GC in G1GC G1GC中的并行全GC
The G1 garbage collector was infamous for doing a single-threaded full GC cycle. G1垃圾收集器因进行单线程完整GC循环而臭名昭着。 At the time when you need all the hardware that you can muster to scrounge for unused objects, we bottlenecked on a single thread. 当您需要所有可以为未使用的对象进行搜索的硬件时,我们会在单个线程上遇到瓶颈。 In Java 10 they fixed this. 在Java 10中他们解决了这个问题。 The full GC now runs with all the resources that we throw at it. 完整的GC现在运行我们投入的所有资源。

JVM parameters: -Xlog:gc,gc+cpu::uptime -Xmx4g -Xms4g -Xlog:gc*:details.vgc This will output each GC event and its CPU usage to stdout, showing only the uptime as a tag. JVM参数: -Xlog:gc,gc+cpu::uptime -Xmx4g -Xms4g -Xlog:gc*:details.vgc这会将每个GC事件及其CPU使用情况输出到stdout,仅显示正常运行时间作为标记。 The setting -Xlog:gc* is like the -XX:+PrintGCDetails of previous Java versions. 设置-Xlog:gc*类似于以前Java版本的-XX:+PrintGCDetails

Java 10 reduces Full GC pause times by iteratively improving on its existing algorithm. Java 10通过迭代改进其现有算法来减少Full GC暂停时间。 Until Java 10 G1 Full GCs ran in a single thread. 直到Java 10 G1 Full GC在单个线程中运行。 That's right - your 32 core server and it's 128GB will stop and pause until a single thread takes out the garbage. 那是对的 - 你的32核心服务器和它的128GB将停止并暂停,直到一个线程取出垃圾。 In Java 10 this has been improved to run in Parallel. 在Java 10中,这已被改进为并行运行。 This means that the Full GCs will be on multiple threads in parallel, albeit still pausing the JVM's progress whilst it completes. 这意味着Full GCs将并行处于多个线程上,尽管在完成时仍然会暂停JVM的进度。 The number of threads can be optionally configured using -XX:ParallelGCThreads. 可以使用-XX:ParallelGCThreads.选择性地配置线程数-XX:ParallelGCThreads.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM