Java: getting a heap dump without jmap or without application freezing

In few circumstances, our application uses about 12 GB of memory. We tried to get a bunch of heaps using the jmap utility. Since the application uses some GB of memory, this causes the application to stop responding and causes problems during production.

In our case, heap usage suddenly increases from 2-3 GB to 12 GB in 6 hours. In an attempt to find a trend in memory usage, we tried to collect a bunch of heaps every hour after restarting the application. But, as said, since the use of jmap causes the application to freeze, we need to restart it, and we cannot get the tendency to use memory.

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

Thoughts on this are highly appreciated, since without getting a memory usage trend it is very difficult to solve the problem.

Note. Our application runs on CentOS.

Thanks Arun

+5
java heap memory jmap
Dec 30 '14 at 3:12
source share
5 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 reset process is much faster than resetting with jmap! Dumpfiles are much smaller, but this is enough to give you your idea where there are leaks.

When writing this answer, there are errors with Memory Analyzer and IBM HeapAnalyzer that they cannot read dumpfiles from jmap (jdk8, large files). You can use Yourkit to read these files.

+5
Nov 19 '16 at 11:56
source share

First of all, this (AFAIK) needs to freeze the JVM when taking a dump / snapshot of a stream. If the JVM was able to continue working while creating the snapshot, it would be almost impossible to get a sequential snapshot.

So are there other ways to get a bunch of heaps?

  • You can get a bunch of heaps using VisualVM, as described here .

  • You can get a bunch of heaps using jconsole or Eclipse Memory Analyzer as described here .

But they are all related to the fact that the JVM (at least) is paused.




If your application really hangs (constantly!), This seems like a problem with the application itself. My suggestion would be to see if you can track this issue before looking for a storage leak.

My other suggestion is that you look at one heap bush and use statistics to figure out which objects of the object use all the space ... and why they are reachable. There is a good chance that you do not need trend information at all.

+2
Dec 30 '14 at 5:03
source share

You can use GDB to get a heap dump without running jmap on the target virtual machine, but this still hangs the application for the time it takes to write the heap dump to disk. Assuming a disk speed of 100 MB / s (a basic mirrored array or one disk), this is another 2 minutes of downtime. http://blogs.atlassian.com/2013/03/so-you-want-your-jvms-heap/

The only sure way to avoid stopping the JVM is with transactional memory and the kernel, which uses it to provide a snapshot of the process. This is one of the dreams of STM supporters, but it is not yet available. The hot migration of VMWare is approaching, but depends on the distribution speed not exceeding the network bandwidth, and it does not save snapshots. Ask them to add it for you, it will be a neat feature.

+1
Mar 11 '15 at 10:43
source share

To add to Stephen's answers, you can also run a bunch of heaps via the API for the most common JVM implementations:

0
May 18 '14 at 8:54
source share

A heap dump analyzed with the right tool will tell you what the heap is consuming. This is the best tool for tracking memory leaks. However, collecting heap dumps is slow, not to mention analyzing it.

Knowing the operation of your application, sometimes a histogram is enough to give you a hint where to look for a problem. For example, if MyClass$Inner is at the top of the histogram, and MyClass$Inner used only in MyClass , then you know exactly which file to look for the problem.

Here is the command to collect the histogram.

jcmd pid GC.class_histogram filename=histogram.txt

0
Feb 06 '19 at 21:49
source share



All Articles