I’m often using the excellent VisualVM tools to profile applications. It’s free (as in beer), delivered with the JDK and packed with enough tools to solve 99% of the performance problems. I have to give that credit to the authors they did an excellent job !
Today I tried to set up for a memory profiling of a Tomcat/Spring/Hibernate stack. The Tomcat instances didn’t show up in VisualVM’s "local" node. No problem. I’ll setup JMX to operate remotely and I’ll do it that way. Adding the properties to Tomcat’s …
… and restarted. Now I can connect to the Tomcat instance using port 3333.
I’m most often doing the profiling using the Sampler plugin. It’s fast and accurate enough for most profiling cases. While the "real" Profiler tool does code weaving to achieve a higher precision. (I guess.) And it takes a lot of time to patch a Tomcat with its applications deployed on.
The next problem is that the Sampler does not want to allow memory profiling for "remotely" connected JVM’s. CPU profiling is allowed however. I could do memory profiling with the JVM’s in the "local" node of VisualVM. So I have to make Tomcat visible again to VisualVM. I know that once worked !
In the end the solution is very straightforward: Set the environment variable CATALINA_TMPDIR to "/tmp". At least to the same value as the one of VisualVM. Once this is done, Tomcat pops-up again in VisualVM’s "local" node and you can do memory profiling using the Sampler plugin. I have no rational explanation (neither irrational for that matter) for this problem. At least now it works.
It seems to be an old problem however.
To make absolutely sure I’m not ever confronted with this I have put "export CATALINA_TMPDIR=/tmp" into a script in /etc/profile.d. Even if I re-install Tomcat, it will always work.
Hope this helps somebody too.