Profile Tomcat Application With VisualVM

不想你离开。 提交于 2019-11-30 05:54:06

问题


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 button (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.


回答1:


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.




回答2:


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




回答3:


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/




回答4:


All you need to do it set these VM options:

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



来源:https://stackoverflow.com/questions/1890431/profile-tomcat-application-with-visualvm

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!