简体   繁体   English

如何调整jvm崩溃而不是英雄GC直到100%的CPU利用率?

[英]How to tune a jvm to crash instead of heroically GC till 100% CPU utilization?

We have a JVM process that infrequently pegs the CPU at 100%, with what appears to be (according to visualgc) a very nearly exhausted heap. 我们有一个JVM进程很少将CPU固定在100%,看起来似乎是(根据visualgc)一个非常耗尽的堆。 Our supposition is that the process is heroically GC'ing causing a CPU spike, which is affecting the overall health of the entire system (consisting of other JVMs doing different things). 我们的假设是,这个过程是英勇的GC导致CPU峰值,这会影响整个系统的整体运行状况(包括其他JVM做不同的事情)。

This process is not critical and can be restarted. 此过程并不重要,可以重新启动。 Is there a way to tune the JVM via the command line which starts it to make it fall on its own sword rather than it keep GC'ing and causing the entire box to suffer? 有没有办法通过命令行调整JVM,启动它使它落在自己的剑上而不是它保持GC并导致整个盒子受损?

Of note is that we are not getting OOMExceptions, so the heap isn't TOTALLY exhausted, but just barely not, we think. 值得注意的是,我们没有得到OOMExceptions,所以堆不是完全耗尽,但我们认为只是勉强没有。

Alternatively, something to give us some insight as to what in the JVM is actually using the CPU in the way that it is to confirm/deny our GC supposition? 或者,有什么东西可以让我们了解一下JVM中实际使用CPU的方式是确认/拒绝我们的GC假设?

We can get the statistics from 我们可以从中获取统计数据

1):The option -XX:+PrintGCTimeStamps will add a time stamp at the start of each collection. 1):选项-XX:+ PrintGCTimeStamps将在每个集合的开头添加时间戳。 This is useful to see how frequently garbage collections occur. 这对于查看垃圾收集发生的频率很有用。

With the above option we can get rough estimation whether you supposition that the process is heroically GC'ing causing a CPU spike or not . 通过上面的选项,我们可以粗略估计您是否认为该过程是英雄性的GC'ing导致CPU峰值。

If your suppossition is right then start tunig your GC . 如果您的支持是正确的,那么开始调整您的GC。

 Both parallel collector and Concurrent Collector will throw an OutOfMemoryError if too much time is being
 spent in garbage collection: if more than 98% of the total time is spent in garbage collection and 
less than 2% of the heap is recovered, an OutOfMemoryError will be thrown. the option X:-UseGCOverheadLimit 
 is enabled by default for both Parallel and concurrent collector . Check whether this option is disabled in
 your system .  

For more information about Gc tuning in JVM refer this and for vm debugging options check this 有关JVM中的Gc调优的更多信息,请参阅此内容 ,对于vm调试选项,请检查此项

The parallel and concurrent collectors have an "overhead limit" that might do what you want: 并行和并发收集器有一个“开销限制”,可以做你想要的:

if more than 98% of the total time is spent in garbage collection and less than 2% of the heap is recovered, an OutOfMemoryError will be thrown 如果超过总时间的98%用于垃圾收集并且不到2%的堆被恢复,则会抛出OutOfMemoryError

See http://www.oracle.com/technetwork/java/javase/gc-tuning-6-140523.html for more information. 有关更多信息,请参阅http://www.oracle.com/technetwork/java/javase/gc-tuning-6-140523.html

The best thing to do is to find out the memory leak and fix it. 最好的办法是找出内存泄漏并修复它。

A simple way to exit on high memory usage: 退出高内存使用率的简单方法:

if(Runtime.getRuntime().totalMemory()>100*1024*1024)
    System.exit(0);

Try to look what processes are currently running in the JVM. 尝试查看当前在JVM中运行的进程。

  • with jstack you can make a thread dump (there are other ways to do that as well) 使用jstack你可以进行一个线程转储(还有其他方法可以做到这一点)
  • with jvisualvm you could peek into the current state of the JVM (takes some resources) 使用jvisualvm您可以查看JVM的当前状态(需要一些资源)
  • also turn on verbosegc (to prove your assumption that GC is frequent) 也打开verbosegc (以证明你认为GC频繁)

You need to find a way how to gather some statistic about GC work. 您需要找到一种方法来收集有关GC工作的统计信息。 Actually there are some methods to do this. 实际上有一些方法可以做到这一点。 I will not do copy-paste, just give you the link to similar question: 我不会复制粘贴,只是给你类似问题的链接:

Can you get basic GC stats in Java? 你能用Java获得基本的GC统计数据吗?

I believe, you will think of how to analyze this statistic and decide when GC is constantly active. 我相信,您将考虑如何分析此统计数据并确定GC何时始终处于活动状态。

Because this question contains some new idea of applying GC statistic, I don't think, that it is duplicate. 因为这个问题包含了应用GC统计量的一些新想法,我不认为它是重复的。

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

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