26

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.

Teun Zengerink
  • 4,277
  • 5
  • 30
  • 32
Flavien
  • 7,497
  • 10
  • 45
  • 52
  • 5
    Two points about this benchmark. 1.) The gunicorn test uses the default sync worker not the gevent worker that you are looking to use. 2.) From the summary "If there is one thing which made this benchmark clear is that most Python Web servers offer great performance and if you feel things are slow the first thing to look at is really your own application." – Mark Lavin Jun 13 '12 at 18:27
  • 9
    See answer to a similar question (http://stackoverflow.com/questions/7855343/run-web-app-with-gevent/7857201#7857201), the author of gevent himself says, in a nutshell, "Use gunicorn." – akent Jun 16 '12 at 11:43

1 Answers1

38

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.

rdegges
  • 32,786
  • 20
  • 85
  • 109
  • 7
    I've seen that I need to disable buffering if I use it with gevent. Does it cancel the benefits of Nginx? – Flavien Aug 01 '12 at 16:29
  • 1
    What is the point of using HTTP on back-end server? Unlike FastCGI, SCGI and uwsgi, HTTP wasn't designed for front-end to back-end communication and using it for that purpose has its limitations and problems. – Alex K Dec 14 '12 at 04:02
  • I believe you don't need to worry about running with a reverse proxy like nginx when using Heroku since the routing mesh handles it. – dhackner Jan 17 '13 at 01:05
  • 1
    @Flavien only if you're doing streaming stuff, like long polling, comet, etc. – twneale Apr 09 '14 at 02:11
  • 1
    Hi, what is the difference between the flags: `k` and `worker-class`? https://docs.gunicorn.org/en/stable/run.html?highlight=worker-class#commonly-used-arguments – hafiz031 Dec 05 '21 at 09:36
  • 1
    @hafiz031 There's no difference, one is a short version and the other is the long version of the option so you can use either one (https://superuser.com/questions/174564/why-are-there-short-and-long-alternatives-for-command-line-options) – shaye059 Jan 25 '22 at 13:58