APR是apache的一个linux操作系统级优化库,可以在tomcat中使用操作系统级native调用大大提高并发处理效率
先安装前置依赖:
yum install -y apr-devel openssl-devel gcc make expat-devel
https://mirrors.tuna.tsinghua.edu.cn/apache/apr/
下载最新apr-1.6.3.tar.gz apr-util-1.6.1.tar.gz apr-iconv.x.x.tar.gz
解压apr-1.6.3.tar.gz到main下,cd进去
./configure --prefix=/main/apr make && make install
然后解压 apr-util-1.6.1.tar.gz cd进去:
./configure --prefix=/main/apr-util --with-apr=/main/apr/
make && make install
同上再安装一个apr-iconv.x.x.tar.gz
然后解压tomcat/bin目录下的tomcat-native-1.2.16.tar.gz并进入:
apache-tomcat-8.5./bin/tomcat-native-1.2.-src/native
先
./configure --with-apr=/main/apr --with-java-home=/main/jdk1..0_172
再 make && make install即可
加上lib目录:
JAVA_OPTS="$JAVA_OPTS -Djava.library.path=/main/lib"
或者
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/main/lib
tomcat配置文件,打开线程池:
<Executor name="tomcatThreadPool" namePrefix="catalina-exec-"
maxThreads="" minSpareThreads=""/>
设置protocol为:org.apache.coyote.http11.Http11AprProtocol
<Connector executor="tomcatThreadPool"
maxThreads=""
URIEncoding="UTF-8"
port=""
protocol="org.apache.coyote.http11.Http11AprProtocol"
connectionTimeout=""
enableLookups="false"
redirectPort="" />
启动后可以看到:
-Jul- ::10.016 信息 [localhost-startStop-] org.apache.catalina.startup.HostConfig.deployWAR Deployment of web application archive [/main/apache-tomcat-8.5./webapps/XXXXX.war] has finished in [,] ms
-Jul- ::10.023 信息 [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["http-apr-8080"]
-Jul- ::10.030 信息 [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["ajp-nio-8009"]
-Jul- ::10.043 信息 [main] org.apache.catalina.startup.Catalina.start Server startup in ms