在Spring Boot中增加Tomcat的连接超时

如何增加超时时间,以便在处理响应之前,请求不超时?


Spring Boot中的Tomcat设置:


server.tomcat.max-connections=2000

server.tomcat.max-threads=200

server.connection-timeout=1200000

constantUsersPerSec(20) during (15)在15秒的过程中,每秒的请求数增加到300,并且所有请求均得到满足,如下面的加特林(蓝色)所示。


scn.inject(

      constantUsersPerSec(20) during (15), 

    )

这是由于max-connections = 2000使用200工作线程处理了300个请求。


控制器是用Spring MVC编写的,它返回后DeferredResult会执行异步请求处理,因此一旦响应被处理,它将恢复响应。

http://img3.mukewang.com/607fdb5a000152e508820225.jpg

但是,即使server.connection-timeout将其设置为较高的数字,1200000也有很多503即将结束(红色)


> status.find.in(200,304,201,202,203,204,205,206,207,208,209), b     78 (100.0%)

ut actually found 503

http://img3.mukewang.com/607fdb6a00011ec008920263.jpg

Gatling.conf也设置为增加超时时间:


   timeOut {

      simulation = 8640000 # Absolute timeout, in seconds, of a simulation

    }

    ahc {

      #keepAlive = true                                # Allow pooling HTTP connections (keep-alive header automatically added)

      connectTimeout = 600000                          # Timeout when establishing a connection

      handshakeTimeout = 600000                        # Timeout when performing TLS hashshake

      pooledConnectionIdleTimeout = 600000             # Timeout when a connection stays unused in the pool

      readTimeout = 600000                             # Timeout when a used connection stays idle

      #maxRetry = 2                                    # Number of times that a request should be tried again

      requestTimeout = 600000      


猛跑小猪
浏览 3129回答 1
1回答

芜湖不芜

检查以下属性:spring.mvc.async.request-timeout =#异步请求处理超时之前的时间此设置有助于进行其余的配线架配置spring.mvc.async.request-timeout=1200000但是,根本原因是,当请求数量很大时,所有工作线程(200)都会占用上载打开的连接(2000)(控制器将MultipartFile作为参数并返回DeferredResult)我认为DeferredResult当请求服务逻辑很快而业务逻辑很慢(在forkjoin.commonPool上运行)时,它就闪闪发光。它不太适合MultiPartFile上载(阻塞和缓慢),并且在文件大小较大时不适合,因为自从那时起响应就不能快速恢复(如以上每秒响应图表中所示,仅在几秒钟后响应就开始恢复,因为打开了连接)是2000,而工人只有200)。如果增加了工作人员,则无论如何都会减轻异步处理的优势。在这种情况下,请求处理(上传和阻止)很慢,而业务逻辑很快。因此响应已经准备就绪,但是所有工作线程(200)忙于处理越来越多的请求,因此响应没有恢复,因此超时了。可能需要为DeferredResult提供单独的池request serve并response resume进行异步处理?
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java