Tuesday 3 May 2011

Installing APR based Tomcat Native library

After installing Tomcat I kept seeing the following message in the Catalina logs:

INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: /usr/lib/jvm/java-6-openjdk/jre/lib/i386/client:/usr/lib/jvm/java-6-openjdk/jre/lib/i386:/usr/lib/jvm/java-6-openjdk/jre/../lib/i386:/usr/java/packages/lib/i386:/usr/lib/jni:/lib:/usr/lib

This got my curiosity up and after learning about APR and the benefits it supposedly offers, I decided I would try it out and see if I could notice any difference in performance. Luckily, there's a package in Ubuntu for the Tomcat native libraries, making it easy to install:

sudo apt-get install libtcnative-1

This should install the library as well as all of the packages that it depends on. I restarted Tomcat after installing this package, but it still didn't detect the library. I couldn't get around this problem and didn't manage to solve it. It turned out that the next time I started my laptop I didn't get the warning in the logs, but instead I saw:

03/05/2011 3:39:15 PM org.apache.catalina.core.AprLifecycleListener init
INFO: Loaded APR based Apache Tomcat Native library 1.1.19.
03/05/2011 3:39:15 PM org.apache.catalina.core.AprLifecycleListener init
INFO: APR capabilities: IPv6 [true], sendfile [true], accept filters [false], random [true].


I think that some part of the Tomcat/JVM stack scans for the libraries when the computer starts and caches them from then on and this was what was causing Tomcat to not see the native library files straight away after install.

Now that Tomcat had detected and was using the libraries, I loaded up a few test projects as well as looking at the example projects included with the Tomcat install, but couldn't notice any difference in performance. Hopefully in the next few weeks I can go ahead and test out Tomcat performance using JMeter, ab or something similar and compare the results with APR and without.

NOTE: Just as an update to this post, the process for installing Tomcat Native on CentOS is a lot more complicated as there is no 'libtcnative' package for CentOS and the best guide I've found for it so far involves compiling 'libtcnative' from source.

No comments: