这是一个反应器并行执行的例子。当我们以很少的负载运行服务时,它工作得很好。然而,当我们强调服务时,它并没有像预期的那样响应。一旦我们达到40请求/秒(更长意味着超过5秒),响应时间就会变得更长。
下面是导致问题的代码片段:)
public Mono<ServerResponse> getAccountWithBalances(final ServerRequest request) {
final List<String> accounts = List.of("account-1", "account-2", "account-3", "account-4");
return Flux.fromIterable(accounts)
.log(Thread.currentThread().getName())
.parallel()
.runOn(Schedulers.boundedElastic())
.flatMap(account ->
webClient.get().uri("/stubs/accounts")
.retrieve()
.bodyToMono(Object.class)
)
.doOnError(throwable -> LOGGER.error("Error during runtime ", throwable))
.sequential()
.collectList()
.flatMap(accountsWithBalances ->
ServerResponse.ok().contentType(MediaType.APPLICATION_JSON).bodyValue(accountsWithBalances));
}这是我拥有代码的存储库:https://github.com/EstefaniaExamples/webflux-load-test
这是wiremock服务器所在的存储库:https://github.com/EstefaniaExamples/wiremock-standalone-server
这个话题真的很有趣:),我还在从这类事情开始,所以任何帮助都是wellcome。
提前谢谢你了。
发布于 2021-03-20 05:52:05
谢谢你们两位!真的很感谢,我一直在调查这个问题,感谢你的评论,我看到了这条路。是的,wiremock服务器导致了这个问题。我已经缩放了副本,还在wiremock服务器(https://github.com/sagardutta/wiremock-load-test)中做了一些更改,我认为我得到的结果是可以的。所以,代码不是导致问题的原因,这是好的部分。
诚挚的问候。
https://stackoverflow.com/questions/66586989
复制相似问题