Throughput in spring boot netty web application

I would like to improve throughput in my web-server. But I don't understand what is really happening when I am testing it with high load (jmeter).

I run spring boot webflux app (spring boot 2.0.2, netty) on a computer with 8 core cpu.
I created a simple controller with this code:

@GetMapping("/test-delay")
public Mono<String> testGetWithDelay() throws InterruptedException {
    Thread.sleep(3000);
    return Mono.just("current time:" + LocalDateTime.now());
}

"Thread.sleep(3000)" - it is an imitation of synchronous works. Then I run jmeter tests with 100 threads. And I see a throughput only 2.5 message/sec. I thought it should be about 100 messages/3 sec (about 30 messages/sec)

So, I have 2 questions:

  1. why the throughput so low
  2. how can I manage it

Thanks

1 answer

  • answered 2018-05-16 07:31 Dmitriy Dumanskiy

    Your results are correct. You get 2.5 message/sec with delay 3 secs (in every thread), that gives us 2.5 * 3 = 7.5 = 8 cores. Webflux by default uses availableProcessors() as a default number of threads for processing network/work IO.

    So what you need to do is either increase the number of processing threads or move Thread.sleep(3000) block to separate ThreadPool/Executor (so working threads are not blocked) or your Thread.sleep(3000) code should be executed in some kind of non-blocking API (for example in webflux you may use Mono.fromCallable).

    I would recommend you to go with the second/third approach, as non-blocking API should never be blocked.