aspose file tools*
The moose likes Performance and the fly likes Tomcat Heap Dump  - SOLVED Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Performance
Bookmark "Tomcat Heap Dump  - SOLVED" Watch "Tomcat Heap Dump  - SOLVED" New topic
Author

Tomcat Heap Dump - SOLVED

Jaz Chana
Ranch Hand

Joined: Feb 19, 2008
Posts: 34
Hi Guys,

I'm using tomcat version 5.5 with jdk 5. I would like to create a heap dump file while the server is running so that I can use this in some monitoring application. How would I do this?
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16250
    
  21

You have to start the Tomcat server with the profiling options you want to be used. I believe that the JAVA_OPTIONS environment variable can be used to pass them into the catalina startup script.

To actually get a snapshot taken, you fire a signal to the Tomcat server. In Linux, this can be done using the "kill" command. If you send the right signal "kill" won't actually kill the app, it simply triggers a JVM snapshot. You can do this as many times as you like (they will be appended).

I'd be more specific, but I'd have to go back and RTFM. I've forgotten the exact details.


Customer surveys are for companies who didn't pay proper attention to begin with.
Jaz Chana
Ranch Hand

Joined: Feb 19, 2008
Posts: 34
Thanks for the advice Tim. I noticed that you cant use this for java 1.6. I had to do a little messing around, but I finally managed to get the memory dumps I needed. I've put together a rough HowTo for those that are interested;

For java 1.5 use:

1) Find the following line of code in your catalina.sh file;

elif [ "$1" = "start" ] ; then

2) Underneath this line add the following;

JAVA_OPTS="$JAVA_OPTS -XX:+HeapDumpOnCtrlBreak -Dcatalina.ext.dirs=$CATALINA_HOME/shared/lib:$CATALINA_HOME/common/lib -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=9004 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false"

Specifically the command -XX:+HeapDumpOnCtrlBreak will generate the heap dump file.

3) Start up tomcat as usual
4) After a few minutes get the process id of the tomcat process

ps ux | grep apache

look for anything in the line that says tomcat_version….

5) Use this process id to send a signal to the process with the following code

kill -3 <pid>

6) This will create a new file in the bin directory of you tomcat root installation directory with the .hprof.date.time extension. Remove the date.time extension and you can use this file with memory monitoring applications like eclipse based memory analyser

For java 1.6 use: jmap or jconsole
-both of these are tools that come bundled with package. They located in JAVA_HOME/bin.

jmap
1) Find the pid of the process

ps ux | grep [java/apache]

2) Use the following command to invoke jmap

$JAVA_HOME/bin/jmap -dump:live,file=heap.dump.out,format=b <pid>

jconsole

1) Find the following line of code in your catalina.sh file;

elif [ "$1" = "start" ] ; then

2) Underneath this line add the following;

JAVA_OPTS="$JAVA_OPTS -Dcatalina.ext.dirs=$CATALINA_HOME/shared/lib:$CATALINA_HOME/common/lib -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=9004 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false"

3) Open jconsole (just type jconsole)
4) Go to the mbeans tab
5) In the left hand tree structure look for the following folder; com.sun.management. Expand and click on HotSpotDiagnostic
6) In the right hand window click on operations. There should be an option to dump the heap memory in the tomcatHome/bin directory

Sravan revuru
Greenhorn

Joined: Feb 07, 2011
Posts: 1
Hi,

Can you tell me the same process for Windows - tomcat version....
windows 7
Tocat 6.0
jdk 1.5

wat shoud i change in catalina.bat


thanks,
Sravan
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Tomcat Heap Dump - SOLVED