[英]How to figure out N threads I need in a parallel execution context?
I'm working in a redelivery system. 我正在重新交付系统中工作。 This system attempt to execute an action, if the action fails, it try to execute again two times with an interval of five minutes, so I use the
ExecutorService
implementation to perform the first execution and ScheduledExecutorService
to schedule the other ones, depending of its results (fail). 此系统尝试执行一个动作,如果该动作失败,它将尝试以五分钟的间隔再次执行两次,因此我将使用
ExecutorService
实现执行第一次执行,并使用ScheduledExecutorService
来安排其他执行,具体取决于执行结果(失败)。
What should I consider to figure out the number of threads I need? 我应该考虑什么来确定所需的线程数? In this moment I use only a single thread model (created by
newSingleThreadScheduledExecutor
method) 目前,我仅使用一个线程模型(由
newSingleThreadScheduledExecutor
方法创建)
You should only need the one thread as only one action is running at a time. 您一次只需要运行一个操作,因此只需要一个线程。 You could use a CachedThreadPool and not worry about it.
您可以使用CachedThreadPool而不用担心。
Without knowing details about the load your system has, environment it is using and how long does it take to process one message it is hard to say which number of threads you need. 在不了解有关系统负载,系统正在使用的环境以及处理一条消息所需的时间的情况下,很难说出您需要多少线程。 However, you can think of the following base principles:
但是,您可以考虑以下基本原则:
x64
it is typically 1MB
per thread. x64
,每个线程通常为1MB
。 I would probably create 2 thread pools (one scheduled, one non-scheduled) for both sending and redelivery and test them under high load varying number of threads from 2 to 10 to see which number suits best. 我可能会为发送和重新交付创建2个线程池(一个预定的线程池,一个非预定的线程池),并在高负载下(从2到10)更改线程数来测试它们,以查看哪个数字最合适。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.