-
Notifications
You must be signed in to change notification settings - Fork 38.7k
Description
Environment: 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);
}