Troubleshooting application performance with VisualVM
Those of you who have not heard about VisualVm , we had talked about it in earlier post Performance tuning your java and J2ee applications.
This is one of the best free tools for monitoring the performance of your java/j2ee application. If you try to use VisualVM with myeclipse, you will have to upgrade from basic license of $30 ! But if you follow the rest of the post , I will explain how to do it for free.
Not many people have worked with it but it sure gives you a deeper insight of your application and helps in locating the problematic areas. The motivation for us was to identify the out of memory exceptions were facing in our application and pinpoint the cause.
In this post we will talk about Visual VM, setting it up with your eclipse and how to monitor your application. We will set up a web application and run visualVM to monitor the application
1. What is Visual VM
Java Management Extensions (JMX) had been part of java since JDK 5.0. JMX enables you to get all the information from the JVM. VisualVM is a visual tool that integrates some of the commandline JDK tools and gives you powerful profiling capabilities. VisualVM uses JMX and gives you detailed info about JVM memory, CPU usage, Garbage Collection . It can also profile your objects for CPU and memory usage suggested for local JVM’s only.
More about VisualVM
2. Installing Visual VM
Visual VM comes bundled with your JDK install ,(post JDK 1.6 update 7). Alternatively you can go to https://visualvm.dev.java.net/download.html and download the file.
Once installed , go to <installed directory>/bin and click visualvm.exe.
It will fire up the visualVM for you.
3. Setting up the tomcat for Visual VM
Since we would be profiling a web application , let us configure tomcat to run with VisualVM. We would be adding some parameters to use JMX with Tomcat
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
4. Connect your tomcat with VisualVM
Start your tomcat and fire up your Visual VM. If Tomcat is running locally, then you would see a Tomcat icon under Local
If tomcat is running on Remote machine, click on Remote and set up the parameters
4. Setting up Visual VM with Eclipse
5. Identifying the problem
With Visual VM fired up , we did a peek of what was happening inside the visual VM and could identify the problem source , the heap size and connection pool
Here is peek inside application with Visual VM
This has been covered in two different posts