[英]Throughput in spring boot netty web application
I would like to improve throughput in my web-server. 我想提高Web服务器的吞吐量。 But I don't understand what is really happening when I am testing it with high load (jmeter).
但是我不了解在高负载(jmeter)下测试时到底发生了什么。
I run spring boot webflux
app ( spring boot 2.0.2, netty
) on a computer with 8 core
cpu. 我在具有
8 core
cpu的计算机上运行spring boot webflux
应用程序( spring boot 2.0.2, netty
)。
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. "Thread.sleep(3000)"
-它是对同步作品的模仿。 Then I run jmeter tests
with 100 threads. 然后我用100个线程运行
jmeter tests
。 And I see a throughput only 2.5 message/sec
. 而且我发现吞吐量仅为
2.5 message/sec
。 I thought it should be about 100 messages/3 sec
(about 30 messages/sec) 我认为应该是
messages/3 sec
100条messages/3 sec
(大约30条消息/秒)
So, I have 2 questions: 所以,我有两个问题:
Thanks 谢谢
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. 您获得2.5条消息/秒,延迟3秒(在每个线程中),这使我们获得
2.5 * 3 = 7.5 = 8
内核。 Webflux by default uses availableProcessors()
as a default number of threads for processing network/work IO. 默认情况下,Webflux使用
availableProcessors()
作为处理网络/工作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
). 因此,您需要做的是要么增加处理线程的数量,要么将
Thread.sleep(3000)
块移至单独的ThreadPool/Executor
(这样就不会阻塞工作线程),或者您的Thread.sleep(3000)
代码应在某些情况下执行一种非阻塞API(例如,在webflux中,您可以使用Mono.fromCallable
)。
I would recommend you to go with the second/third approach, as non-blocking API should never be blocked. 我建议您采用第二种/第三种方法,因为非阻塞API绝不应该被阻塞。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.