tomcat连接数、线程数关系
来源:互联网 发布:子账号登录淘宝助理 编辑:程序博客网 时间:2024/05/20 00:16
个人对tomcat连接器3个属性maxConnections、maxThreads、acceptCount的理解:
先摘取官网对这3个属性的描述:
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.
maxConnections The maximum number of connections that the server will accept and process at any given time. When this number has been reached, the server will accept, but not process, one further connection. This additional connection be blocked until the number of connections being processed falls below maxConnections at which point the server will start accepting and processing new connections again.Note that once the limit has been reached, the operating system may still accept connections based on the acceptCount setting.The default value varies by connector type. For BIO the default is the value of maxThreads unless an Executor is used in which case the default will be the value of maxThreads from the executor. For NIO the default is 10000. For APR/native, the default is 8192.
Note that for APR/native on Windows, the configured value will be reduced to the highest multiple of 1024 that is less than or equal to maxConnections. This is done for performance reasons.
If set to a value of -1, the maxConnections feature is disabled and connections are not counted.
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. Note that if an executor is configured any value set for this attribute will be recorded correctly but it will be reported (e.g. via JMX) as -1 to make clear that it is not used.
其中maxConnections描述红色部分说明当连接数达到最大值后,系统会继续接收连接但不会超过acceptCount的值。
理解:
我们可以把tomcat比做一个电影院,流程是取号、买票、观影,acceptCount比作前厅(容纳取到号的人)、maxConnections比作大厅(容纳买到票的人)、maxThreads比作影厅(可以理解一个影厅只容纳一个人,因为一个线程同时只处理一个请求),以下场景是针对已达到maxConnections最大值来讨论的
1)取号:如果前厅人数已达到acceptCount,则拿号失败,会得到Connection refused connect的回复信息。反之则会进入前厅,等待买票。
2)买票:当大厅人数小于maxConnections时,前厅的人就可以进入大厅
3)观影:当影厅的人离开时,大厅的部分人能进入影厅,一般来讲大厅的容量要远大于影厅的数量。
本文是针对apache-tomcat-7.0.55做的测试。
tomcat server.xml配置参数
<Connector port="8080" protocol="org.apache.coyote.http11.Http11NioProtocol" acceptCount="2" maxConnections="10" maxThreads="2" connectionTimeout="20000" redirectPort="8443" />
Servlet的代码:休眠20秒
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
try {
InputStream is = request.getInputStream();
System.out.println(new Date()+”:”+is+”开始”);
Thread.sleep(20000);
System.out.println(new Date()+”:”+is+”结束”);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
一个请求或一个connection的生命周期:可以简单的理解为从doGet或doPost开始response响应结束。
使用JMeter测试,线程数20,连接超时时间10s,响应超时时间30s
测试结果:
察看结果数:
第1秒:8个请求得到响应数据:Connection refused connect
第20秒:2个请求正常响应
第30秒:剩余10个请求得到响应数据:Readtimed out
tomcat日志:
打印12组开始结束的日志,说明tomcat会处理acceptCount+maxConnections的请求,说明只要取到号,有足够的耐心,就肯定能够看到电影。
maxThread 最大并发量
maxConnections + acceptCount 最大连接数,它们与maxThread没有一点关系。
- tomcat连接数、线程数关系
- tomcat连接数线程数
- Tomcat 的连接数与线程池
- tomcat连接数与线程池概念
- tomcat 调整线程数
- TOMCAT 线程数
- TOMCAT 线程数
- Tomcat线程数
- Tomcat线程数参数设置
- tomcat线程数
- Tomcat线程数配置
- tomcat最佳线程数
- Tomcat最佳线程数
- tomcat连接数设置
- Tomcat 连接数优化
- 加大Tomcat连接数
- Tomcat连接数
- tomcat连接数过大
- 成为Java顶尖程序员 ,看这11本书就够了
- HDU-1171-Big Event in HDU(01背包的简单变形)
- Android_Service获取系统服务
- Eclipse插件之动态刷新ToolBar的图片
- MA8601|HUB方案|中文规格书|MA8601一级代理|MA8601应用|
- tomcat连接数、线程数关系
- ugui
- android 腾讯X5webview里HTML5的地理位置定位
- PHP获取当前日期所在星期(月份)的开始日期与结束日期(实现代码)
- Cordova+Angularjs+Ionic混合开发入门篇(一)----- ionic环境搭建
- Go 字符串格式化
- Javascript判断页面刷新或关闭的方法
- Eclipse下第一个NDK项目
- 课时11 Linux文件系统