这是个很简单的问题,但是搜了一圈,发现大家都写错了。所以这里总结一下:

几乎所有的中文网页都介绍,要修改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

最新文章

  1. JS(去掉前后空格或去掉所有空格)的用法
  2. AsyncHttpClient 源码分析
  3. 加载gif动画的三种方式
  4. Qt Style Sheet实践(一):按钮及关联菜单
  5. android Textview动态设置大小
  6. sqlserver 2000事务复制问题
  7. webview页面和壳通信的库(精简版)
  8. Sublime 编译出来的是 dos格式,不是unix格式
  9. bzoj 1026 [SCOI2009]windy数 数位dp
  10. u163是什么故障 佳能MX328 u163是什么意思?墨水打完了,我加了墨水后还是显示U163(请检查墨水-彩色)警告灯亮
  11. Servlet 总结
  12. Jenkins任务启动的后台进程被自动kill
  13. PHP得出附件扩展名
  14. div滚动与控制
  15. [bzoj1587] [Usaco2009 Mar]Cleaning Up 打扫卫生
  16. 我们数学中常用的自然常数e代表什么?看完长知识了!
  17. C# float与UInt16互转
  18. Exception thrown on Scheduler.Worker thread. Add `onError` handling
  19. 马凯军201771010116《面向对象程序设计(java)》第三周学习总结
  20. ORACLE-016:ora-01720 授权选项对于&#39;xxxx&#39;不存在

热门文章

  1. 【原】Gradle调用shell脚本和python脚本并传参
  2. C#Winform获取屏幕大小
  3. myeclipse工程当中的.classpath 和.project文件什么作用?
  4. Flex调用java webservice
  5. Ajax异步刷新地址栏
  6. Mono资源
  7. 大数据架构师NoSQL建模技术
  8. 黄永成-thinkphp讲解-个人博客讲解26集
  9. 大熊君大话NodeJS之开篇------Why NodeJS(将Javascript进行到底)
  10. 用jinja做了个E-Letter小项目