Having trouble with performance and scalability issues is not so uncommon in my working environment as it should be. That is a shame – but there are a lot of pretty tools out there in this java developer world, that can rescue my reputation as a hardworking and serious software craftsman. (The sole existence of such tools gives me the impression that there must be other performance and scalability idiots out there in java world)
A pretty neat thing might be a profiler and there are a lot of good and better ones available. For unknown reasons I personally fell in love with JProfiler many years before and sometimes I tend to evangelize my working mates using it. If you want to try it – the guys from ejtechnologies give you ten days time ;)
Although I used the pretty little thing called JProfiler very often over the years in various environments, I recently stumbled across a problem when I tried to use it with IBMs J9 virtual machine on a 64-Bit Linux. JProfiler has a very good built-in integration wizard that worked very good many times before, but not on the following system environment:
- VMware Server
- Suse Linux Enterprise 11 – 64 Bit
- IBM J9 JDK 1.6
- Apache Tomcat 7.0.27
- JProfiler 7.2.2
So I had to integrate this dream team manually.
- Prerequisite:
- Change tomcat setenv.sh
- Change catalina.sh
- Start Tomcat in profiling mode
- Connect with JProfiler GUI
JProfiler is downloaded and a licence is available.
http://www.ej-technologies.com/download/jprofiler/file
To install JProfiler I unzipped jprofiler_linux_7_2_2.tar.gz to opt/jprofiler.
Afterwards, it can be started by opt/jprofiler/jprofiler7/bin/jprofiler.sh
.
The following line needs to be introduced into the setenv.sh script of your Tomcat installation and is the key of a successfull handshake between the profiler and the JVM started by Tomcat.
export LD_LIBRARY_PATH=/opt/jprofiler/jprofiler7/bin/linux-x64
Next thing to do is to configure your JVM with JProfiler agent as a JVM native agent library. Besides that you should configure the agent to open up a server socket for remote connections of the JProfiler GUI.
You can do this for example within your catalina.sh script with the following line
exec "$_RUNJAVA" "$LOGGING_CONFIG" -agentpath:/opt/jprofiler/jprofiler7/bin/linux-x64/libjprofilerti.so=port=6766-Xshareclasses:none $JAVA_OPTS $CATALINA_OPTS -Djava.endorsed.dirs="$JAVA_ENDORSED_DIRS" -classpath "$CLASSPATH" -Dcatalina.base="$CATALINA_BASE" -Dcatalina.home="$CATALINA_HOME" -Djava.io.tmpdir="$CATALINA_TMPDIR" org.apache.catalina.startup.Bootstrap "$@" start
The part in bold letters is the change made to the original script line.
Simply done with the following command catalina.sh run
The output of tomcat console should be like that:
Using CATALINA_BASE: /opt/apache-tomcat-7.0.27-lab1
Using CATALINA_HOME: /opt/apache-tomcat-7.0.27-lab1
Using CATALINA_TMPDIR: /opt/apache-tomcat-7.0.27-lab1/temp
Using JRE_HOME: /opt/ibm-java-x86_64-60
Using CLASSPATH: /opt/apache-tomcat-7.0.27-lab1/bin/bootstrap.jar:/opt/apache-tomcat-7.0.27-ab1/bin/tomcat-juli.jar
JProfiler> Protocol version 37
JProfiler> Using JVMTI
JProfiler> Thread status info workaround enabled.
JProfiler> Restricted JVMTI version 1.1 detected.
JProfiler> 64-bit library
JProfiler> Listening on port: 6766.
JProfiler> Instrumenting native methods.
JProfiler> Native library initialized
JProfiler> VM initialized
JProfiler> Waiting for a connection from the JProfiler GUI ...
The Tomcat JVM will run Tomcat only if a JProfiler GUI is connected through port=6766.
Start JProfiler as mentioned above and then do the following clicks:
Attach locally through port 6766
Choose Instrumentation
SessionStartup can be easiliy skipped with “OK”
Congratulations you have reached the next level in your quest for better java web application performance ;)


Very helpful, much appreciated :)
AFAIK the “-agentpath….” bit can also go into tomcat/bin/setenv.sh (making it a single point of maintenance, e.g. when changing versions, enabling/disabling the agent, etc)
Thanks for helpful article. I agree that it’s even better to add the jprofiler options to the “CATALINA_OPTS” in the setenv.sh file.
Some additional hints from my analysis:
1. You can add the “nowait” option, so that the server doesn’t need to wait for the JProfiler GUI to connect. In this example the complete option would look like this:
-agentpath:/opt/jprofiler/jprofiler7/bin/linux-x64/libjprofilerti.so=port=6766,nowait
2. It might be necessary to remove the remote debugging options if they are also defined, as the definition of the “agentpath” and “agentlib” JVM options at the same time might cause some problems.