关于 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/