Como instalar o componente native library 1.2.3 no Tomcat 7.

Introdução

O Apache Tomcat Native Library é um componente opcional que permite você utilizar recursos (bibliotecas) nativos do sistema operacional, substituindo componentes Java padrões. Com Native Library instalado é possível melhorar o desempenho do servidor de aplicação.

Ambiente utilizado

  • CentOS 7
  • tomcat-native-1.2.3
  • apache-tomcat-7.0.67
  • openjdk-1.7.0.91

Pré-requisito

  • gcc
  • make
  • openssl-devel
  • apr-devel

Instalação

1) Baixar a ultima versão do Tomcat Native (1.2.3).

wget http://mirror.olnevhost.net/pub/apache/tomcat/tomcat-connectors/native/1.2.3/source/tomcat-native-1.2.3-src.tar.gz  

2) Compilar e instalar o componente tomcat-native.

tar xzvf tomcat-native-1.2.3-src.tar.gz  
cd tomcat-native-1.2.3-src/native

export JAVA_HOME=/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.91-2.6.2.3.el7.x86_64

export CATALINA_HOME=/opt/apache-tomcat-7.0.67

./configure --with-apr=/usr/bin/apr-1-config \
            --with-java-home=$JAVA_HOME \
            --with-ssl=yes \
            --prefix=$CATALINA_HOME

make 

make install  

3) Criar o arquivo setenv.sh dentro do $CATALINA_HOME/bin/

Arquivo: setenv.sh

LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$CATALINA_HOME/lib  
export LD_LIBRARY_PATH  

4) Validando.

Verifique se as bibliotecas foram criadas no diretório $CATALINA_HOME/lib/

-rw-r--r--  1 tomcat tomcat 1992904 Dec 28 14:22 libtcnative-1.a
-rwxr-xr-x  1 tomcat tomcat    1022 Dec 28 14:22 libtcnative-1.la
lrwxrwxrwx  1 tomcat tomcat      22 Dec 28 14:22 libtcnative-1.so -> libtcnative-1.so.0.2.3  
lrwxrwxrwx  1 tomcat tomcat      22 Dec 28 14:22 libtcnative-1.so.0 -> libtcnative-1.so.0.2.3  
-rwxr-xr-x  1 tomcat tomcat 1143597 Dec 28 14:22 libtcnative-1.so.0.2.3

Reinicie o tomcat e verifique se os arquivos de logs possuem a entrada abaixo:

grep -i apr $CATALINA_HOME/logs/catalina.out

catalina.out:INFO: Loaded APR based Apache Tomcat Native library 1.2.3 using APR version 1.4.8.

Testes de performance:

Componente native desabilitado:

$ ab -n 300 -c 20 http://localhost:8080/

This is ApacheBench, Version 2.3 <$Revision: 1430300 $>  
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/  
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking localhost (be patient)  
Completed 100 requests  
Completed 200 requests  
Completed 300 requests  
Finished 300 requests


Server Software:        Apache-Coyote/1.1  
Server Hostname:        localhost  
Server Port:            8080

Document Path:          /  
Document Length:        11197 bytes

Concurrency Level:      20  
Time taken for tests:   0.542 seconds  
Complete requests:      300  
Failed requests:        0  
Write errors:           0  
Total transferred:      3402900 bytes  
HTML transferred:       3359100 bytes  
Requests per second:    553.49 [#/sec] (mean)  
Time per request:       36.135 [ms] (mean)  
Time per request:       1.807 [ms] (mean, across all concurrent requests)  
Transfer rate:          6131.06 [Kbytes/sec] received

Connection Times (ms)  
              min  mean[+/-sd] median   max
Connect:        0    0   0.3      0       2  
Processing:     6   34  25.5     28     177  
Waiting:        4   32  23.0     27     176  
Total:          7   35  25.4     29     177

Percentage of the requests served within a certain time (ms)  
  50%     29
  66%     37
  75%     42
  80%     46
  90%     69
  95%     76
  98%    119
  99%    149
 100%    177 (longest request)

Componente native habilitado:

ab -n 300 -c 20 http://localhost:8080/

This is ApacheBench, Version 2.3 <$Revision: 1430300 $>  
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/  
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking localhost (be patient)  
Completed 100 requests  
Completed 200 requests  
Completed 300 requests  
Finished 300 requests


Server Software:        Apache-Coyote/1.1  
Server Hostname:        localhost  
Server Port:            8080

Document Path:          /  
Document Length:        11197 bytes

Concurrency Level:      20  
Time taken for tests:   0.352 seconds  
Complete requests:      300  
Failed requests:        0  
Write errors:           0  
Total transferred:      3402900 bytes  
HTML transferred:       3359100 bytes  
Requests per second:    852.50 [#/sec] (mean)  
Time per request:       23.460 [ms] (mean)  
Time per request:       1.173 [ms] (mean, across all concurrent requests)  
Transfer rate:          9443.27 [Kbytes/sec] received

Connection Times (ms)  
              min  mean[+/-sd] median   max
Connect:        0    1   1.1      0       6  
Processing:     6   21  15.6     17     102  
Waiting:        6   20  15.1     16     102  
Total:          7   22  15.8     17     103

Percentage of the requests served within a certain time (ms)  
  50%     17
  66%     20
  75%     24
  80%     28
  90%     42
  95%     55
  98%     84
  99%     97
 100%    103 (longest request)

Repare que o tempo de processamento (conexões) caiu bastante e numero de requests aumentaram.

Abraços.