Pitfalls Experienced When Profiling Tomcat Webapps with VisualVM and NetBeans
Join the DZone community and get the full member experience.Join For Free
profiling a webapp running on tomcat with visualvm or netbeans wasn’t as easy as expected, so this is a brief record of what to avoid to succeed.
environment: mac os x, java jdk 1.6.0_29, netbeans 7.1, visualvm 1.3.3 (installed separately), tomcat 6.
- visualvm sampler and profiler: to be able to drill down to the slow methods you need to take a snapshot before you stop the sampling/profiling (there is a [snapshot] button above the hot spots list). this is not very intuitive and the interface doesn’t communicate it.
- visualvm profiler: excludes thread.sleep() & object.wait() time (as opposed to the netbeans profiler where you can choose to include/exclude them) => if you method is spending lot of time waiting for a lock, you won’t discover it
- you might need to allow unsafe, passwordless jmx connections in your tomcat config, see resources
- while visualvm was able to dynamically connect to my tomcat, netbeans wasn’t able to do it and hasn’t provided any notification about the failure. the only visible manifestation was that it wasn’t showing and collecting any data. solution: use the “direct” attach invocation, i.e. starting the target java application with the netbeans profiling agentlib.
extremely useful tool, included in jdk since 6.0 (command line: jvisualvm) or on the visualvm page .
- automatically discovers local java processes and can connect to them (if they run java 6+)
- monitoring – threads, heap, permgen, cpu, classes
- sampler – low-overhead profiling tool (takes thread snapshot at regular intervals and compares their stack traces to find out where most time is spent)
- plugins, such as mbeans, tracers
- profiler – a simpler version of netbeans profiler ( comparison here ); it can dynamically attach to running (java 6+) processes and instrument classes on-the-fly. the not very visible checkbox settings in the right-top corner can be used to set the classes to start profiling from (syntax: my.package.** to include subpackages or my.package.* or my.pkg.myclass) and the packages not to / only to profile (syntax differs here: my.package.* to include subpackages or my.package. or my.pkg.).
- profiling with visualvm, part 1 (6/2008) and part 2 , including comparison with the full nb profiler
- profiling tomcat with visualvm on mac os x – including jmx setup in tomcat
NetBeans Apache Tomcat
Opinions expressed by DZone contributors are their own.