简体   繁体   English

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

[英]Increasing connection timeout for Tomcat in Spring Boot

How can timeout be increased so that till response is processed, request does not timeout? 如何增加超时以便在处理响应之前,请求不会超时?

Tomcat settings in Spring Boot: Spring Boot中的Tomcat设置:

server.tomcat.max-connections=2000
server.tomcat.max-threads=200
server.connection-timeout=1200000

Request per second were raised constantUsersPerSec(20) during (15) to 300 during course of 15 seconds and all requests were served as can be seen in plot below from gatling(blue). 在15秒期间,每秒请求constantUsersPerSec(20) during (15)constantUsersPerSec(20) during (15)提升到300并且所有请求都被提供,如下面的图表中可以看到的那样(蓝色)。

scn.inject(
      constantUsersPerSec(20) during (15), 
    )

This is due to max-connections = 2000 which served 300 requests using 200 worker threads. 这是由于max-connections = 2000 ,它使用200工作线程提供300个请求。

Controller is written in Spring MVC which returns DeferredResult which does asynchronous request processing and therefore will resume response once response is processed. Controller是用Spring MVC编写的,它返回DeferredResult ,它执行异步请求处理,因此一旦处理响应就会恢复响应。

每秒请求数

But even though server.connection-timeout is set to high number 1200000 there are lot of 503 towards end (red) 但即使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

每秒响应

Gatling.conf is also set for increased timeout: 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           

As per comments from Rcordoval - 根据Rcordoval的评论 -

Check this property: spring.mvc.async.request-timeout= # Amount of time before asynchronous request handling times out 检查此属性:spring.mvc.async.request-timeout =#异步请求处理超时之前的时间

This setting helps with rest of gatling configurations 此设置有助于其余的gatling配置

spring.mvc.async.request-timeout=1200000

The root cause however is that when requests come in large numbers, then all worker threads (200) get occupied in uploading open connections (2000) (the Controller is taking MultipartFile as argument and returning a DeferredResult ) 然而,根本原因是当请求大量发生时,所有工作线程(200)在上传打开的连接(2000)时被占用(Controller将MultipartFile作为参数并返回DeferredResult)

I think DeferredResult shines when request serve logic is fast and business logic is slow (runs on forkjoin.commonPool). 我认为当请求服务逻辑很快且业务逻辑很慢(在forkjoin.commonPool上运行)时, DeferredResult发光。 It does not quite fits with MultiPartFile uploads (blocking and slow) and more so when File sizes are big since then responses are not quickly resumed (as can be seen in above response per sec chart, only after few seconds responses start resuming since open connections are 2000 and workers only 200). 它不太适合MultiPartFile上传(阻塞和慢速),当文件大小很大时更是如此,因为那时响应不会很快恢复(如上面的响应每秒图表所示,仅在几秒钟后响应开始恢复,因为打开连接2000年,工人只有200)。 If workers are increased, it then mitigates advantages of async processing anyway. 如果工作人员增加,那么无论如何它都会减轻异步处理的优势。

In this case, request processing (upload and blocking) was slow and business logic was fast. 在这种情况下,请求处理(上传和阻止)很慢,业务逻辑很快。 so responses were getting ready but all the worker threads (200) are so busy serving more and more requests that responses are not getting resumed and timing out as a result. 所以响应已经准备就绪但是所有工作线程(200)都忙着提供越来越多的请求,响应没有得到恢复并因此超时。

Probably makes a case for having separate pool for request serve and response resume in async processing with DeferredResult ? 可能会在DeferredResult的异步处理中为request serveresponse resume request serve单独的池吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM