Tomcat 7最大并发连接数的正确修改方法(转)

简介: 几乎所有的中文网页都介绍,要修改Tomcat的默认最大并发连接数,应该进行如下设置(实际上这些步骤是错误的): -------------------------------------------- 在tomcat配置文件server.

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

--------------------------------------------

在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代码
<Connector className="org.apache.coyote.tomcat4.CoyoteConnector" port="8080"
minProcessors="5" maxProcessors="75" enableLookups="true" redirectPort="8443"
acceptCount="100" debug="0" connectionTimeout="20000 " useURIValidationHack="false"
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等的设置选项。其中这句话已经介绍得很清楚:

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).

所以我们需要设置的是maxThreads和acceptCount这两个值:

其中,maxThreads的介绍如下:

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:

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

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

相关阅读:

Linux下Apache与多个Tomcat 集群负载均衡 http://www.linuxidc.com/Linux/2012-01/51731.htm

Nginx Tomcat 集群负载均衡解决笔记 http://www.linuxidc.com/Linux/2013-07/86827.htm

实例详解Tomcat组件安装+Nginx反向代理Tomcat+Apache使用mod_jk和mod_proxy反向代理和负载均衡 http://www.linuxidc.com/Linux/2013-06/85290.htm

Apache+Tomcat 环境搭建(JK部署过程) http://www.linuxidc.com/Linux/2012-11/74474.htm

http://www.linuxidc.com/Linux/2013-09/90332.htm

 

相关文章
|
应用服务中间件
tomcat修改默认端口详细步骤(包含运行测试)
在tomcat端口被占用或者需要把默认的8080端口换成其他的端口,就可以修改默认端口。
697 0
tomcat修改默认端口详细步骤(包含运行测试)
|
安全 Java 应用服务中间件
组件漏洞修复---修改SpringBoot内置tomcat的版本号
安全反应Tomcat9.0.41存在安全漏洞,让将所有服务的Tomcat版本升级到9.0.44,我们都知道SpingBoot中是集成的有内置的Tomcat的,叫Embed-Tomcat,这个Tomcat和我们用于部署war包的Tomcat还是有有一些区别的,但是版本一直和Tomcat基本保持一致。
803 0
组件漏洞修复---修改SpringBoot内置tomcat的版本号
|
9月前
|
网络协议 Java 应用服务中间件
详解Tomcat的连接数与线程池,调优必备
详解Tomcat的连接数与线程池,调优必备
|
缓存 Java 应用服务中间件
【Tomcat】史上最全下载、安装配置及使用教程,(2022最新..建议收藏,教学)附Tomcat常见报错解决方法
【Tomcat】史上最全下载、安装配置及使用教程,(2022最新..建议收藏,教学)附Tomcat常见报错解决方法
1074 0
【Tomcat】史上最全下载、安装配置及使用教程,(2022最新..建议收藏,教学)附Tomcat常见报错解决方法
|
12月前
|
Java 应用服务中间件 C++
Tomcat - Tomcat 网络通信模型剖析 & 并发参数解读
Tomcat - Tomcat 网络通信模型剖析 & 并发参数解读
45 0
|
12月前
|
安全 Java 应用服务中间件
tomcat的put方法任意文件写入漏洞浅谈
tomcat的put方法任意文件写入漏洞浅谈
210 0
QGS
|
容器
浅谈Tomcat9之Servlet-request获取请求参数及常用方法
//获取Map集合中所有的key Enumeration<String> getParameterNames();
QGS
115 0
|
Web App开发 网络协议 Java
tomcat 的并发能力分析
tomcat 的并发能力分析
567 0
tomcat 的并发能力分析
|
Java 应用服务中间件
tomcat对AQS的扩展:使用LimitLatch控制连接数
tomcat对AQS的扩展:使用LimitLatch控制连接数
tomcat对AQS的扩展:使用LimitLatch控制连接数
|
应用服务中间件 Windows
Tomcat安装配置及IDEA配置方法【亲测有效】
配置Tomcat环境变量主要是为了随时随地能够启动Tomcat服务(可选) 打开环境变量,添加用户环境变量
432 1
Tomcat安装配置及IDEA配置方法【亲测有效】