2

I'm using gunicorn for deploying my web service. And the document suggests an example configure file in the following webpage for deploying: http://docs.gunicorn.org/en/latest/configure.html.

And the code is like:

import multiprocessing

bind = "127.0.0.1:8000"
workers = multiprocessing.cpu_count() * 2 + 1

I don't know why we should use this weird count: "num_of_cpu_core * 2 + 1". Why not just using the num of cpu cores?

4

1 回答 1

3

他们的架构页面提供了更多关于选择工人数量的建议:

虽然不是太科学,但该公式基于这样的假设:对于给定的核心,一个工作人员将在另一个工作人员处理请求时从套接字读取或写入。

“为什么不使用内核数作为工作人员数量”的答案是有时工作人员被阻塞(例如在 IO 操作期间),因此有额外的工作人员可以更好地利用 CPU。

于 2013-10-30T08:13:24.783 回答