个人对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的请求,说明只要取到号,有足够的耐心,就肯定能够看到电影

本文转自https://blog.csdn.net/kaka20099527/article/details/53285348

Tomcat中acceptCount,maxConnections、maxThreads的含义及关系的更多相关文章

  1. hibernate中各个jar包的含义和关系

    最基本的Hibernate3.3.2之 JAR包(必要): 包名 位置 用途 hibernate3.jar /hibernate 核心JAR包 antlr.jar /hibernate/lib/req ...

  2. tomcat 的acceptCount、acceptorThreadCount、maxConnections、maxThreads 如何确定

    acceptCount 连接在被ServerSocketChannel accept之前就暂存在这个队列中,acceptCount就是这个队列的最大长度. ServerSocketChannel ac ...

  3. 深度解读Tomcat中的NIO模型(转载)

    转自https://www.jianshu.com/p/76ff17bc6dea 一.I/O复用模型解读 Tomcat的NIO是基于I/O复用来实现的.对这点一定要清楚,不然我们的讨论就不在一个逻辑线 ...

  4. Tomcat中server.xml配置详解(2)

    Tomcat中配置文件详解 Server.xml配置文件说明,以及Tomcat组件的说明 Tomcat服务器是由一系列可以配置的组件构成,其中核心组件是Catalina Servlet,它是最顶层组件 ...

  5. tomcat 中无法添加项目等问题的解决方案

    博客地址:http://www.moonxy.com 一.前言 今天新建了一个 maven 项目,添加程序文件之后,发现无法添加项目,然后修改配置,将应用添加到了 tomcat,启动时又报错,解决出现 ...

  6. Java网络编程与NIO详解10:深度解读Tomcat中的NIO模型

    本文转自:http://www.sohu.com/a/203838233_827544 本系列文章将整理到我在GitHub上的<Java面试指南>仓库,更多精彩内容请到我的仓库里查看 ht ...

  7. Tomcat中的Server.xml配置详解

    Tomcat中的Server.xml配置详解 Tomcat Server的结构图如下: 该文件描述了如何启动Tomcat Server <Server> <Listener /> ...

  8. Java Web开发Tomcat中三种部署项目的方法

    第一种方法:在tomcat中的conf目录中,在server.xml中的,<host/>节点中添加: <Context path="/hello" docBase ...

  9. JNDI和在tomcat中配置DBCP连接池 元数据的使用 DBUtils框架的使用 多表操作

    1 JNDI和在tomcat中配置DBCP连接池 JNDI(Java Naming and Directory Interface),Java命名和目录接口,它对应于J2SE中的javax.namin ...

随机推荐

  1. Kubernetes移除node节点

    1.kubectl delete node {{节点名称}} 2.删除node节点上由kubelet自动生成的kubelet.kubeconfig配置文件,和ssl密钥证书kubelet.key,ku ...

  2. 查看python中模块的所有方法

    查看python中模块的所有方法     安装的python模块,现将查看方法总结如下 一.CMD命令行下使用pydoc命令 在命令行下运行$ pydoc modules即可查看 二.在python交 ...

  3. Python中使用多进程来实现并行处理的方法小结

    进程和线程是计算机软件领域里很重要的概念,进程和线程有区别,也有着密切的联系,先来辨析一下这两个概念: 1.定义 进程是具有一定独立功能的程序关于某个数据集合上的一次运行活动,进程是系统进行资源分配和 ...

  4. ngix匹配规则

    语法规则: location [=|~|~*|^~] /uri/ { … } =:开头表示精确匹配 ^~:开头表示uri以某个常规字符串开头,理解为匹配 url路径即可.nginx不对url做编码,因 ...

  5. NewSQL和TiDB入门

    TiDB已经在项目中使用,从了解来看,它主要解决的是分布式事务的问题,而我们实际使用场景,却是大数据量下不需要关注分表: 最近实在忙加懒,一直没时间看TiDB的原理.今天看了下PingCAP3篇入门介 ...

  6. 如何在运行时(Runtime)获得泛型的真正类型

    前言 由于Java 的类型擦除机制,在编译时泛型都被转为了Object,例如List<String>经过编译之后将变为类型 List.可以通过以下的方式再运行时获得泛型的真正类型 泛型如何 ...

  7. 开发Canvas 绘画应用(三):实现对照绘画

    需求分析 在我的毕设中,提出了视图引导的概念,由两部分功能组成: (1)可以对照着图片进行绘画,即将图片以半透明的方式呈现在绘图板上,然后用户可以对照着进行绘画: (2)可以直接将简笔画图片直接拖拽到 ...

  8. nodejs故障cnpm没反应

    莫名发生的故障cnpm没反应 重新整理nodejs使用流程 方案1 1.安装64位nodejs 2.设置代理 npm config set proxy http://127.0.0.1:9999    ...

  9. 浅谈session和cookie

    含义: session(会话):指用户登录网站后的一系列动作,比如浏览商品添加到购物车并购买 cookie:用户身份的一种标识 区别: 1.Cookie通过在客户端记录信息确定用户身份,Session ...

  10. XSS(四)攻击防御

    XSS Filter XSS Filter的作用是过滤用户(客户端)提交的有害信息,从而达到防范XSS攻击的效果 XSS Filter作为防御跨站攻击的主要手段之一,已经广泛应用在各类Web系统之中, ...