Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java : Get heap dump without jmap or without hanging the application

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.

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.

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.

Note: Our application runs in CentOS.

Thanks, Arun

like image 480
Arun Avatar asked Dec 30 '13 03:12

Arun


People also ask

How do I manually take a heap dump?

Start the administrative console. In the navigation pane, click Troubleshooting > Java dumps and cores. Select the server_name for which you want to generate the heap dump. Click Heap dump to generate the heap dump for your specified server.

How do I make an automatic heap dump?

Click the Runtime tab. Select the Enable automatic heap dump collection check box.

Does taking heap dump trigger GC?

So, by triggering a heap dump, you are forcing a Full GC - regardless of whether the heap needs one or not. That is why the GC didn't occur automatically - it did not need to run, but you forced it to. It is very unlikely that there is a regression or other problem with JDK 10 running JDK 8 bytecode.


1 Answers

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

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

Example:

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

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.

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.

like image 107
Tim Long Avatar answered Nov 16 '22 02:11

Tim Long