WebFlux with Java 11 HttpClient unexpected slow performance comparing with WebClient
See original GitHub issueEnvironment: Spring Boot 2.1.2.RELEASE, Java 11(OpenJDK/Oracle)
So, I have RestConrtoller that sends an incoming request to another Rest service and returns the result back to clients.
So I compared WebClient with Java 11 HttpClient and I see an unexpected slow performance (looks like due to high GC usage) for Java 11 HttpClient.
Jmeter shows that with Java 11 HttpClient we have in 2 times less throughput than with WebClient. The problem cannot be in Java HttpClient because I tested the same stuff with Spring MVC and it has the same performance as with WebClient.
All code you can see here https://github.com/Aleksandr-Filichkin/spring-mvc-vs-webflux. JMeter files for the test also are added.
I think the problem in memory because I see high GC usage for HttpClient comparing with WebClient.
So getUserUsingWithCF with Spring MVC works in two times faster than getUserUsingWebfluxJavaHttpClient with WebFlux
@GetMapping(value = "/completable-future")
public CompletableFuture<String> getUserUsingWithCF(@RequestParam long delay) {
return sendRequestWithHttpClient(delay).thenApply(x -> "completable-future: " + x);
}
@GetMapping(value = "/webflux-java-http-client")
public Mono<String> getUserUsingWebfluxJavaHttpClient(@RequestParam long delay) {
CompletableFuture<String> stringCompletableFuture = sendRequestWithHttpClient(delay).thenApply(x -> "webflux-java-http-client: " + x);
return Mono.fromFuture(stringCompletableFuture);
}
Issue Analytics
- State:
- Created 5 years ago
- Comments:10 (4 by maintainers)
Hi @bclozel. I agree with your comments. I see that it’s not a Spring problem. But 1 CPU and 1 GB is a quite popular setup for dockerized microservices on Kubernetes and AWS ECS cluster. That is why I made benchmarks for this setup.
Thank you!
I have switched from OkHTTP 3.x to Java 15 http cllient and performance decreased significantly. My use case involves downloading many (~50000) average sized binary files (100s kb’s to 10’s megabytes) from the https in parallel threads. The performance degradation is about 50%. Does anyone meet such problems?