spring boot Tomcat maxConnections、maxThreads、acceptCount

目录

1. maxConnections:

2. acceptCount 

3. maxThreads:

4.connectionTimeout

5.maxKeepAliveRequests

问题1:

问题2:

附录1:

附录2:

参考:

1:

1. maxConnections:

  • 官方解释
AttributeDescription
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 is 8192.

For NIO/NIO2 only, setting the value to -1, will disable the maxConnections feature and connections will not be counted.

  • 图2

  • 理解

服务程序可以在一定时间内接收并处理的连接数目如图1中queue-2,超过这个数,会根据acceptCount 这个值继续建立连接存放在queue-1中,但是该连接不会被处理,只有当queue-2中的连接数小于maxConnections值,queue-1中的连接才会进入queue-2中,该连接才有可能被执行。queue-2中的连接状态如图2标注所示。当同时请求数大于maxConnections+acceptCount 新的请求将会被拒绝连接。

  • spring boot 默认值

  • 设置

配置spring boot 项目 resources 目录下的application. properties 文件

server.tomcat.max-connections=10

2. acceptCount 

  • 官方解释
AttributeDescription
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.

  • 图3

  • 理解

超过maxConnections这个值的连接数将根据acceptCount这个值继续建立连接,如图1 queue-1,当queue-2的连接数小于maxConnections, queue-1的连接进入queue-2.

queue-1的连接状态如图3标注所示。

  • spring boot 默认值

  • 设置:

配置spring boot 项目 resources 目录下的application. properties 文件

server.tomcat.accept-count=5

3. maxThreads:

  • 官方解释
AttributeDescription
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.

  • 理解

服务程序可以同时处理的线程数如图1 ThreadPool,可以理解为通过设定 maxConnections=10 ,同时可以建立10个连接,maxThreads=3,则这10个连接中同时只有3个连接被处理,其余7个连接都在queue-2中等待被处理,等这3个连接处理完之后,其余的7个连接中的3个才可以被处理。如果处理完的3个连接关闭后,queue-1中就可以有3个连接进入queue-2。

  • spring boot 默认值

  • 设置

配置spring boot 项目 resources 目录下的application. properties 文件

server.tomcat.max-threads=3

4.connectionTimeout

  • 官方解释
AttributeDescription
connectionTimeout

The number of milliseconds this Connector will wait, after accepting a connection, for the request URI line to be presented. Use a value of -1 to indicate no (i.e. infinite) timeout. The default value is 60000 (i.e. 60 seconds) but note that the standard server.xml that ships with Tomcat sets this to 20000 (i.e. 20 seconds). Unless disableUploadTimeout is set to false, this timeout will also be used when reading the request body (if any).

  • 理解

连接的生存周期,当已经建立的连接,在connectionTimeout时间内,如果没有新的请求到来,服务端程序将会主动关闭该连接。

  • 设置

配置spring boot 项目 resources 目录下的application. properties 文件

server.tomcat.connection-timeout=20000

5.maxKeepAliveRequests

  • 官方解释
maxKeepAliveRequests

The maximum number of HTTP requests which can be pipelined until the connection is closed by the server. Setting this attribute to 1 will disable HTTP/1.0 keep-alive, as well as HTTP/1.1 keep-alive and pipelining. Setting this to -1 will allow an unlimited amount of pipelined or keep-alive HTTP requests. If not specified, this attribute is set to 100.

  • 理解

长连接,在发送了maxKeepAliveRequests个请求后就会被服务器端主动断开连接。

  • 设置
server.tomcat.max-connections=-1

问题1:

这里测试过程中设置的 server.tomcat.accept-count=5,但是图3中的 连接数是6,而且通过改变server.tomcat.accept-count这个值,测出的等待连接数都会比这个值多1。

问题2:

当连接数大于maxConnections+acceptCount时,新来的请求没有收到服务器拒绝连接响应,而是不会和新的请求建立连接,如果客户端设置了请求连接超时,就会出现请求连接超时。

附录1:

Jmeter测试设置:

附录2:

TCP 3次握手4次挥手流程:

参考:

Common Application Properties

Apache Tomcat 9 Configuration Reference (9.0.68) - The HTTP Connector

Linux netstat命令详解 - 小a玖拾柒 - 博客园

[Spring Boot]用Jmeter测试maxConnections、maxThreads、acceptCount的关系_seabreezesuper的博客-CSDN博客

  • 2
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值