确定包含以下任务的线程池大小的基本规则是什么:
- 始终是网络绑定的;
- 以不同的吞吐量和延迟访问外部服务。
我主要关心的是优化使用带宽(即不要连续处理任务,但也不要打开 1200 个网络连接);
确定包含以下任务的线程池大小的基本规则是什么:
我主要关心的是优化使用带宽(即不要连续处理任务,但也不要打开 1200 个网络连接);
Is your network access synchronous or asynchronous?
If your network access and request processing is asynchronous, then the thread pool size can be => Number of available cores + 1.
UPDATE: By available cores, I mean the number of physical processors available on the system. A thread pool is required even for a server using async I/O to take advantage of multiple physical processors.
If your network access and request processing is synchronous, then there is no hard-and-fast rule for sizing the thread pool. It is always better to make the thread pool size configurable in this case. A guestimate for a default value, given that your request processing is not CPU bound, could be:
(Request Processing Latency/Network Latency) * (Number of Available cores + 1) with a maximum value of 4 * Number of Avaliable cores.
我不是专家,但你不应该每个任务有一个线程吗?线程将阻塞/轮询,直到数据可用。如果您正在等待连接,则启动一个线程来处理连接处理程序中的每个连接。