user12372643
user12372643

Reputation: 113

How to increase Spring WebClient concurrent requests limit?

I have 2 microservices. First one is simply echo service which returns after 3 seconds delay. Second one calls first over spring webclient. When I simulate 501 concurrent users to request second microservice, first 500 users get response in 3 seconds and the last one gets response in 6 seconds. Means spring webclient supports only 500 concurrent connections by default. Corresponding value is configurable in apache client. But I can't find how to configure it in spring webclient. Similar situation with WebSocket, it supports only 256 concurrent connections. How to configure it?

Tests are done with jMeter. If I test first microservice directly - there is no limit.

public TestController(WebClient.Builder webClientBuilder) {
    this.webClient = webClientBuilder.baseUrl("http://localhost:8081").build();
}

@GetMapping("/test1")
public Mono<String> test1() {
    return webClient
            .get().uri("/test/HTTP")
            .retrieve().bodyToMono(String.class);
}

Upvotes: 2

Views: 6242

Answers (1)

user12372643
user12372643

Reputation: 113

Thanks Mark, solution from you link works.

Either this:

HttpClient httpClient = HttpClient.create(ConnectionProvider
        .elastic("myConnectionProvider"));
this.webClient = webClientBuilder.clientConnector(new ReactorClientHttpConnector(httpClient))
        .baseUrl("http://localhost:8081").build();

Or that:

HttpClient httpClient = HttpClient.create(ConnectionProvider
        .fixed("myConnectionProvider", 1000));
this.webClient = webClientBuilder.clientConnector(new ReactorClientHttpConnector(httpClient))
        .baseUrl("http://localhost:8081").build();

Upvotes: 3

Related Questions