Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How many gunicorn workers in a loadbalanced dockerized Flask app?

I use gunicorn for my flask app. So far I have been following the guideline so that the numbers of gunicorn workers per machine is (2 x $num_cores) + 1 (they sit behind a load balancer). I am in the process of dockerising the app and my question is: Should I run one gunicorn worker per container (again, the dockerised is load balanced)? Or is there any point in running multiple gunicorn workers per docker container?

like image 537
Bjorn Stiel Avatar asked Feb 17 '16 21:02

Bjorn Stiel


1 Answers

It entirely depends on what type of workers you use and the specifics of your app. Some apps will work well with a large number of processes, some with threads, some with a combination of both, some with gevent coroutines, etc. It's down to you to experiment and test your app under load to determine what works well.

Typically, Python will perform better with processes than threads, and the typical number of processes is either the number of cores or 2x + 1. Gevent coroutines only run within one process (and core) but don't have a limit beyond memory requirements.

like image 101
davidism Avatar answered Oct 13 '22 20:10

davidism