Reputation: 1771
I`m new to this, and misunderstand how Gunicorn + Flask works.
When i run Gunicorn with 4 workers it creates 4 instances of my Flask app, or it will create 4 processes that handle web requests from Nginx and one instance of Flask app?
If i make simple implementation of memory cache(dictionary for example) in my app, will gunicorn create more than one instances of app and therefore more than one instances of cache?
Upvotes: 7
Views: 3627
Reputation: 7758
It will create 4 gunicorn workers to handle the one flask app. If you spin 4 instances of a flask app (with docker for example) you will need to run gunicorn 4 times. Finally to handle all those flask instances you will need a Nginx server in front of it acting as a load balancer.
For example, if one user is doing a registration routine that takes a lot of time due to multiple querys to the database you still have another worker to send the request to the flask instance.
I get our point, but Flask is not WSGI ready, which is the stardard. Gunicorn is playing that role in production so you get more reliability instead of using the Develpment standard Werkzeug server that comes with it. In other words, Gunicorn is just a wrapper on you flask object. It just handles the requests and let Flask do its thing.
Upvotes: 11