Nginx – Using uwsgi and gunicorn at the same time or fully switch to gunicorn

gunicornnginxpythonuwsgiwsgi

We are running our python app behind nginx. First we used uWSGI, because it is fast, reliable and easy to deploy. Next, as the number of simultaneous clients (using server-sent events/eventstream) increased, we have partially switched the app to gunicorn+gevent.

Currently, the app is served like this:

  • statics is handled by nginx directly;
  • short requests (REST API) is handled by uWSGI (nginx<->uwsgi connected via unix socket)
  • long requests (server-sent events) are handled by gunicorn+gevent (and nginx acts as a rev proxy)

Should we stay with this setup or are there any reasons for switching from uWSGI to gunicorn?

Best Answer

It really depends on how much of the uWSGI features are part of your infrastructure. One of the purposes of WSGI is allowing easy move from one adapter to another. If you use uWSGI only for the "WSGI" part you can move to gunicorn without problems.

Having said that, you should take in account that the uWSGI gevent support is really powerful and highly integrated with the uWSGI api (once you load the gevent plugin, all of the blocking internals of the server are hooked with gevent primitives), so maybe you can consider it (in addition to this uWSGI offloading allows you to move requests from one instance to another without blocking the frontend worker, so your rest api can be used as a "proxy with more logic")