[英]What is the best way to measure GC pause times?
What is the best way to track the GC pause/stall times in a Java instance? 跟踪Java实例中GC暂停/停止时间的最佳方法是什么?
Does gc.log have any additional information that the MXBean doesn't have? gc.log是否具有MXBean没有的其他信息? I would prefer option 1 because I want the instance to emit that metric to our monitoring system.
我希望选择选项1,因为我希望实例向我们的监视系统发出该指标。
I have read through a few posts like this on SO, but I don't seem to be getting the right answer. 我已经通过像几个帖子读这对SO,但我似乎并没有越来越正确的答案。 I am specifically looking for the GC stall times and not the total time spent on GC.
我专门在寻找GC停止时间,而不是在GC上花费的总时间。
Garbage Collection is not the only reason of JVM stop-the-world pauses. 垃圾回收并不是JVM停止世界暂停的唯一原因。
You may want to count other reasons , too. 您可能还需要数其他原因 。
The first way to monitor safepoint pauses is to parse VM logs: 监视安全点暂停的第一种方法是解析VM日志:
-XX:+PrintGCApplicationStoppedTime
JVM option; -XX:+PrintGCApplicationStoppedTime
JVM选项; -Xlog:safepoint
. -Xlog:safepoint
。 Then look for Total time for which application threads were stopped
messages in the log file. 然后在日志文件中查找
Total time for which application threads were stopped
消息的Total time for which application threads were stopped
。
The second way is to use undocumented Hotspot internal MXBean: 第二种方法是使用未记录的 Hotspot内部MXBean:
sun.management.HotspotRuntimeMBean runtime =
sun.management.ManagementFactoryHelper.getHotspotRuntimeMBean();
System.out.println("Safepoint time: " + runtime.getTotalSafepointTime() + " ms");
System.out.println("Safepoint count: " + runtime.getSafepointCount());
It gives you the cumulative time of all JVM pauses. 它为您提供了所有JVM暂停的累积时间。 See the discussion in this answer .
请参阅此答案中的讨论。
I am specifically looking for the GC stall times
我专门在寻找GC停止时间
There are more to stall times than the GC itself. 失速时间比GC本身多。 Time to acquire the safepoint is also an application stall and is only available as part logging, not through MXBeans
获取安全点的时间也是应用程序的停滞状态,并且只能作为部分日志记录来使用,而不能通过MXBeans来获取。
But really, if you're concerned about application stalls then neither GC pauses nor over safepoint time is what you should actually measure . 但是,实际上,如果您担心应用程序停顿,那么您实际上应该测量 GC既不暂停也不超过安全点时间。 You should measure the stalls themselves, eg via jhiccup
您应该自己测量档位,例如通过jhiccup
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.