利用APR本地库提高Tomcat性能(merged)
Tomcat可以使用APR来提供超强的可伸缩性和性能,更好地集成本地服务器技术。APR(Apache Portable Runtime)是一个高可移植库,它是Apache HTTP Server 2.x的核心。APR有很多用途,包括访问高级IO功能(例如sendfile,epoll和OpenSSL),OS级别功能(随机数生成,系统状态等等),本地进程管理(共享内存,NT管道和UNIX sockets)。这些功能可以使Tomcat作为一个通常的前台WEB服务器,能更好地和其它本地web技术集成,总体上让Java更有效率作为一个高性能web服务器平台而不是简单作为后台容器。
按照官方说明需要:
- APR library
- OpenSSL libraries
CentOS 可以直接用yum 安装 apr 和 ssl :
Requirements:
- APR 1.2+ development headers (libapr1-dev package)
- OpenSSL 0.9.7+ development headers (libssl-dev package)
- JNI headers from Java compatible JDK 1.4+
- GNU development environment (gcc, make)
The wrapper library sources are located in the Tomcat binary bundle, in the bin/tomcat-native.tar.gz
archive. Once the build environment is installed and the source archive is extracted, the wrapper library can be compiled using (from the folder containing the configure script):
./configure && make && make install | ||
手动安装:
openssl 可以用 yum install openssl-devel,apr还是下载*.gz来安装。
apr-1.3.2.tar.gz
apr-util-1.3.2.tar.gz
两个可以在 http://apache.mirror.phpchina.com/apr/ 找到。
tomcat-native.tar.gz 可以在tomcat/bin目录下找到。
安装 apr
- # wget http://apache.mirror.phpchina.com/apr/apr-1.3.2.tar.gz
- # tar zxvf apr-1.3.2.tar.gz
- # cd apr-1.3.2
- # ./configure
- # make
- # make install
- # wget http://apache.mirror.phpchina.com/apr/apr-1.3.2.tar.gz
- # tar zxvf apr-1.3.2.tar.gz
- # cd apr-1.3.2
- # ./configure
- # make
- # make install
- # wget http://apache.mirror.phpchina.com/apr/apr-1.3.2.tar.gz
- # tar zxvf apr-1.3.2.tar.gz
- # cd apr-1.3.2
- # ./configure
- # make
- # make install
apr 默认安装在 /usr/local/apr
安装 apr-util
- # wget http://apache.mirror.phpchina.com/apr/apr-util-1.3.2.tar.gz
- # tar zxvf apr-util-1.3.2.tar.gz
- # cd apr-util-1.3.2
- # ./configure --with-apr=/usr/local/apr
- # make
- # make install
- # wget http://apache.mirror.phpchina.com/apr/apr-util-1.3.2.tar.gz
- # tar zxvf apr-util-1.3.2.tar.gz
- # cd apr-util-1.3.2
- # ./configure --with-apr=/usr/local/apr
- # make
- # make install
- # wget http://apache.mirror.phpchina.com/apr/apr-util-1.3.2.tar.gz
- # tar zxvf apr-util-1.3.2.tar.gz
- # cd apr-util-1.3.2
- # ./configure --with-apr=/usr/local/apr
- # make
- # make install
安装 tomcat-native
- # cd /usr/local/tomcat-6.0.18/bin
- # tar zxvf tomcat-native.tar.gz
- # cd tomcat-native-1.1.14-src/jni/native
- # ./configure --with-apr=/usr/local/apr --with-java-home=/usr/java/jdk1.6.0_11
- # make
- # make install
- # cd /usr/local/tomcat-6.0.18/bin
- # tar zxvf tomcat-native.tar.gz
- # cd tomcat-native-1.1.14-src/jni/native
- # ./configure --with-apr=/usr/local/apr --with-java-home=/usr/java/jdk1.6.0_11
- # make
- # make install
- # cd /usr/local/tomcat-6.0.18/bin
- # tar zxvf tomcat-native.tar.gz
- # cd tomcat-native-1.1.14-src/jni/native
- # ./configure --with-apr=/usr/local/apr --with-java-home=/usr/java/jdk1.6.0_11
- # make
- # make install
设置 apr 的环境变量:
- # vi /etc/profile
- // 后面添加以下内容
- export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/apr/lib
- //使profile生效,
- # source /etc/profile
- # bin/startup.sh
- # head logs/catalina.out
- // 可以看到以下结果:
- 信息: Loaded APR based Apache Tomcat Native library 1.1.14.
- 2009-1-13 11:12:51 org.apache.catalina.core.AprLifecycleListener init
- 信息: APR capabilities: IPv6 [true], sendfile [true], accept filters [false], random [true].
- # bin/startup.sh
- # head logs/catalina.out
- // 可以看到以下结果:
- 信息: Loaded APR based Apache Tomcat Native library 1.1.14.
- 2009-1-13 11:12:51 org.apache.catalina.core.AprLifecycleListener init
- 信息: APR capabilities: IPv6 [true], sendfile [true], accept filters [false], random [true].
好了, 可以运行了,但没有测试其性能提升多少。
转自
參考自:http://www.chinajvm.com/main/helpcontent.jsp?id=5320b71a1eb098e2011ee230a2311367
http://blog.chenlb.com/2009/01/install-apache-portable-runtime-or-tomcat-native-on-tomcat.html