首页 > 代码库 > tomcat高并发配置
tomcat高并发配置
最近在项目中负责Tomcat高并发优化方案写一写新得。
优化1)tomcat默认的并发是75,可以启用线程池根据生产环境硬件设定线程池大小。
<Executor name="tomcatThreadPool" namePrefix="catalina-exec-"
maxThreads="150" minSpareThreads="40"/>
并在使用时引用线程池。
并发在150左右
优化2)tomcat7及之前的版本默认采用BIO,启用NIO模式(NIO与BIO差距自行脑补)
<style>p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px "Heiti SC Light" }</style><Connector executor="tomcatThreadPool"
port="8080" protocol="org.apache.coyote.http11.Http11NioProtocol"
connectionTimeout="20000"
redirectPort="8443" />
经过这次优化后250的并发量一般是没问题
优化3)APR模式,因为实际生产环境大部分在linux下,所以直说Linux下的安装
(1)先安装gcc (没有yum命令先安装yum,sudo apt -get install yum)
yum -y install gcc
(2) 按装apr和apr-util
下载地址http://apr.apache.org/download.cgi
<style>p.p1 { margin: 0.0px 0.0px 14.0px 0.0px; font: 14.0px Arial; color: #323333 } p.p2 { margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Arial; color: #323333 } span.s1 { } span.s2 { font: 14.0px "Heiti SC Light" }</style><style>p.p1 { margin: 0.0px 0.0px 14.0px 0.0px; font: 14.0px Arial; color: #323333 } p.p2 { margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Arial; color: #323333 } span.s1 { } span.s2 { font: 14.0px "Heiti SC Light" }</style>
apr-1.3.2.tar.gz安装:
tar zxvf apr-1.3.2.tar.gz
cd apr-1.3.2
./configure --prefix=/usr/local/apr
make
make install
<style>p.p1 { margin: 0.0px 0.0px 14.0px 0.0px; font: 14.0px Arial; color: #323333 } p.p2 { margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Arial; color: #323333 } span.s1 { } span.s2 { font: 14.0px "Heiti SC Light" }</style>
apr-util-1.3.2.tar.gz 安装:
tar zxvf apr-util-1.3.2.tar.gz
cd apr-util-1.3.2
./configure --prefix=/usr/local/apr-util
make
make install
(3)安装pcre 下载地址https://sourceforge.net/projects/pcre/files/pcre/
unzip -o pcre-8.33.zip # cd pcre-8.33
# ./configure --prefix=/usr/local/pcre
make
make install
(4)安装apache http://httpd.apache.org/download.cgi
tar zxvf httpd-2.4.25.tar.tz
./configure --prefix=/usr/local/apache --enable-modules=all --enable-mods-shared=all --enable-proxy --enable-proxy-connect --enable-proxy-ftp --enable-proxy-http --enable-proxy-ajp --enable-proxy-balancer --enable-rewrite --enable-status --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util/ --with-pcre=/usr/local/pcre
make
make install
(5)
<style>p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; min-height: 13.0px } p.p2 { margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo } span.s1 { } span.s2 { font: 11.0px "Heiti SC Light" }</style>
配置apache开机自启动
在/etc/rc.local(或者/etc/rc.d/rc.local)中加入如下一下 /opt/apache/bin/apachectl -k start
查看是否正常启动:ps -ef | grep httpd
经过APR优化后并发量轻松破300
END
参考地址
<style>p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px "Heiti SC Light"; color: #323333 } span.s1 { }</style>http://wenku.baidu.com/link?url=IWluBNhmZVtnY3zvQBSHbI18gmItJc1wM8ExsYAcLznE1_zWnQID99HATHuiYmBl1PCcVV5rdeXBZttkPcwmMZM95m-aTBgdSMD7Hb2u1ZG
<style>p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px "Heiti SC Light"; color: #323333 } span.s1 { }</style> <style>p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Arial; color: #323333 } span.s1 { }</style> <style>p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px "Heiti SC Light"; color: #323333 } p.p2 { margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px "Heiti SC Light"; color: #323333; min-height: 14.0px } span.s1 { }</style> <style>p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px "Heiti SC Light"; color: #323333 } p.p2 { margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo } span.s1 { } span.s2 { }</style>
tomcat高并发配置