Java 7 G1GC的异常行为 [英] Java 7 G1GC strange behaviour

查看:195
本文介绍了Java 7 G1GC的异常行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近,我尝试在Java处理器中使用来自jdk1.7.0-17的G1GC,该处理器正在处理从MQ接收到的许多相似消息(大约15-20 req/sec).每个消息都是在Java受限线程池所服务的单独线程(处于稳定状态的约100个线程)中处理的.出乎意料的是,我检测到了奇怪的行为-GC启动完整的gc周期后,就开始使用大量的处理时间(高达100%的CPU甚至更多).我多次进行代码重构,目的是优化代码并使其更轻量.但是没有任何明显的结果-行为是相同的.我在Debian OS(2.6.32-5内核)上使用4核64位计算机.有人可以帮助我了解和解决这种情况吗? 以下是上述问题的一些插图.

Recently I have tried to use G1GC from jdk1.7.0-17 in my java processor which is processing a lot of similar messages received from an MQ (about 15-20 req/sec). Every message is processed in the separate thread (about 100 threads in stable state) that serviced by Java limited thread pool. Surprisingly, I detected the strange behaviour - as soon as GC starts the full gc cycle it begins to use significant processing time (up to 100% CPU and even more). I was doing refactoring of the code several times having a goal to optimizing it and doing it more lightweight. But without any significant result - the behaviour is the same. I use the 4-core 64-bit machine with Debian OS (2.6.32-5 kernel). May someone help me to understand and resolve the situation? Below are depicted some illustrations for listed above issue.

推荐答案

令人惊讶的是,我检测到了奇怪的行为-GC启动后, 整个gc周期...

Surprisingly, I detected the strange behaviour - as soon as GC starts the full gc cycle...

不幸的是,这并不奇怪,因为在JVM中实现的G1 GC仅使用一个硬件线程(vCPU)来执行Full GC,因此其想法是将Full GC的数量减至最少.请记住,建议您将此收集器推荐用于具有多个内核的配置(当然,它不会影响Full GC,但会影响分配和并行收集),并且我认为大于8GB的大堆.

Unfortunately, this is not a surprise because for the G1 GC implemented within the JVM uses just one hardware thread (vCPU) to execute the Full GC so the idea is to minimize the number of Full GCs. Please, you should keep in mind this collector is recommended for configurations with several cores (of course it does not impact on the Full GC, but impacts on allocation and parallel collections) and big heaps I think bigger than 8GB.

根据Oracle:

https://docs.oracle .com/javase/8/docs/technotes/guides/vm/gctuning/g1_gc.html

垃圾优先(G1)垃圾收集器是服务器样式的垃圾 收集器,用于具有较大记忆力的多处理器计算机. 它尝试达到较高的垃圾回收(GC)暂停时间目标 高吞吐量的可能性.全堆操作 (例如全局标记)与 应用程序线程.这样可以防止与堆成比例的中断 或实时数据大小.

The Garbage-First (G1) garbage collector is a server-style garbage collector, targeted for multiprocessor machines with large memories. It attempts to meet garbage collection (GC) pause time goals with high probability while achieving high throughput. Whole-heap operations, such as global marking, are performed concurrently with the application threads. This prevents interruptions proportional to heap or live-data size.

本文中对此收集器中的Full GC单线程进行了解释.

In this article there is an explanation about the Full GC single thread in this collector.

https://www.redhat.com /en/blog/part-1-introduction-g1-垃圾收集器

最后,不幸的是,G1还必须处理可怕的Full GC.尽管G1最终试图避免使用Full GC,但它们仍然是 苛刻的现实,尤其是在调整不当的环境中. 鉴于 G1的目标是更大的堆大小,完全GC的影响可能是 对飞行中的处理和SLA造成灾难性的影响.主要之一 原因是Full GC在G1中仍然是单线程操作. 查看原因,第一个也是最可避免的与 元空间.

Finally and unfortunately, G1 also has to deal with the dreaded Full GC. While G1 is ultimately trying to avoid Full GC’s, they are still a harsh reality especially in improperly tuned environments. Given that G1 is targeting larger heap sizes, the impact of a Full GC can be catastrophic to in-flight processing and SLAs. One of the primary reasons is that Full GCs are still a single-threaded operation in G1. Looking at causes, the first, and most avoidable, is related to Metaspace.

顺便说一句,它似乎是Java(10)的最新版本,它将包括一个G1,该G1具有并行执行Full GC的能力.

By the way, it seems to be the newest version of Java (10) is going to include a G1 with the capability of executing Full GCs in parallel.

https://www.opsian.com/blog/java- 10-with-g1/

Java 10通过迭代改进其完整的GC暂停时间 现有算法.直到Java 10 G1 Full GC在单个线程中运行. 是的-您的32核心服务器和128GB将会停止并暂停 直到有一个线程清除了垃圾.

Java 10 reduces Full GC pause times by iteratively improving on its existing algorithm. Until Java 10 G1 Full GCs ran in a single thread. That’s right - your 32 core server and it’s 128GB will stop and pause until a single thread takes out the garbage.

也许您应该调整元空间或增加堆,或者可以使用其他收集器,例如并行GC.

Perhaps, you should tune the metaspace or increase the heap or you can use other collector such as the parallel GC.

这篇关于Java 7 G1GC的异常行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆