本文介绍了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.

推荐答案

不幸的是,这并不奇怪,因为在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

本文中对此收集器中的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-垃圾收集器

顺便说一句,它似乎是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/

也许您应该调整元空间或增加堆,或者可以使用其他收集器,例如并行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的异常行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 15:04