tomcat的运行模式有3种
1)bio
默认的模式,性能非常低下,没有经过任何优化处理和支持.
2)nio
利用java的异步io护理技术,noblocking IO技术.
想运行在该模式下,直接修改server.xml里的Connector节点,修改protocol为
protocol="org.apache.coyote.http11.Http11NioProtocol"
启动后,就可以生效。
3)apr
安装起来最困难,但是从操作系统级别来解决异步的IO问题,大幅度的提高性能.
必须要安装apr和native,直接启动就支持apr。下面的修改纯属多余,仅供大家扩充知识,但仍然需要安装apr和native
如nio修改模式,修改protocol为org.apache.coyote.http11.Http11AprProtocol
官方对 三种方式 简单对比
Java Blocking Connector Java Non Blocking Connector APR/native Connector
BIO NIO APR
Classname Http11Protocol Http11NioProtocol Http11AprProtocol
Tomcat Version 3.x onwards 6.x onwards 5.5.x onwards
Support Polling NO YES YES
Polling Size N/A maxConnections maxConnections
Read HTTP Request Blocking Non Blocking Blocking
Read HTTP Body Blocking Sim Blocking Blocking
Write HTTP Response Blocking Sim Blocking Blocking
Wait for next Request Blocking Non Blocking Non Blocking
SSL Support Java SSL Java SSL OpenSSL
SSL Handshake Blocking Non blocking Blocking
Max Connections maxConnections maxConnections maxConnections
<strong> </strong><strong>安装</strong><strong>APR</strong>
APR项目有APR,APR-util和APR-iconv,其中APR-iconv是可选安装的。
下载最新的APR和APR-util源码包
2.1安装APR
1)解压apr-1.4.6:tar -zxf apr-1.4.6
2) cd apr-1.4.6
3)依次执行./configure
make
sudo make install
在apr被安装到了/usr/local/apr目录下面
2.2 安装APR-util
1) 解压apr-util-1.4.1:tar -zxfapr-util-1.4.1
2) cd apr-util-1.4.1
3) 依次执行./configure–with-apr=/usr/local/apr/bin/apr-1-config (如果不加后面的可能会报APR找不到的错误”checkingfor APR… no
configure: error: APR could not be located. Please use the–with-apr option.”
make
sudo make install
apr-util也被安装找/usr/local/apr下面
2.3进入tomcat主目录下,在bin/tomcat-native-1.1.23-src/jni/native下面依次执行:
./configure–with-apr=/usr/local/apr/bin/apr-1-config (如果不加后面的可能会报APR找不到的错误”checkingfor APR… no
configure: error: APR could not be located. Please use the–with-apr option.”
make
sudo make install
2.4. 设置启动参数:
在catalina.sh 加入启动参数:
CATALINA_OPTS=”$CATALINA_OPTS-Djava.library.path=/usr/local/apr/lib”
转载请注明:爱开源 » tomcat的三种模式(bio、nio、apr)