Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WSGI vs uWSGi with Nginx [closed]

Could anyone please explain pros/cons when using WSGI VS uWSGI with Nginx.

Currently i am building up a production server for the Django website which i have prepared but unable to decide whether should i go with WSGI or uWSGI. Could you please explain in detail what differentiates each configuration? Which configuration should scale the best?

Thanks in advance

like image 562
fear_matrix Avatar asked Oct 12 '11 12:10

fear_matrix


People also ask

Is nginx needed with uWSGI?

Can I then ditch NGINX? uWSGI could be used as a standalone web server in production, but that is not it's intentional use. It may sound odd, but uWSGI was always supposed to be a go-between a full-featured web server like NGINX and your Python files.

What is the difference between uWSGI and WSGI?

uWSGI is a software application that "aims at developing a full stack for building hosting services". It is named after the Web Server Gateway Interface (WSGI), which was the first plugin supported by the project. uwsgi (all lowercase) is the native binary protocol that uWSGI uses to communicate with other servers.

Does nginx support WSGI?

Nginx also functions well as a reverse proxy to handle requests and pass back responses for Python WSGI servers or even other web servers such as Apache.

Why is uWSGI needed?

WSGI is a standard described on PEP 3333 and basically, provides a standard interface between web applications written in Python and Webservers. That means, WSGI gives portability to your Python Web Application across many different Web Servers, without any additional configurations on your NGINX, Apache, etc.


3 Answers

Ok, guys this confusion is because of lack of detail from several sources, and the naming of these protocols, and what WSGI actually is.

Summary:

  1. WSGI and uwsgi both ARE protocols, not servers. It is used to communicate with web servers for load balancing and especially to take advantage of extra features that pure HTTP can not provide. So far Nginx and Cherokee have implemented this protocol.
  2. uWSGI is a server and one of the protocols it implements is WSGI (do not confuse the uwsgi protocol with the uWSGI server). WSGI is a Python specification. There are several implementations of the WSGI specification and it's intended to be used for more than just application servers/web servers, but there are quite a few WSGI application servers (ie. CherryPy, which also happens to have a production ready WSGI compliant web server, if you weren't confused enough already!).
  3. Comparing uwsgi to WSGI is comparing oranges to apples.
like image 59
Derek Litz Avatar answered Oct 18 '22 23:10

Derek Litz


It is generally best to run Python in a separate process from your main web server. That way, the web server can have lots of tiny threads that serve static content really fast, while your separate Python processes will be big and heavyweight and each be running their own Python interpreter. So plain WSGI is bad, because it bloats every single one of your nginx threads with a big Python interpreter. Using flup or gunicorn or uWSGI behind nginx is much better, because that frees up nginx to simply serve content, and lets you choose how many tiny light nginx threads to run, independently of your choice of how many heavyweight Python threads you bring up to serve dynamic content. People seem very happy with gunicorn at the moment, but any of those three options should work fine.

Going forward, it also frees you up to move the Python to another server when load starts to get serious.

like image 27
Brandon Rhodes Avatar answered Oct 18 '22 23:10

Brandon Rhodes


I believe this right here http://flask.pocoo.org/docs/deploying/uwsgi/ is a good answer to clear up the confusion. The question isnt silly, happens to anyone who sees the two terms and has no prior info on how things work outside of mod_PHP world (for e.g. nothing against php or folks)

The site does well to explain in practical terms what is needed and what is the difference as well as a good deployment example for nginx.


For the convenience, the explanation from Flask wiki is quoted here:

uWSGI is a deployment option on servers like nginx, lighttpd, and cherokee; see FastCGI and Standalone WSGI Containers for other options. To use your WSGI application with uWSGI protocol you will need a uWSGI server first. uWSGI is both a protocol and an application server; the application server can serve uWSGI, FastCGI, and HTTP protocols.

The most popular uWSGI server is uwsgi, which we will use for this guide. Make sure to have it installed to follow along.

like image 32
Abhishek Dujari Avatar answered Oct 18 '22 21:10

Abhishek Dujari