5

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.

mchr
  • 6,161
  • 6
  • 52
  • 74
  • 1
    Have you tried to attach VisualVM to the VM and create a HeapDump using that? – Johannes Wachter Aug 19 '10 at 12:18
  • This isn't ideal for me as my Tomcat is running on a remote Linux server. VisualVM includes support for remote heap dumps but this requires that a JMX port be opened when the JVM is started. – mchr Aug 19 '10 at 12:38
  • http://stackoverflow.com/questions/20235802/ways-how-to-get-heap-dump-from-running-tomcat-7 has more detailed answers. – Vadzim Jun 16 '14 at 09:42

3 Answers3

2

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.

sourcerebels
  • 5,140
  • 1
  • 32
  • 52
2

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
Danny Thomas
  • 1,879
  • 1
  • 18
  • 32
  • Thanks for this answer - I'll try retrying jmap next time. I have posted my own answer about using visualvm. – mchr Aug 28 '10 at 18:48
2

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.

mchr
  • 6,161
  • 6
  • 52
  • 74