为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

猛跑小猪 2021-04-09 18:13:53
如何增加超时时间,以便在处理响应之前,请求不超时?Spring Boot中的Tomcat设置:server.tomcat.max-connections=2000server.tomcat.max-threads=200server.connection-timeout=1200000constantUsersPerSec(20) during (15)在15秒的过程中,每秒的请求数增加到300,并且所有请求均得到满足,如下面的加特林(蓝色)所示。scn.inject(      constantUsersPerSec(20) during (15),     )这是由于max-connections = 2000使用200工作线程处理了300个请求。控制器是用Spring MVC编写的,它返回后DeferredResult会执行异步请求处理,因此一旦响应被处理,它将恢复响应。但是,即使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 503Gatling.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      
查看完整描述

1 回答

?
芜湖不芜

TA贡献1796条经验 获得超7个赞

检查以下属性:spring.mvc.async.request-timeout =#异步请求处理超时之前的时间

此设置有助于进行其余的配线架配置

spring.mvc.async.request-timeout=1200000

但是,根本原因是,当请求数量很大时,所有工作线程(200)都会占用上载打开的连接(2000)(控制器将MultipartFile作为参数并返回DeferredResult)

我认为DeferredResult当请求服务逻辑很快而业务逻辑很慢(在forkjoin.commonPool上运行)时,它就闪闪发光。它不太适合MultiPartFile上载(阻塞和缓慢),并且在文件大小较大时不适合,因为自从那时起响应就不能快速恢复(如以上每秒响应图表中所示,仅在几秒钟后响应就开始恢复,因为打开了连接)是2000,而工人只有200)。如果增加了工作人员,则无论如何都会减轻异步处理的优势。

在这种情况下,请求处理(上传和阻止)很慢,而业务逻辑很快。因此响应已经准备就绪,但是所有工作线程(200)忙于处理越来越多的请求,因此响应没有恢复,因此超时了。

可能需要为DeferredResult提供单独的池request serveresponse resume进行异步处理?


查看完整回答
反对 回复 2021-04-21
  • 1 回答
  • 0 关注
  • 3128 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信