如何在Spring Webflux / WebClient中设置事件循环池大小? [英] How to set event-loop pool size in Spring Webflux / WebClient?

查看:1499
本文介绍了如何在Spring Webflux / WebClient中设置事件循环池大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

多反应堆框架(如Vert.X)中,我们可以设置事件循环线程的数量,例如:

In multi-reactor framework such as Vert.X we can set the number of event-loop threads, e.g.:

final VertxOptions vertxOptions = new VertxOptions();
vertxOptions.setEventLoopPoolSize(16);
final Vertx myVertx = Vertx.vertx(vertxOptions);

如何在Spring Boot 2 WebFlux / WebClient中执行等效操作?

How to do the equivalent in Spring Boot 2 WebFlux / WebClient?

推荐答案

您有两种选择:


  1. 使用应用事件循环资源config的自定义程序覆盖 ReactiveWebServerFactory bean:

@Bean
public ReactiveWebServerFactory reactiveWebServerFactory() {
    NettyReactiveWebServerFactory factory = new NettyReactiveWebServerFactory();
    factory.addServerCustomizers(builder -> builder.loopResources(LoopResources.create("my-http", 16, true)));

    return factory;
}


  • 或者使用 -Dreactor.ipc。 netty.workerCount = 16 环境变量。默认情况下,它的值设置为 Math.max(availableProcessors(),4)

  • Or use -Dreactor.ipc.netty.workerCount=16 environment variable. By default it's value is set to Math.max(availableProcessors(), 4).

    这篇关于如何在Spring Webflux / WebClient中设置事件循环池大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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