如何解决Spring Boot Reactive:经过时间计算
我目前正在使用 Spring Boot Reactive(使用 webflux)来开发微服务。在其中,我实现了某种经过时间的计算,以确定流程运行所需的时间。
基本上,当进程开始时,我将当前时间戳初始化为开始时间戳,如下所示:
...
metrics.setStartMillis(System.currentTimeMillis());
...
然后它会分别在doOnSuccess()
和onErrorResume()
中打印进程是否成功以及经过的时间:
...
metrics.setStartMillis(System.currentTimeMillis());
return webclientAdapter.getResponse(request)
.doOnSuccess(success -> {
metrics.info(true); // This will print a metric log indicating a success process along with process time with current timestamp
})
.onErrorResume(error -> {
metrics.info(false); // This will print a metric log indicating a failed process along with process time with current timestamp
});
...
通过使用 cUrl 以 100 毫秒的延迟模拟后端调用来测试服务时,经过的时间设法正确打印(经过时间约为 100 毫秒),但是,在使用 jmeter 的负载测试期间,打印的经过时间变得非常快(~0 - 20ms ish) 尽管服务被配置为以 100 毫秒的延迟调用模拟后端。
这是否与 Reactive 处于事件循环中的性质有关,如果是,我如何确保能够正确计算调用进程经过的时间?
如果有任何混淆,请随时询问更多信息。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。