question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

WebFlux with Java 11 HttpClient unexpected slow performance comparing with WebClient

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:10 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
Aleksandr-Filichkincommented, Feb 7, 2019

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!

0reactions
kivan-mihcommented, Apr 29, 2021

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?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Spring Boot performance battle: blocking vs non-blocking vs ...
Spring Webflux with WebClient and Apache clients wins in all cases. The most significant difference(4 times faster than blocking Servlet) when ...
Read more >
Does the use of Spring Webflux's WebClient in a blocking ...
Compared to the alternative RestTemplate, it seems like WebClient would spend additional resources by using the event loop. Is it correct that ...
Read more >
Web on Reactive Stack - Spring
The reactive WebClient operates in event loop style. So you can see a small, fixed number of processing threads related to that (for...
Read more >
Comparison of Java HTTP Clients - Reflectoring
This post provides an overview of some of the major libraries that are used as HTTP clients by Java applications for making HTTP...
Read more >
Simultaneous Spring WebClient Calls - Baeldung
It provides a reactive, non-blocking interface for sending HTTP requests. For an in-depth guide to reactive programming with WebFlux, check out ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found