Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Collecting Java heapdump under load

Tags:

java

tomcat

I am running load against Tomcat 6 running on Java 6. I want to collect a heapdump of the Java heap while the Tomcat server is under load. I normally use jmap -dump to collect my heapdumps.

However, when I try to do this when Tomcat is handling a high load I find that the heapdump collection fails.

Is jmap the best tool for collecting a heap dump from a process under load? What are the possible causes which would cause jmap to fail to collect a heapdump?

If jmap is not the best tool - what is better?

It is entirely acceptable to me for jmap (or some other tool) to stop the world within the Java process while the heap dump is taken.

like image 369
mchr Avatar asked Aug 19 '10 11:08

mchr


People also ask

How do I capture Heapdump?

Right-click on one of the Java process. Click on the 'Heap Dump' option on the drop-down menu. Heap dump will be generated. File path where heap dump is generated will be specified in the Summary Tab > Basic Info > File section.

When should I take a heap dump?

A heap dump is a snapshot of all the objects that are in memory in the JVM at a certain moment. They are very useful to troubleshoot memory-leak problems and optimize memory usage in Java applications. Heap dumps are usually stored in binary format hprof files.

What do you look for in a Java heap dump?

Heap dumps contain a snapshot of all the live objects that are being used by a running Java application on the Java heap. We can obtain detailed information for each object instance, such as the address, type, class name, or size, and whether the instance has references to other objects.


3 Answers

Is jmap the best tool for collecting a heap dump from a process under load?

I think: No it isn't. From this link:

NOTE - This utility is unsupported and may or may not be available in future versions of the JDK.

like image 174
sourcerebels Avatar answered Oct 16 '22 11:10

sourcerebels


I've also found jmap can pretty temperamental. If you're having problems:

  • Try it again. It often manages to get a heap dump after a couple of attempts if it first fails
  • Use the -F option
  • Add -XX:+HeapDumpOnOutOfMemoryError as a standard configuration to proactively take heap dumps when an OOM error is thrown
  • Run Tomcat interactively and add the heap dump on ctrl-break option. This gives you a thread dump too, something you'll probably need anyway
  • If your heap size is especially large and you have a repeatable condition, temporarily lower your heap size. It makes the resulting file much easier to handle, takes less time and is more likely to succeed
like image 28
Danny Thomas Avatar answered Oct 16 '22 10:10

Danny Thomas


I have found that running Tomcat with a JMX port allows me to take a remote heapdump using visualvm. This succeeded for me when jmap failed.

like image 2
mchr Avatar answered Oct 16 '22 10:10

mchr