WebClient maxConnection 池限制?
Posted
技术标签:
【中文标题】WebClient maxConnection 池限制?【英文标题】:WebClient maxConnection pool limit? 【发布时间】:2019-12-31 13:52:34 【问题描述】:如果远程服务阻塞,我可以发送多少并发请求?
意思是:使用WebClient
时spring内部使用的maxConnection池限制是多少?
@Autowired
private WebClient webClient;
webClient.post().uri(url).syncBody(req).retrieve().bodyToMono(type);
还有:如何修改?
【问题讨论】:
【参考方案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。
【讨论】:
以上是关于WebClient maxConnection 池限制?的主要内容,如果未能解决你的问题,请参考以下文章
如何在 Spring Webflux / WebClient 中设置事件循环池大小?
Apache的commons-pool池创建多线程使用WebClient