Tomcat maxThreads&;用于快速失效的acceptCount调整

Tomcat maxThreads&;用于快速失效的acceptCount调整,tomcat,microservices,fail-fast,Tomcat,Microservices,Fail Fast,我希望将Tomcat调优为在所有线程都被占用的情况下出现任何问题时快速失败(例如,如果数据库突然开始执行不良,则等待数据库连接) 我查看了几篇文章,具体如下: 我有几个问题,如果您能帮助我,我将不胜感激: 为什么Netflix会将并发请求保存在内存中,然后在达到阈值时在自己的代码中回复503?这背后的理由是什么? 据我从tomcat文档(见上面的链接)了解,如果达到maxThreads和acceptCount,tomcat将以自己拒绝的连接进行回复。因此,正确指定较小的acceptCount应

我希望将Tomcat调优为在所有线程都被占用的情况下出现任何问题时快速失败(例如,如果数据库突然开始执行不良,则等待数据库连接)

我查看了几篇文章,具体如下:

我有几个问题,如果您能帮助我,我将不胜感激:

  • 为什么Netflix会将并发请求保存在内存中,然后在达到阈值时在自己的代码中回复503?这背后的理由是什么? 据我从tomcat文档(见上面的链接)了解,如果达到maxThreads和acceptCount,tomcat将以自己拒绝的连接进行回复。因此,正确指定较小的acceptCount应该是关键
  • 来自Tomcat文档:

    每个传入请求在该请求期间都需要一个线程。如果接收到的并发请求超过当前可用的请求处理线程所能处理的数量,则将创建额外的线程,直到配置的最大值(maxThreads属性的值)。如果接收到更多的同时请求,则这些请求将堆积在连接器创建的服务器套接字中,直至配置的最大值(acceptCount属性的值)。任何进一步的同时请求都将收到“连接被拒绝”错误,直到有可用的资源来处理这些错误

    第条:

    跟踪内存中活动并发请求的数量,并将其用于快速失败。如果并发请求的数量接近估计的活动线程(在我们的示例中为8个),则返回503的http状态码。这将防止太多工作线程变得繁忙,因为一旦达到峰值吞吐量,任何处于活动状态的额外线程都将执行非常轻的返回503的任务,然后可用于进一步处理

  • 例如,我假设即使在TomcatNIO中,工作线程也不会像在NodeJ中那样“同时”重复使用。 对于一个http请求,有一个已分配的1工作线程,它不会处理任何其他http请求,除非完成此请求。即使此http请求正在等待类似阻塞i/o的数据库读取

  • 鉴于上述所有情况,我认为这可能是正确的配置:

  • 另外,我正在使用Tomcat 8.5和NIO连接器


    任何帮助/建议都将不胜感激。

    您好,您是否以某种方式解决了此问题?我还尝试配置fail fast,我们正在应用程序中进行一些批处理,默认配置不好。不,我没有。我把它推迟了一点,也许下个星期会再讨论。如果我得到任何结果,我会写信的。嗨,你解决了这个问题吗?我还尝试配置fail fast,我们正在应用程序中进行一些批处理,默认配置不好。不,我没有。我把它推迟了一点,也许下个星期会再讨论。如果我得到任何结果,我会写信的。
    # not using the executor, but a 'default' internal thread pool of the connector
    
    maxConnections = -1 # For NIO/NIO2 only, setting the value to -1, will disable the maxConnections feature and connections will not be counted.
    # or we can leave default, i.e. 10k. The thing is that only 1 thread ( hence little resources used ) will keep these connections alive, so we can use keepAlive
    # and avoid establishing connections again and again which can be costly and resource consuming.
    
    server.tomcat.max-threads = 96 # we assume that 8 cores can handle up to this amount of threads, given that each thread spends significant time in database and/or other network calls
    # in the article above it was stated that they increased maxThreads 3 times than the amount of cores
    
    server.tomcat.accept-count = ?? # from one point of view, it can be something really-really small like 16 or 32
    # from another point of view, maybe something like 512 
    # imagine that due to a temporary network glitch an upstream service won't be reachable and we need few seconds to reach the timeouts and open circuit breaker. would be nice to queue other requests and successfully ( the ones what are independent ) process them seconds after rather than reject them right away