Reputation: 41
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?
Upvotes: 3
Views: 4033
Reputation: 10177
Their architecture page gives more advice on choosing the number of workers:
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.
The answer to "why not use num of cores as worker count" is that sometimes workers blocked (for example during IO operations), so having extra workers utilizes the CPU better.
Upvotes: 3