Tuesday, August 07, 2012

Profiling tomcat using jvisualvm

 

Enabling Eclipse to use JMX listener on tomcat server

  1. Using the Servers view double click on your server
  2. Click on "Open Launch Configuration"
  3. Go to "Arguments" tab
  4. In "VM arguments" text box (one on the bottom) add following:
    -Dcom.sun.management.jmxremote=true
    -Dcom.sun.management.jmxremote.port=9090
    -Dcom.sun.management.jmxremote.ssl=false
    -Dcom.sun.management.jmxremote.authenticate=false
  5. Launch jvisualvm (in the bin directory of your JDK, version 1.5 or newer)
  6. Under Applications window you should see "local" and "Tomcat", right and "Open"; this will attach it

Using JVisualVM to profile a URL

After attaching to Tomcat process (above) you will have a Tomcat tab with 5 sub-tabs:
Overview - of the attached process
Monitor - of memory usage, threads active, loaded class count (here you can force garbage collector to clean up and generate heap dumps which can be used to do detailed analysys using eclipse with MAT plugin (download by usual Install New Software... in eclipse).
Threads - detailed thread information
Sampler - CPU or Memory can be sampled (method and CPU time logged)
Profiler - CPU or Memory can be profiled (time and invocation count logged)