网络绑定任务的线程池大小
调整线程池大小的基本规则是什么,该线程池包含以下任务:
- 始终受网络限制;
- 访问具有不同吞吐量和延迟的外部服务。
我主要关心的是如何最佳地使用带宽(即不串行处理任务,但也不打开 1200 个网络连接);
What are the basic rules for sizing a thread pool which contains tasks that:
- are always network-bound;
- access external services with different throughput and latency.
My main concern is using the bandwith optimally ( i.e. don't process tasks serially, but don't open 1200 network connections either );
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的网络访问是同步的还是异步的?
如果你的网络访问和请求处理是异步的,那么线程池大小可以=> 可用核心数 + 1。
更新:可用核心数是指系统上可用的物理处理器的数量。 即使使用异步 I/O 的服务器也需要线程池来利用多个物理处理器。
如果您的网络访问和请求处理是同步的,那么调整线程池的大小就没有硬性规则。 在这种情况下,最好使线程池大小可配置。
如果您的请求处理不受 CPU 限制,则默认值的估计值可能为:(
请求处理延迟/网络延迟)*(可用核心数 + 1)
最大值为 4 * 可用核心数。
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.
我不是专家,但每个任务不应该有一个线程吗?
线程将阻塞/轮询,直到数据可用。
如果您正在等待连接,则启动一个线程来处理连接处理程序中的每个连接。
I'm not an expert but shouldn't you have one thread per task?
The threads will block/poll until data is available.
If you're waiting on a connection then start a thread to handle each connection in the connection handler.