Skip to content

WebFlux with Java 11 HttpClient unexpected slow performance comparing with WebClient #22333

@Aleksandr-Filichkin

Description

@Aleksandr-Filichkin

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.
image

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);
    }

image

Metadata

Metadata

Assignees

No one assigned

    Labels

    in: webIssues in web modules (web, webmvc, webflux, websocket)status: invalidAn issue that we don't feel is valid

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions