Tomcat Native Library

This article deals with the use of the Apache Tomcat Native Library to speed up Liferay.

Basic Overview #

The Apache Tomcat Native Library is a JNI (Java Native Interface) that provides many of Tomcat's core functionality in native code instead of Java bytecode. What does this mean? SPEED. For a cursory speed comparison, here is the startup time for my Liferay running on Tomcat without it installed:

 INFO: Server startup in 14463 ms

And, with the native library installed:

 INFO: Server startup in 13266 ms

That's about a 10% speed boost. If you do not have the native library properly installed on your system, your log files will always begin with something that looks like this:

 INFO: The Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: .:/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java

Installation #

Linux #

(Tested with standard Tomcat 5.5.17 downloaded from Apache site, running on Ubuntu 7.04 - Feisty Fawn)

  1. Make sure that you have the libssl-dev and libapr1-dev packages installed$ apt-get install libssl-dev libapr1-dev
  2. Switch to your tomcat's bin directory$ cd ${TOMCAT_HOME}/bin
  3. Extract the tarball (tarred and gzipped archive) of the tomcat native lib$ tar -xvzf tomcat-native.tar.gz
  4. Jump into the source folder$ cd tomcat-native-1.1.3/jni/native
  5. Configure, make and install it$ ./configure --with-apr=/usr && make && sudo make install
  6. Change to the system library folder$ cd /usr/lib
  7. Make a convenience link to you new library$ sudo ln -s /usr/local/apr/lib/libtcnative-1.so libtcnative-1.so
  8. Edit ${TOMCAT_HOME}/bin/catalina.sh adding the following lines somewhere before the java program is executedLD_LIBRARY_PATH=/usr/lib:$LD_LIBRARY_PATHexport LD_LIBRARY_PATH
  9. Finally, edit /etc/modprobe.d/aliases and change the linealias net-pf-10 ipv6toalias net-pf-10 off ipv6 and reboot. This disables IPV6 which the library does not support yet (and hence will throw exceptions when trying to bind to TCP ports on network devices having IPV6 enabled).
  10. Restart tomcat and enjoy!

Mac OS X #

  • Make sure to have installed the latest version of MacPorts.
  • From the Terminal program, install and make symbolic links of the native libraries:
sudo port install tomcat-native
sudo ln -s /opt/local/lib/libtcnative-1.* /usr/lib/java
  • Restart Tomcat and enjoy!

Windows #

  1. Download http://archive.apache.org/dist/tomcat/tomcat-connectors/native/1.1.15/binaries/win64/x64/
  2. Copy tcnative-1-ip4.dll to %TOMCAT_HOME%/bin
  3. Restart Tomcat and enjoy!

JBoss-Tomcat Bundle #

If you are running with JBoss-Tomcat, be aware that the standard APR will not work properly. This is because JBoss makes some modifications to the Tomcat that is part of its bundle. For instructions on how to install the native libraries for JBoss-Tomcat, see the documentation at http://wiki.jboss.org/wiki/Wiki.jsp?page=HowToAddAprToJBoss. Liferay running on JBoss AS 4.0.5 has been reported to run with JBoss Native 2.0.1 performing, under load, with about a 20% speed boost.

0 Anhänge
71259 Angesehen
Durchschnitt (5 Stimmen)
Die durchschnittliche Bewertung ist 4.8 von max. 5 Sternen.
Kommentare
Antworten im Thread Autor Datum
This is a fantastic article. I followed these... Ahmed Hasan 27. Februar 2010 06:10

This is a fantastic article. I followed these steps to set up APR native tomcat in our of our LINUX based production servers. Just few minor points i would like to highlight, so that i can help people like me.

1. In step 5, it may give the problem - "Unable to find JDK". In your command prompt, give "export JAVA_HOME=/usr/liv/jvm/java-6-sun"

2. Step no 8, insert the following line in your "setenv.sh" under "tomcat/bin",

export LD_LIBRARY_PATH=/usr/lib:$LD_LIBRARY_PATH

3. In step 9, you may NOT find the file aliases. Do the following steps,

a. touch /etc/modprobe.d/aliases
b. vi /etc/modprobe.d/aliases
c. insert the line, "alias net-pf-10 off ipv6"
d. save and close the file

4. Re-boot the server with the command "init 6"

5. After reboot, start your tomcat.
Gepostet am 27.02.10 06:10.