简体   繁体   English

次要 GC 暂停时间太高。 可能的原因?

[英]Minor GC pause times are too higfh. possible reasons?

I Am experiencing a regular high minor GC pause times(~ 9seconds).我正在经历一个常规的高次要 GC 暂停时间(~ 9 秒)。

The application is a server written in Java, executing 3 transactions/seconds.该应用程序是一个用 Java 编写的服务器,执行 3 个事务/秒。

在此处输入图像描述

Eventhough there's no I/O excessive activity即使没有 I/O 过度活动

在此处输入图像描述

Heap parameters are:堆参数为:

-Xms1G
-Xmx14G
-XX:+UseConcMarkSweepGC
-XX:+DisableExplicitGC
-XX:+PrintGC
-XX:+PrintGCApplicationStoppedTime
-XX:+PrintGCTimeStamps
-XX:+PrintGCDateStamps
-XX:+PrintGCDetails

What are the possible reasons for such minor gc pause times values?这种较小的 gc 暂停时间值的可能原因是什么?

For questions in category "Why my GC pause that long?" 对于类别“为什么我的GC暂停这么长时间?”的问题 you should always provide some snippets for GC logs. 您应该始终为GC日志提供一些摘要。

As a pure speculation, here are few reasons why minor GC may be abnormally slow: 纯粹出于猜测,以下是次要GC可能异常缓慢的一些原因:

  • JVM were suspended from execution by OS (ei CPU starvation, swapping, virtual server freeze) JVM暂停了OS的执行(例如CPU饥饿,交换,虚拟服务器冻结)
  • There are some issue with putty JVM at safepoint (unlikely looking at your pause pattern though) 有一些问题用腻子JVM在还原点 (不太可能在您的暂停模式看,虽然)
  • Object survival spikes 对象生存高峰
  • Reference object processing overhead (you need add -XX:+PrintReferebceGC to get reference processing info into GC log) 参考对象处理开销(您需要添加-XX:+PrintReferebceGC才能将参考处理信息添加到GC日志中)

As the other answer says, without GC log snippets it's not possible to answer this definitively. 就像另一个答案所说的那样,没有GC日志片段,就不可能确切地回答这个问题。 Some things to think about: 需要考虑的一些事情:

Assuming no impact from the underlying OS (scheduling, CPU thrashing), the time taken for a minor collection will be proportional to the amount of live data in the young gen. 假设不受到底层操作系统的影响(计划,CPU抖动),次要收集所花费的时间将与年轻一代中实时数据的数量成正比。 when the collector runs (every live object in the young gen. gets copied during a minor GC). 收集器运行时(年轻一代中的每个活动对象在次要GC中都会被复制)。 Looking at the graph of your old gen. 看你的老一代的图。 you are seeing consistent growth which would indicate you are promoting significant amounts of data during minor GC. 您会看到持续增长,这表明您在次要GC期间正在推广大量数据。 You're either creating a lot of long-lived objects or you're maintaining references unnecessarily. 您要么创建许多长期存在的对象,要么不必要地维护引用。

To reduce the pauses you could try reducing the size of the Eden space (so there is less potential data to copy on each minor GC) and also reduce the tenuring threshold so that objects get moved out of the survivor spaces more quickly. 为了减少停顿,您可以尝试减小Eden空间的大小(因此,每个次要GC上要复制的潜在数据更少),还可以降低使用期限,以使对象更快地移出幸存空间。 The downside of this will be your minor GCs will happen more frequently so you will probably see a degradation in throughput. 这样做的缺点是次要GC的发生频率更高,因此吞吐量可能会下降。

I would also change the -Xms value. 我还将更改-Xms值。 You clearly need more than 1Gb in your heap so it would be best to set it to 14Gb to avoid the heap having to be resized by the JVM as the amount of data increases. 显然您的堆中需要超过1Gb,因此最好将其设置为14Gb,以避免随着数据量的增加,JVM必须调整堆的大小。

Try using 尝试使用

-XX:+UseG1GC -XX:MaxGCPauseMillis=1000 

This will try to keep max GC pause below 1s. 这将尝试将最大GC暂停时间保持在1秒以下。

You need to assign enough memory using -Xmx and set the MaxGCPauseMillis as per need. 您需要使用-Xmx分配足够的内存,并根据需要设置MaxGCPauseMillis

IMHO:恕我直言:

  • There is no sufficient evidence that there is indeed minor GC "pause time".没有足够的证据表明确实存在次要 GC“暂停时间”。 What is shown is Garbage Collection Time, and GC time.= GC Pause time.显示的是垃圾收集时间和 GC 时间。= GC 暂停时间。 Garbage collection activity time and garbage collection pause time are two different beasts - or in technical words, I should say that these are JVM ergonomics/performance goals.垃圾收集活动时间和垃圾收集暂停时间是两种不同的野兽——或者用技术术语来说,我应该说这些是 JVM 人体工程学/性能目标。
  • Minor GC pause time is commonly negilible and it is the major GC pause time that affects the application responsiveness. Minor GC 暂停时间通常可以忽略不计,而影响应用程序响应能力的是 Major GC 暂停时间。
  • There is something called as JVM/Ergonomics goals, and "Throughput Goal" is one of the three goals, so I think in this case at max what can be said is that throughput goal is not going very good for young generation as lot of time is spent on GC.有一种叫做 JVM/Ergonomics 目标的东西,而“吞吐量目标”是三个目标之一,所以我认为在这种情况下,最多可以说吞吐量目标对于年轻一代来说并不是很好花费在 GC 上。

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

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