pycon logo

PyCon 2011 Atlanta

March 9th–17th

Log in or Sign Up

Python/Django deployment workshop

log in to bookmark this presentaton

Experienced / Tutorial
March 10th 9 a.m. – 12:20 p.m.
So you've written a web site... now what? Writing the application is just the beginning; now you've got to put it into production! Luckily, deploying Python web applications is pretty awesome these days, with a number of strong choices. This hands-on workshop walks through the creation of a simple deployment environment for a Django or Python WSGI application.

Abstract

Course description

So you've written a web site... now what? Writing the application is just the beginning; now you've got to put it into production! Luckily, the WSGI standard means that deploying Python web applications is pretty awesome, with a number of strong choices.

In this hands-on workshop we'll walk through the creation of a simple Python WSGI deployment environment. We'll cover a couple of options for application servers (mod_wsgi and Gunicorn), some automation technologies (Fabric), and some solutions to dealing with scaling up (nginx). By the end of the class, each student will have created a simple production environment featuring load-balanced, redundant web servers. Though fairly simple, this production environment could easily serve most small-to-medium apps.

The example application used in this class with be a Django site, and the class assumes at least basic exposure to Django. However, the tools and techniques explained apply to any WSGI-compliant Python web framework -- thats all of the popular ones and most of the others, too -- so developers using other technologies are welcome!

Format

This is a hands-on workshop. If students want to follow along, they'll need:

  • Access to at least one -- and preferably as many as four -- machines running Ubuntu 10.04. I recommend four EC2 or Rackspace Cloud servers, but a local VM or machine will also work. I'll send out information to students about creating a VM a couple weeks before the class.
  • A copy of the class-provided Django app to deploy. This'll also be sent out a couple weeks before the class. Students may bring their own Django or Python apps to deploy, but I'll only be able to provide very limited support for these apps.

Outline

  • Getting started
    • Introducing our example application.
    • Overview of where we're going.
  • Application servers
    • What's an application server?
    • What's WSGI?
    • Overview of Python WSGI servers
  • Introducing mod_wsgi
  • Configuring Apache and mod_wsgi
  • Exercise: deploy the application under mod_wsgi.
  • Exercise: initial load test.
  • Introducing gunicorn
    • Configuring gunicorn
    • Hints for running gunicorn in production
    • Exercise: deploy the application under gunicorn
    • Exercise: compare load tests
  • Database server: PostgreSQL
    • Why a separate database server?
    • Configuring PostgreSQL
    • Exercise: split out the database server.
  • Introducing Fabric
    • What's Fabric?
    • Writing fabfiles.
    • Integrating fabfiles into Django applications.
    • Exercise: deploy using Fabric
  • Load balancing and multiple web servers
    • Why multiple web servers?
    • "Shared nothing" and multiple servers
    • What's a load balancer?
    • Introducing nginx
    • Exercise: deploy nginx.
  • Final load test: how'd we do?