spring boot Tomcat maxConnections、maxThreads、acceptCount

目录

1. maxConnections:

2. acceptCount 

3. maxThreads:

4.connectionTimeout

问题1:

问题2:

附录1:

附录2:

参考:


1:

1. maxConnections:

  • 官方解释
Attribute Description
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 

  • 官方解释
Attribute Description
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:

  • 官方解释
Attribute Description
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

  • 官方解释
Attribute Description
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

问题1:

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

问题2:

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

附录1:

Jmeter测试设置:

附录2:

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

参考:

https://tomcat.apache.org/tomcat-9.0-doc/config/http.html

https://www.cnblogs.com/ftl1012/p/netstat.html

https://blog.csdn.net/seabreezesuper/article/details/84874917

猜你喜欢

转载自blog.csdn.net/abcdu1/article/details/112996643