Profile Tomcat Application With VisualVM
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/