Java:在没有jmap或不挂起应用程序的情况下获取堆转储 [英] Java : Get heap dump without jmap or without hanging the application

查看:353
本文介绍了Java:在没有jmap或不挂起应用程序的情况下获取堆转储的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在少数情况下,我们的应用程序使用大约12 GB的内存. 我们尝试使用jmap实用程序获取堆转储.由于应用程序正在使用一些GB的内存,因此会导致应用程序停止响应并在生产中引起问题.

In few circumstance, our application is using around 12 GB of memory. We tried to get the heap dump using jmap utility. Since the application is using some GB of memory it causes the application to stop responding and causes problem in production.

在我们的例子中,堆使用率在6小时内突然从2-3 GB增加到12GB.为了找到内存使用趋势,我们尝试在重新启动应用程序后每隔一小时收集一次堆转储.但是如前所述,由于使用jmap会导致应用程序挂起,因此我们需要重新启动它,而我们无法掌握内存使用的趋势.

In our case the heap usage suddenly increases from 2-3 GB to 12GB in 6 hours. In an attempt to find teh memory usage trend we tried to collect the heap dump every one hour after restarting the application. But as said since using the jmap causes the application to hang we need to restart it and we are not able to get the trend of memory usage.

是否有一种无需挂起应用程序即可获取堆转储的方法,或者是否有jmap以外的实用程序来收集堆转储.

Is there a way to get the heap dump without hanging the application or is there a utility other than jmap to collect heap dump.

对此想法高度赞赏,因为如果不掌握内存使用趋势,就很难解决此问题.

Thoughts on this highly appreciated, since without getting the trend of memory usage it is highly difficult to fix the issue.

注意:我们的应用程序在CentOS中运行.

Note: Our application runs in CentOS.

谢谢, 阿伦

推荐答案

请尝试以下操作.它带有JDK> = 7:

Try the following. It comes with JDK >= 7:

/usr/lib/jvm/jdk-YOUR-VERSION/bin/jcmd PID GC.heap_dump FILE-PATH-TO-SAVE

示例:

/usr/lib/jvm/jdk1.8.0_91/bin/jcmd 25092 GC.heap_dump /opt/hd/3-19.11-jcmd.hprof

此转储过程比使用jmap进行转储要快得多!转储文件要小得多,但足以让您知道泄漏的位置.

This dumping process is much faster than dumping with jmap! Dumpfiles are much smaller, but it's enough to give your the idea, where the leaks are.

在编写此答案时,Memory Analyzer和IBM HeapAnalyzer存在一些错误,即它们无法从jmap读取转储文件(jdk8,大文件).您可以使用Yourkit读取这些文件.

At the time of writing this answer, there are bugs with Memory Analyzer and IBM HeapAnalyzer, that they cannot read dumpfiles from jmap (jdk8, big files). You can use Yourkit to read those files.

这篇关于Java:在没有jmap或不挂起应用程序的情况下获取堆转储的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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