网络客户端最大连接池限制?



如果远程服务阻塞,我可以发送多少个并发请求? 意味着:弹簧在使用WebClient时内部使用的最大连接池限制是多少?

@Autowired
private WebClient webClient;
webClient.post().uri(url).syncBody(req).retrieve().bodyToMono(type);

此外:我该如何修改它?

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

要更改连接池限制,您可以定义自己的WebClient.BuilderBean 并使用它来创建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

取自netty文档

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

最新更新