server.tomcat.max-threads VS corePoolSize VS spring.datasource.tomcat.max

匆匆过客 提交于 2019-12-24 08:17:41

问题


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

  1. Connections threads from clients (wanna REST request go in parallel)
  2. Thread numbers for @Async methods in my service tier
  3. pool of connections to DB

Browsing documentations and sites found possibilities:

corePoolSize value=... VS server.tomcat.max-threads = ... - What is the difference?

spring.datasource.hikari.maximum-pool-size= ... VS spring.datasource.tomcat.max... = ... - What is the difference?


回答1:


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 Request Handling 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.

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.

Number of Threads for task execution

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.

Connection Pool properties

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.

Note

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.



来源:https://stackoverflow.com/questions/54126131/server-tomcat-max-threads-vs-corepoolsize-vs-spring-datasource-tomcat-max

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!