Home » Categories » Linux Cloud Server » Python |
A Comparison of Web Servers for Python Based Web Applications |
Article Number: 261 | Rating: Unrated | Last Updated: Sat, Jan 4, 2014 at 1:22 AM
|
In this article, we will talk about three main things: Python, Web Servers, and most importantly the bits and bobs in-between the two. Jokes aside, this rather long article might seem dire for some looking for quick guidance or answers. Unfortunately, unlike most things in the world of Python, when it comes to choosing a production server stack to deploy your application on, there is not one-- and preferably only one --obvious way to do it. However, this should not scare you. After completing this article, you will have a good knowledge of how different web servers work and handle the task of talking with Python based web applications. Upon gauging your needs and requirements, you will be able to decide which server to use. Python Web Server Gateway Interface v1.0 (WSGI)Understanding the IssuesToday, there exists web servers (or modules for servers) in ever growing numbers specifically designed (or adapted) to work with Python web applications interchangeably. However, this has not always been the case. In ye olde days, developers did not really have the possibility to switch web servers at will easily, and each switch came with a cost due to dependencies and limitations. Upon deciding on a framework to build on, you would have also decided, not always willingly nor consciously, on the server(s) you could use to serve the application as well. This was due to the lack of existence of a universally accepted interface specification: a common ground which applications (frameworks) and web servers alike would adapt and use to communicate, allowing interchangeability of components when necessary with possibly zero code change. Birth of the StandardAt beginning of this century, efforts were made to finally solve the issue with the presentation of Python Enhancement Proposal (PEP) 333 to the community. From the PEP (Python Enhancement Proposal) 333:
As explained in the PEP, this new standard was (and is) meant to allow portability across (and between) [web] servers and [Python web] applications. The standard's powerful features and its wide adoption compared to those from before lead the way for today: a world where many (perhaps too many) web servers willing to do the job for you exist. The ComparisonIn this comparison of web servers for Python based web applications, we will talk about some of the choices available and what makes them stand out. The aim here is for the reader to have a clearer vision and to provide help to match the servers against applications' custom needs to find the one. Due to the vast number of options (more popping up every day!), we will filter our way through and talk about those which are "special" in various ways: popularity, solidness, or doing something different (or better) compared to the rest. Note: I would like to advise you, the reader, to be wary of biased and deceiving benchmarks which tend to not reflect the conditions of a real production environment. Unfortunately, those [articles] do not really mean much when it comes to choosing a web server for production, which is also highly unlikely to be the part causing the bottleneck. You are, therefore, advised to gauge and understand your own needs and then to try different options, refraining from speculative numbers to avoid real future disaster scenarios. Web Servers (Alphabetical Order)CherryPy WSGI ServerWhat is it? CherryPy is actually a web framework. Yet it is a fully self-contained one -- meaning that it can run on its own, including in production scenarios without the need of additional software. This is achieved thanks to its own WSGI, HTTP/1.1-compliant web server. CherryPy project describes it as a "A high-speed, production ready, thread pooled, generic HTTP server". As it is a WSGI server, it can be used to serve any other WSGI Python application as well, without being bound to CherryPy's application development framework. Why should you consider using it?
GunicornWhat is it? Gunicorn is a stand-alone web server which offers quite a bit of functionality in a significantly easy to operate fashion. It uses the pre-fork model -- meaning that a central master process (Gunicorn) is tasked with managing the initiated worker processes (of differing types), which then handle and deal with the requests directly. And all this can be configured and adapted to suit your needs and diverse production scenarios. Why should you consider using it?
Tornado (HTTP Server via wsgi.WSGIContainer)What is it? Tornado is an application development framework and a networking library designed for handling asynchrnous operations, allowing servers to maintain a lot of open connections. It also comes with a WSGI server which other WSGI Python applications (and frameworks) can use to run. Why should you consider using it?
Although under these circumstances you might want to choose Tornado's WSGI server for your project, you can also opt to use Gunicorn with Tornado [Asynchronous] workers. Twisted WebWhat is it? Twisted Web is the web server that comes with the Twisted networking library. Whereas Twisted itself is "an event-driven networking engine", theTwisted Web server runs on WSGI and it is capable of powering other Python web applications. Why should you consider using it?
uWSGIWhat is it? Despite its very confusing naming conventions, uWSGI itself is a vast project with many components, aiming to provide a Why should you consider using it?
Waitress WSGI ServerWhat is it? Waitress is a pure-Python WSGI server. At a first glance it might not appear to be that much different than many others; however, its development philosophy separates it from the rest. Its aim for easing the production (and development) burden caused by web servers for Python web-application developers. Waitress achieves this by neutralizing issues caused by platform (ex. Unix vs. Windows), interpreter (CPython vs. PyPy) and Python (version 2 vs. 3) differences. Why should you consider using it?
Modules for Stand-Alone Serversmod_python with a WSGI adapter (Apache) (Embedding Python) What is it? Simply put, mod_python is an Apache module that embeds Python within the server itself. Although not recommended for various reasons (project is dead and outdated with only very recent intentions to continue the development by original author), it can be used to run WSGI applications on Apache via wrappers. Why should you consider using it? You might want to program and extend Apache using Python for a specific reason. mod_wsgi (Apache) (Embedding Python) What is it? Being a WSGI compliant module, mod_wsgi allows you to run Python WSGI applications on Apache HTTP Server. It achieves this in two ways: the first being similar to how mod_python works, by embedding the code and executing it within the child process. The other method offers a daemon based operation mode whereby the WSGI application has its own distinct process, managed automatically by mod_wsgi. Why should you consider using it?
|
Attachments
There are no attachments for this article.
|
Common Python Tools: Using virtualenv, Installing with Pip, and Managing
Viewed 2141 times since Sat, Jan 4, 2014
How To Set Up Python 2.7.6 and 3.3.3 on CentOS 6.4
Viewed 7437 times since Sat, Jan 4, 2014
How To Create Nagios Plugins With Python On CentOS 6
Viewed 3628 times since Sat, Jan 4, 2014
Docker Explained: How To Containerize Python Web Applications
Viewed 4614 times since Sat, Jan 4, 2014
How To Use the Web2py Framework to Quickly Build Your Python App
Viewed 4578 times since Sat, Jan 4, 2014
How To Create Nagios Plugins With Python On Ubuntu 12.10
Viewed 6704 times since Sat, Jan 4, 2014
How to Deploy Python WSGI Applications Using uWSGI Web Server with Nginx
Viewed 6773 times since Sat, Jan 4, 2014
How To Work with the ZeroMQ Messaging Library
Viewed 8194 times since Sat, Jan 4, 2014
How To Use the Pyramid Framework To Build Your Python Web App on Ubuntu
Viewed 4113 times since Sat, Jan 4, 2014
How To Setup uWSGI On Ubuntu 12.10
Viewed 2156 times since Sat, Jan 4, 2014
|