开发者

Profile Tomcat Application With VisualVM

I would like to profile an application that runs on Tomcat with the VisualVM tool. Unfortunately, when I tell VisualVM to profile Tomcat, Tomcat prints out a couple of messages indicating it is connecting to a profile tool and then simply exits.

Details…

I am using Windows XP, Tomcat 6, VisualVM 1.2.1, and JDK 1.6.0_11.

  1. In Visual VM, I right-click on the Tomcat Application and select “Profile”
  2. In the Profiler Tab, I press the Memory butto开发者_如何学编程n (or the CPU button).
  3. Tomcat exits

Note that if I right-click on the Tomcat Application and select “Heap Dump” that seems to work OK.


I have VisualVM profiling working with my Tomcat application now. I needed to add the following parameters to the tomcat startup:

-Dcom.sun.management.jmxremote.port=8086
-Dcom.sun.management.jmxremote.ssl=false
-Dcom.sun.management.jmxremote.authenticate=false

Here is a nice article on monitoring Tomcat with VisualVM.


Yes we do profile Tomcat applications.

Go to catalina.bat or catalina.sh and this to your JAVA_OPTS (I am using Tomcat 6.0.16):

-Dcom.sun.management.jmxremote=true -Dcom.sun.management.jmxremote.port=9090 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false

Your JAVA_OPTS should look like

set JAVA_OPTS=%JAVA_OPTS% -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djava.util.logging.config.file="%CATALINA_BASE%\conf\logging.properties" -Dcom.sun.management.jmxremote=true -Dcom.sun.management.jmxremote.port=9090 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false

Updated after Ryan comment that it is better to use setenv.sh. This is my setenv.sh for JDK 8. Missing few other settings but good to start with.

SUN_JVM_OPTS="
    -server \
    -XX:MaxMetaspaceSize=3G \
    -XX:+UseConcMarkSweepGC -XX:+CMSParallelRemarkEnabled \
    -XX:+UseCMSInitiatingOccupancyOnly -XX:CMSInitiatingOccupancyFraction=70 \
    -XX:+ScavengeBeforeFullGC -XX:+CMSScavengeBeforeRemark \
    -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=3 -XX:GCLogFileSize=2M \
    -XX:+HeapDumpOnOutOfMemoryError \
    -Dsun.net.inetaddr.ttl=60 \
    -Dcom.sun.management.jmxremote  \
    -Dcom.sun.management.jmxremote.port=8480 \
    -Dcom.sun.management.jmxremote.authenticate=false \
    -Dcom.sun.management.jmxremote.ssl=false"


# Set custom application options here
APPLICATION_OPTS="-Dlog4j.configurationFile=patht-to-log/log4j2.xml -Dlog4j.debug=true "

JVM_OPTS="$GENERAL_JVM_OPTS $SUN_JVM_OPTS"
CATALINA_OPTS="$JVM_OPTS $APPLICATION_OPTS"
echo "Tomcat started with settings "$CATALINA_OPTS

Once you drop the setenv.sh in bin directory, you can see the changes in console on startup.

Here's another step by step tutorial to profile Tomcat applications with Visual VM: Trouble shooting application performance with Visual VM


I am using Tomcat 7 and the full configuration reqires more parameters to work.

-Dcom.sun.management.jmxremote=true 
-Dcom.sun.management.jmxremote.port=9090 # port to connect JMX 
-Dcom.sun.management.jmxremote.ssl=false
-Dcom.sun.management.jmxremote.authenticate=false
-Djava.rmi.server.hostname=50.112.22.47" # IP of the server running tomcat (it is necessary)

source: http://blog.markshead.com/1129/connecting-visual-vm-to-tomcat-7/


All you need to do it set these VM options:

-XX:+UnlockCommercialFeatures -XX:+FlightRecorder -XX:+UnlockDiagnosticVMOptions -XX:+DebugNonSafepoints -XX:FlightRecorderOptions=stackdepth=512

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜