Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WebClient maxConnection pool limit?

How many concurrent requests can I send if the remote service if blocking? Means: what is the maxConnection pool limit that spring uses internally when using WebClient?

@Autowired
private WebClient webClient;

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

And moreover: how can I modify it?

like image 428
membersound Avatar asked Aug 27 '19 11:08

membersound


People also ask

Is WebClient multithreaded?

Because WebClient is immutable it is thread-safe. WebClient is meant to be used in a reactive environment, where nothing is tied to a particular thread (this doesn't mean you cannot use in a traditional Servlet application).

Does WebClient use Netty?

WebClient provides a higher level API over HTTP client libraries. By default it uses Reactor Netty but that is pluggable with a different ClientHttpConnector.

Is WebClient reactive?

WebClient is a non-blocking, reactive client for performing HTTP requests with Reactive Streams back pressure.

Is Spring WebClient async?

Conclusion In this article, we explored two different ways of using web clients in Spring. RestTemplate uses Java Servlet API and is therefore synchronous and blocking. Conversely, WebClient is asynchronous and will not block the executing thread while waiting for the response to come back.


2 Answers

Before reactor-netty 0.9.0.M4 version there wasn't limit by default because of "elastic" connection provider was used. This fix changed it to "fixed" connection provider with the limit of 500.

To change the connection pool limit you could define your own WebClient.Builder bean and use it to create 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));
}

Or you could implement custom org.springframework.boot.web.reactive.function.client.WebClientCustomizer in the same manner with the predefined WebClient.Builder

like image 125
Alexander Pankin Avatar answered Oct 23 '22 09:10

Alexander Pankin


taken from the netty documentation

By default, the TCP client uses a “fixed” connection pool with 500 as the maximum number of the channels and 45s as the acquisition timeout.

like image 3
Toerktumlare Avatar answered Oct 23 '22 09:10

Toerktumlare