gpt4 book ai didi

java - 高负载下的并行线程争用

转载 作者:行者123 更新时间:2023-12-03 12:47:39 24 4
gpt4 key购买 nike

我有一台四核机器。在高负载下,响应时间非常糟糕。这是非常明显的,因为工作队列在高负载下增长,而 4 个并行线程只能消耗这么快。

Mono.just(stream)
.flatMap(handler::handleRequest)
.subscribeOn(Schedulers.parallel())
.subscribe(this::response)

同样,当我收到对 I/O 调用的响应时,我会执行 .publishOn(Schedulers.parallel()) 以便在一个 CPU 调优线程。

我正在考虑使用有界弹性调度程序来启动我的管道,并将并行线程仅用于高度 CPU 密集型任务(POJO 操作和哈希计算)。所以基本上,我在弹性线程上启动我的管道,并在弹性线程上处理响应。

我使用无限弹性调度程序对我的应用程序进行了基准测试,结果堆大小爆炸了。但是,等待时间肯定更短。但是,如果我创建太多线程,调度开销有时会盖过较短的等待时间。

如何优化我的应用程序?我的目标是每个 JVM 大约 800 TPS。是否建议创建那么多线程?

最佳答案

Similarly, when I get a response for an I/O call, I do a .publishOn(Schedulers.parallel()) so that the response is processed on a CPU tuned thread.

这就是问题所在。你永远不应该在由 Schedulers.parallel() 启动的线程中进行阻塞调用(你可以使用 http://github.com/reactor/BlockHound,当你这样做时会抛出错误)。

So basically, I start my pipeline on an elastic threads and process the response on an elastic thread as well.

无需“在弹性线程上启动管道”。只需“正常”启动它,然后卸载对 Schedulers.boundedElastic() 的阻塞调用。

关于java - 高负载下的并行线程争用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62515815/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com