I am making use of gevent in my Python application (Django based). However, I am now wondering how to run it in production. What server should I use? During development, I use gevent.pywsgi, but is that production-ready? I have also heard about gunicorn, but I've seen some pretty bad benchmarks about it.
Note: I need SSL.
By default, Gunicorn uses a synchronous worker class to serve requests, but it can be easily configured to use gevent by simply adding -k gevent to the run command.
The easiest way to run a Flask application is to use a built-in development server. But even this beast supports two modes of request handling. In the single-threaded mode, a Flask application can handle no more than one HTTP request at a time. I.e. the request handling becomes sequential.
server – TCP/SSL server. If the user initialized the server with an address rather than socket, then this function must create a socket, bind it, and put it into listening mode.
gevent is a coroutine-based cooperative multitasking python framework that relies on monkey patching to make all code cooperative. Gevent actually draws its lineage from Eve Online which was implemented using Stackless Python which eventually evolved into eventlet which inspired gevent.
Gunicorn is really the best option. It's fast, it's written in pure python (which makes it easy to deploy on hosted services like Heroku), and it's well maintained and used for a large amount of Python web applications.
By default, Gunicorn uses a synchronous worker class to serve requests, but it can be easily configured to use gevent by simply adding -k gevent
to the run command.
Just a quick note: you should always run gunicorn behind a proxy like NGINX, Varnish, etc., as this will allow gunicorn to handle far more requests than it can otherwise, due to response buffering.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With