How to connect jprofiler with tomcat 7.0.27 running on IBM J9 64-Bit JDK(Linux)

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.

  1. Prerequisite:
  2. 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 .

  3. Change tomcat setenv.sh
  4. 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

  5. Change catalina.sh
  6. 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.

  7. Start Tomcat in profiling mode
  8. 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.

  9. Connect with JProfiler GUI

Start JProfiler as mentioned above and then do the following clicks:

Menu Session->NewSession
NewSession

Attach locally through port 6766
AttachLocalhost
Choose Instrumentation
Instrumentation
SessionStartup can be easiliy skipped with “OK”
SessionStartup

Congratulations you have reached the next level in your quest for better java web application performance ;)

Short URL for this post: http://wp.me/p4nxik-1yG
This entry was posted in Java Runtimes - VM, Appserver & Cloud and tagged , , , , , . Bookmark the permalink.

One Response to How to connect jprofiler with tomcat 7.0.27 running on IBM J9 64-Bit JDK(Linux)

  1. Pelit Mamani says:

    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)

Leave a Reply