【问题标题】:WebClient maxConnection pool limit?WebClient maxConnection 池限制?
【发布时间】:2019-12-31 13:52:34
【问题描述】:

如果远程服务阻塞,我可以发送多少并发请求? 意思是:使用WebClient时spring内部使用的maxConnection池限制是多少?

@Autowired
private WebClient webClient;

webClient.post().uri(url).syncBody(req).retrieve().bodyToMono(type);

还有:如何修改?

【问题讨论】:

    标签: java spring spring-boot spring-webflux spring-webclient


    【解决方案1】:

    在 reactor-netty 0.9.0.M4 版本之前,默认情况下没有限制,因为使用了“弹性”连接提供程序。 This fix 将其更改为“固定”连接提供程序,限制为 500。

    要更改连接池限制,您可以定义自己的 WebClient.Builder bean 并使用它来创建 WebClient

    @Bean
    public WebClient.Builder webClientBuilder() {
        String connectionProviderName = "myConnectionProvider";
        int maxConnections = 100;
        int acquireTimeout = 1000;
        HttpClient httpClient = HttpClient.create(ConnectionProvider
                .fixed(connectionProviderName, maxConnections, acquireTimeout));
        return WebClient.builder()
                .clientConnector(new ReactorClientHttpConnector(httpClient));
    }
    

    或者您可以使用预定义的WebClient.Builder 以相同的方式实现自定义org.springframework.boot.web.reactive.function.client.WebClientCustomizer

    【讨论】:

      【解决方案2】:

      取自网络documentation

      默认情况下,TCP 客户端使用 500 的“固定”连接池作为 最大通道数,采集超时时间为45s。

      【讨论】:

        猜你喜欢
        • 2011-08-16
        • 2020-08-06
        • 1970-01-01
        • 2011-02-06
        • 1970-01-01
        • 2019-05-16
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多