Tomcat 7最大并发链接数的正确修改方法

这是个很简单的问题,可是搜了一圈,发现你们都写错了。因此这里总结一下:html

几乎全部的中文网页都介绍,要修改Tomcat的默认最大并发链接数,应该进行以下设置(实际上这些步骤是错误的):web

--------------------------------------------apache

在tomcat配置文件server.xml中的<Connector ... />配置中,和链接数相关的参数有:
  
minProcessors:最小空闲链接线程数,用于提升系统处理性能,默认值为10
maxProcessors:最大链接线程数,即:并发处理的最大请求数,默认值为75
acceptCount:容许的最大链接数,应大于等于maxProcessors,默认值为100
enableLookups:是否反查域名,取值为:true或false。为了提升处理能力,应设置为false
connectionTimeout:网络链接超时,单位:毫秒。设置为0表示永不超时,这样设置有隐患的。一般可设置为30000毫秒。
其中和最大链接数相关的参数为maxProcessors和acceptCount。若是要加大并发链接数,应同时加大这两个参数。
web server容许的最大链接数还受制于操做系统的内核参数设置,一般Windows是2000个左右,Linux是1000个左右。Unix中如何设置这些参数,请参阅Unix经常使用监控和管理命令

具体的配置信息:
Java代码tomcat

 

  1. <Connector className="org.apache.coyote.tomcat4.CoyoteConnector" port="8080"
  2. minProcessors="5" maxProcessors="75" enableLookups="true" redirectPort="8443"
  3. acceptCount="100" debug="0" connectionTimeout="20000 " useURIValidationHack="false"
  4. protocolHandlerClassName="org.apache.jk.server.JkCoyoteHandler"/>

 

--------------------------------------------网络

可是我仔细查了一圈,发现这个说法只是以讹传讹,并不适用于Tomcat 5.5以上的版本。这里先教你们怎么去查Tomcat的官网:并发

首先,在这里:http://tomcat.apache.org/ 咱们点击左侧导航栏中“Documentation”下的Tomcat 7.0,进入到这个连接中:http://tomcat.apache.org/tomcat-7.0-doc/index.html ,详细的信息咱们不用都看,在左侧导航栏中有一个连接Configuration,咱们点进去以后,再点击其左侧导航栏中connector一项的HTTP,就进入到HTTP链接数及其余相关属性的设置页面了。在这里(http://tomcat.apache.org/tomcat-7.0-doc/config/http.html)咱们能够看到,在Connector的属性配置中,压根就没有maxProcessors等的设置选项。其中这句话已经介绍得很清楚:socket

If more simultaneous requests are received than can be handled by the currently available request processing threads, additional threads will be created up to the configured maximum (the value of the maxThreads attribute). If still more simultaneous requests are received, they are stacked up inside the server socket created by the Connector, up to the configured maximum (the value of the acceptCount attribute).ide

因此咱们须要设置的是maxThreads和acceptCount这两个值:性能

其中,maxThreads的介绍以下:this

The maximum number of request processing threads to be created by this Connector, which therefore determines the maximum number of simultaneous requests that can be handled. If not specified, this attribute is set to 200. If an executor is associated with this connector, this attribute is ignored as the connector will execute tasks using the executor rather than an internal thread pool.

而acceptCount的介绍为:

The maximum queue length for incoming connection requests when all possible request processing threads are in use. Any requests received when the queue is full will be refused. The default value is 100.

因此二者的默认值分别是200和100,要调整Tomcat的默认最大链接数,能够增长这两个属性的值,而且使acceptCount大于等于maxThreads:

 

 

  1. <Connector port="8080" protocol="HTTP/1.1"   
  2.            connectionTimeout="20000"   
  3.            redirectPort="8443" acceptCount="500" maxThreads="400" />  

Html代码  

  1. <Connector port="8080" protocol="HTTP/1.1"   
  2.            connectionTimeout="20000"   
  3.            redirectPort="8443" acceptCount="500" maxThreads="400" />  


今天就记录这么多,但愿你们之后在转载别人的经验时更用心些,不要老出现上面那些以讹传讹的状况。也但愿能对有些朋友起到帮助。

maxThreads 是处理请求的线程数,acceptCount 是等待队列,acceptCount并非必定要大于等于maxThreads。 maxThreads 满了,进入acceptCount ,acceptCount 也满了,则 拒绝请求

相关文章
相关标签/搜索