【发布时间】:2017-08-18 01:45:21
【问题描述】:
有趣的是,我认为有 255 个并发用户,异步 API 会有更好的性能。这是我的 Spring 服务器中的 2 个端点:
@RequestMapping("/async")
public CompletableFuture<String> g(){
CompletableFuture<String> f = new CompletableFuture<>();
f.runAsync(() -> {
try {
Thread.sleep(500);
f.complete("Finished");
} catch (InterruptedException e) {
e.printStackTrace();
}
});
return f;
}
@RequestMapping("/sync")
public String h() throws InterruptedException {
Thread.sleep(500);
return "Finished";
}
在/async 中,它在不同的线程上运行它。我正在使用Siege 进行负载测试,如下所示:
siege http://localhost:8080/sync --concurrent=255 --time=10S > /dev/null
对于async 端点,我得到了27 hits 的事务号
对于sync 端点,我得到了1531 hits 的事务号
那为什么会这样呢?为什么异步端点不能处理更多事务?
【问题讨论】:
标签: java spring api testing asynchronous