APR:Apache Portable Run-time libraries,Apache可移植執行庫
在早期的Apache版本號中。應用程序本身必須可以處理各種詳細操作系統平台的細節,並針對不同的平台調用不同的處理函數。
在早期的Apache版本號中。應用程序本身必須可以處理各種詳細操作系統平台的細節,並針對不同的平台調用不同的處理函數。
隨着Apache的進一步開發。Apache組織決定將這些通用的函數獨立出來並發展成為一個新的項目。這樣。APR的開發就從Apache中獨立出來,Apache不過使用APR而已。
Tomcat Native:
這個項目能夠讓 Tomcat 使用 Apache 的 apr 包來處理包含文件和網絡IO操作,以提升性能。
官網介紹:
The Apache Tomcat Native Library is an optional component for use with Apache Tomcat that allows Tomcat to use certain native resources for performance, compatibility, etc.
(大概意思是Tomcat能夠利用一些native資源來提高性能和兼容性。
)
Specifically, the Apache Tomcat Native Library gives Tomcat access to the Apache Portable Runtime (APR) library's network connection (socket) implementation and random-number generator.
(詳細來說是利用了APR庫中的網絡連接實現和隨機數生成器。)
Features of the APR connector:
- Non-blocking I/O for Keep-Alive requests (between requests)
- Uses OpenSSL for TLS/SSL capabilities (if supported by linked APR library)
- FIPS 140-2 support for TLS/SSL (if supported by linked OpenSSL library)
Linux下,Tomcat啟用APR須要三個組件:
- apr
- apr-util
- tomcat-native.tar.gz(Tomcat自帶,在bin文件夾下)
1、查看是否已經安裝了apr和apr-util
# rpm -qa apr
apr-1.4.8-3.el7.x86_64
# rpm -qa apr-util
apr-util-1.5.2-6.el7.x86_64
2、查看是否有最新版的apr和apr-util
# yum list | grep apr
apr.x86_64 1.4.8-3.el7 @anaconda
apr-util.x86_64 1.5.2-6.el7 @anaconda
3、假設還沒安裝,用yum安裝:
# yum install apr-devel apr apr-util
4、安裝tomcat-native:
搜索tomcat-native安裝包:
# yum list | grep tomcat-native
假設已經存在,直接安裝:
# yum install tomcat-native
……
正在安裝 : tomcat-native-1.1.30-1.el7.x86_64 1/1
驗證中 : tomcat-native-1.1.30-1.el7.x86_64 1/1
已安裝:
tomcat-native.x86_64 0:1.1.30-1.el7
完成!
查看是否成功安裝:
# rpm -qa tomcat-native
tomcat-native-1.1.30-1.el7.x86_64
配置相關的全局變量:
# vi /etc/profile
加入:export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/apr/lib
# source /etc/profile
5、重新啟動Tomcat。看看能否夠成功使用APR
假設一切正常:
APR啟動:
[main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["http-
apr
-18080"]
[main] org.apache.catalina.startup.Catalina.start Server startup in
13617 ms
相比NIO模式的啟動,速度快了一些(~15%):
NIO啟動:
[main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["http-
nio-18080"]
[main] org.apache.catalina.startup.Catalina.start Server startup in
15671 ms
假設發現異常log,比方:
06-Aug-2015 14:46:04.949 SEVERE [main] org.apache.catalina.core.AprLifecycleListener.init An incompatible version 1.1.30 of the APR based Apache Tomcat Native library is installed, while To
mcat requires version 1.1.32
說明系統自帶的tomcat-native版本號太低。
刪除:
# yum erase tomcat-native
用yum檢查有沒有最新版:
# yum update tomcat-native
假設yum找不到最新版。則
下載或從Tomcat/bin中解壓安裝。
從Tomcat/bin文件夾中,解壓tomcat-native.tar.gz文件:
# tar -zxvf tomcat-native.tar.gz
得到目錄:tomcat-native-1.1.33-src
# cd tomcat-native-1.1.33-src/jni/native/
# ./configure --with-apr=/usr/local/apr (官網中樣例的其它參數不須要,會自己主動找到
)
# make && make install
參考:
官網的安裝指導:
http://tomcat.apache.org/native-doc/
Tomcat Connector三種執行模式(BIO, NIO, APR)的比較和優化:http://blog.csdn.net/clementad/article/details/47045673
(原創文章,轉載請注明轉自Clement-Xu的博客)