使用Eclipse Memory Analyzer(MAT)解决Java Web应用故障

来源:互联网 发布:虚拟定位ios软件 编辑:程序博客网 时间:2024/06/01 09:17


转载地址:http://guoyong.me/dev/solve-jvm-oom-problem-with-mat/

这周一我负责维护的一个系统突然出现故障,用户反映系统很慢,浏览器加载半天最后进了错误页面。登录到系统查看,发现系统负载很高,用sar命令进一步明确了是java进程在某一时刻后突然占据了大量CPU资源。查看应用日志,发现了OutOfMemory异常,然后使用jstat的gcutil确认JVM heap工作不正常,已经有上千次的full gc了。

用VisualGC或者jmap工具生成Headp dump文件,然后用MAT打开,生成内存泄露的分析报告,查找占用内存最大的对象并通过Thread call stack就可以定位导致问题出现的类和方法。

由于系统属旧系统,代码一直没有改动,显然是数据出了问题。最终发现是用户输入的格式不规范的数据,使得对数据做查找替换的一段代码不断地扩大1个字符串对象,导致内存消耗不断增长,gc频繁。

# sar
# sar -P ALL 1 5
# jstat -gcutil <pid_of_jvm> 1000
# jmap -dump:format=b,file=HeapDump.hprof <pid_of_jvm>

参考: http://wiki.eclipse.org/index.php/MemoryAnalyzer

This entry was posted in Dev and tagged 运维, heap dump, Java, jvm, mat by guoyong. Bookmark thepermalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

To create code blocks or other preformatted text, indent by four spaces:

    This will be displayed in a monospaced font. The first four     spaces will be stripped off, but all other whitespace    will be preserved.        Markdown is turned off in code blocks:     [This is not a link](http://example.com)

To create not a block, but an inline code span, use backticks:

Here is some inline `code`.
For more help see http://daringfireball.net/projects/markdown/syntax

原创粉丝点击