python - 关于 gunicorn worker 的最佳数量

标签 python gunicorn

关于 gunicorn:我期望最佳 worker 数量为 $num_cores$num_cores-1,即每个 worker 有自己的核心。但是 unicorn documentation给出了以下准则:

Gunicorn relies on the operating system to provide all of the load balancing when handling requests. Generally we recommend (2 x $num_cores) + 1 as the number of workers to start off with. While not overly scientific, the formula is based on the assumption that for a given core, one worker will be reading or writing from the socket while the other worker is processing a request.

我不明白这个解释。这是否表明同一核心可以同时用于 1) 从套接字读取或写入以及 2) 处理请求? (单核能做到吗?)

最佳答案

答案基于等待事物的进程。

例如,当您调用 SQL 服务器时,核心什么也不做。每个核心有一个额外的工作人员意味着内核调度程序可以将时间用于其他进程。

您将通过这种方式获得更多 RPS。

如果您详细了解每个请求的时间以及您的负载模式,您将能够进一步更改它以满足您的需要。

关于python - 关于 gunicorn worker 的最佳数量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25364336/

相关文章:

python - 如何检查数据框列中的值是否为字符串?

python - 使用 pytest 时在同一包中导入的 ModuleNotFoundError

pycharm - 为运行猎鹰应用程序设置的环境

django - 如何在virtualenv中停止gunicorn_django?

Python 2 原始输入(): EOFError when reading a line in WINDOWS 7 command prompt

Python 字符串转十六进制

python - 如何快速计算 numpy.array 中的相等元素?

mysql - Gunicorn 多线程与 MySQL

性能问题 : Async gRPC with Gunicorn + Tornado

python - 如何根据 Flask 中的服务器变量选择配置?