usual me
usual me

Reputation: 8778

About the optimal number of gunicorn workers

About gunicorn: I was expecting the optimal number of workers to be $num_cores or $num_cores-1, i.e., each worker has its own core. But the gunicorn documentation gives the following guidelines:

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.

I don't understand the explanation. Does this suggest that the same core can be used simultaneously for 1) reading or writing from the socket AND 2) processing a request? (Can a single core do such thing?)

Upvotes: 3

Views: 1939

Answers (1)

Joe Doherty
Joe Doherty

Reputation: 3948

The answer is based on the processes waiting on things.

For example the core is doing nothing when you make a call to an SQL server. Having an extra worker per core mean the kernel scheduler can use the time with the other process.

You will get more RPS this way.

If you know where the time goes per request in good details and your load patterns you will be able to further change this to suit you needs.

Upvotes: 5

Related Questions