How to DeploY
WSGI APP


Kamil Gałuszka by S4F Team

Katowice 09.01.2014

WHAT IS WSGI Anyway?


  • PEP333
  • Python Web Server Gateway Interface (WSGI) 
  • It was designed in 2003.
  • The problem was many Python interfaces to different web servers
  • Different frameworks could or couldn't work on some web servers
def simple_app(environ, start_response):
    """Simplest possible application object"""
    status = '200 OK'
    response_headers = [('Content-type', 'text/plain')]
    start_response(status, response_headers)
    return ['Hello world!\n']

MOD_WSGI

  • Built for Apache 2 but also works with old good Apache 1.3
  • Two modes
  • Embedded mode 
  • Bigger overhead by Apache process (mostly by serving statics)
  • Deamon mode
  • It's technically faster
  • It is 

Mod_python


  • It was actively developed until 2007
  • First was build only to make python interface for Apache. It wasn't build from ground with web development in mind.
  • Project has be come back in 2013 with maintainer.
  • It gains WSGI support.
  • I didn't tried it yet cause I'm not using Apache now ;)
  • I think now most community of mod_python is dead beyond core developer of mod_python. It will take some time when it will be back. 

Gunicorn

  • Natively supports WSGI, Django, and Paster
  • Automatic worker process management
  • Pluggable backends
    • gevent
    • eventlet
    • tornado
    • sync
  • Very configurable

Gunicorn vs MOD_WSGI

Blitz configured -p 1-250:60 -T 5000

Apache + mod_wsgi137 hits, 1,039 timeouts, 25 errors
Average hit rate of 2 31/request per second 
The first error happened at 17.59 seconds into the test when the number of concurrent users was at 74

Gunicorn + gevent2,029 hits, 154 timeouts, 154 errors
The average hit rate of 31/request per second 
The first timeout happened at 45.20 seconds into the test when the number of concurrent users was at 189

Problem

  • Detect flapping
  • Managing sockets and process
  • See stdout and stderr in realtime
  • webconsole
  • supervisord has only xml-rpc access
  • there is bunch of process that you want supervise
  1.  

Thanks to...
Tarek Ziadé and Mozilla


Classical Python stack


Circus - stack



Chaussette - 

may your socks  don't suck!! 



So maybe example?

[circus]
statsd = 1
httpd = 1

[socket:web]
host = 127.0.0.1 port = 9999
[watcher:webapp] cmd = bin/chaussette --fd $(circus.sockets.web) django.wsgi.application numprocesses = 3 use_sockets = True
[watcher:celery_app] working_dir = /home/ubuntu/app cmd = /usr/bin/python args = manage.py celery worker stdout_stream.class = StdoutStream stderr_stream.class = StdoutStream [env:webapp] PYTHONPATH = /home/ubuntu/app

DEMO Time


Do you love hackathons?


Thanks for Your Time


How to deploy WSGI app

By Kamil Gałuszka

How to deploy WSGI app

  • 1,772
Loading comments...

More from Kamil Gałuszka