server.tomcat.max线程VS corePoolSize VS spring.datasource.tomcat.max [英] server.tomcat.max-threads VS corePoolSize VS spring.datasource.tomcat.max

查看:103
本文介绍了server.tomcat.max线程VS corePoolSize VS spring.datasource.tomcat.max的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Spring Boot REST异步应用程序,想要调整:

I've an Spring Boot REST async application, wanna adjust:


  1. 来自客户端的连接线程(想要REST请求并行进行)

  2. 服务层中@Async方法的线程号

  3. 与数据库的连接池

浏览文档和网站发现了可能:

Browsing documentations and sites found possibilities:

corePoolSize value = ... VS server.tomcat.max-threads = ... -有什么区别?

spring.datasource.hikari.maximum-pool-size = ... VS spring.datasource .tomcat.max ... = ... -有什么区别?

推荐答案

假设您正在使用Spring Boot 2.1并没有更改默认值(使用Tomcat作为嵌入式容器,使用Hikari作为连接池)。

Assuming you are using Spring Boot 2.1 and haven't changed the defaults (using Tomcat as the embedded container and Hikari as the connection pool).

要修改线程数(默认情况下,tomcat已经使用了200个,为什么会这样?您需要进行更改!)使用 server.tomcat 命名空间中的属性(这些属性仅适用于Tomcat !。因此,请使用 server.tomcat.max -threads 来控制请求处理的数量。

To modify the number of threads (tomcat by default already uses 200 so why would you need to change it!) use the properties in the server.tomcat namespace (those are specific for Tomcat!. So use server.tomcat.max-threads to control the number of request handling.

要限制并发HTTP连接的数量,请使用 server。 tomcat.max-connections (默认值为10000)。这基本上是请求处理线程用来从中进行窃取/窃取工作的处理队列。

To limit the number of concurrent HTTP connections use the server.tomcat.max-connections (default value 10000). This is basically the processing queue which the request handling threads use to pick/steal work from.

用于控制由Spring中默认创建的 TaskExecutor 使用的默认线程数Boot 2.1使用 spring.task.execution 命名空间中的属性,因此请使用 spring.task.execution.pool.max-threads 设置用于 @Async 的最大线程数。 c $ c> spring.task.execution.pool.core-size 控制核心(最小)池大小。增加 max-threads 属性而不通过 spring.task.execution.pool.queue-capacity 限制队列大小没有效果。默认队列大小是无限制的,并且所有内容都不会导致超出 core-size 的线程数增加。

For controlling the number of threads used by the default created TaskExecutor in Spring Boot 2.1 use the properties in the spring.task.execution namespace. So use spring.task.execution.pool.max-threads to set the maximum number of threads to use for @Async. The spring.task.execution.pool.core-size controls the core (minimum) pool-size. Increasing the max-threads property without limiting the queue size through spring.task.execution.pool.queue-capacity has no effect. The default queue size is unbounded and everything will not result in growing the number of threads beyond the core-size.

最后为连接池指定连接(Hikari的默认值为10! )。使用 spring.datasource 命名空间属性,尤其是用于连接池的命名空间属性(默认为Hikari,因此 spring.datasource.hikari spring.datasource.tomcat 用于Tomcat JDBC连接池,该池在2.0之前的Spring Boot上用作默认值)。因此,将 spring.datasource.hikari.maximum-pool-size 设置为最大线程数。

Finally to specify the connections for your connection pool (the default for Hikari is 10!). Use the spring.datasource namespace properties and specifically the one for your connection pool (default is Hikari so the ones in spring.datasource.hikari, the spring.datasource.tomcat are for the Tomcat JDBC connection pool used as default on Spring Boot before 2.0). So set the spring.datasource.hikari.maximum-pool-size to manage to max number of threads.

它们彼此之间没有任何关系,应该相互混淆,因为好(恕我直言,这在参考指南中已经很清楚了,每种服务都有不同的目的)。请参阅以下内容的附录A 《 Spring Boot参考指南》中的常见属性列表。

They don't have anything to do with each other and should be confused with each other as well (imho this is already clear in the reference guide that each serves a different purpose). See Appendix A of the Spring Boot Reference Guide for a list of common properties.

这篇关于server.tomcat.max线程VS corePoolSize VS spring.datasource.tomcat.max的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆