【问题标题】:Default number of threads in Spring boot 2.0 reactive webflux configurationSpring boot 2.0响应式webflux配置中的默认线程数
【发布时间】:2018-04-06 03:14:59
【问题描述】:

在使用 Spring 5 响应式 Webflux 和 Spring Boot 2.0 时,用于处理请求的默认线程数是多少?如何配置使用的线程数?

【问题讨论】:

    标签: spring spring-boot reactive spring-webflux


    【解决方案1】:

    请求处理的默认线程数由底层网络服务器决定;默认情况下,Spring Boot 2.0 使用的是 Reactor Netty,它使用的是 Netty 的默认设置(查看EventLoopGroup 文档)。

    Spring Boot 很快将允许您自定义该部分(请参阅#10418)。同时,您可以提供自己的ReactiveWebServerFactory bean 并通过HttpServer 配置选项进行更改(请参阅this comment)。

    【讨论】:

    • 目前我在日志中看到reactor-http-nio-1,我使用的是SpringBoot 2.0.0 M6。如何配置 netty 以使用所有内核?
    【解决方案2】:

    目前看来,Spring Webflux 2.0 似乎没有提供控制线程的能力。

    Spring Webflux 2.0 正在使用 Reactor-Netty。而ReactorNettyclass 提供了一些配置。

    • reactor.netty.ioWorkerCount
    • reactor.netty.ioSelectCount
    • reactor.netty.pool.maxConnections

    所以,你可以这样使用它。

    System.setProperty("reactor.netty.ioWorkerCount", "100");
    

    希望 Spring Boot 提供自定义配置。

    【讨论】:

      猜你喜欢
      • 2020-06-05
      • 2020-12-12
      • 2021-03-20
      • 2017-08-08
      • 2019-06-07
      • 2021-12-17
      • 2021-03-26
      • 1970-01-01
      • 2020-04-05
      相关资源
      最近更新 更多