Download - Unbit djangoday 20120419
![Page 1: Unbit djangoday 20120419](https://reader033.vdocuments.mx/reader033/viewer/2022042814/55582248d8b42a5e468b5057/html5/thumbnails/1.jpg)
Production-grade Servers for Django
DjangoDay 2012Roberto De Ioris (Unbit)
giovedì 26 aprile 12
![Page 2: Unbit djangoday 20120419](https://reader033.vdocuments.mx/reader033/viewer/2022042814/55582248d8b42a5e468b5057/html5/thumbnails/2.jpg)
python manage.py runserver
Why not ?
giovedì 26 aprile 12
![Page 3: Unbit djangoday 20120419](https://reader033.vdocuments.mx/reader033/viewer/2022042814/55582248d8b42a5e468b5057/html5/thumbnails/3.jpg)
Availability
crash happens. always.
giovedì 26 aprile 12
![Page 4: Unbit djangoday 20120419](https://reader033.vdocuments.mx/reader033/viewer/2022042814/55582248d8b42a5e468b5057/html5/thumbnails/4.jpg)
Concurrency
there is no “premature optimization” thing in sysadmins world
giovedì 26 aprile 12
![Page 5: Unbit djangoday 20120419](https://reader033.vdocuments.mx/reader033/viewer/2022042814/55582248d8b42a5e468b5057/html5/thumbnails/5.jpg)
Users
They ignore you when things go well. They hate you when things go wrong. They want to kill you a bunch
of minutes later...
giovedì 26 aprile 12
![Page 6: Unbit djangoday 20120419](https://reader033.vdocuments.mx/reader033/viewer/2022042814/55582248d8b42a5e468b5057/html5/thumbnails/6.jpg)
Servers are a cost
...and can became the higher cost very easily
giovedì 26 aprile 12
![Page 7: Unbit djangoday 20120419](https://reader033.vdocuments.mx/reader033/viewer/2022042814/55582248d8b42a5e468b5057/html5/thumbnails/7.jpg)
The manager want to scale
...even if he does not know what it means
giovedì 26 aprile 12
![Page 8: Unbit djangoday 20120419](https://reader033.vdocuments.mx/reader033/viewer/2022042814/55582248d8b42a5e468b5057/html5/thumbnails/8.jpg)
Security
be ready for the truth
giovedì 26 aprile 12
![Page 9: Unbit djangoday 20120419](https://reader033.vdocuments.mx/reader033/viewer/2022042814/55582248d8b42a5e468b5057/html5/thumbnails/9.jpg)
WSGI
one standard to rule them all...
def application(env, start_response):
start_response(‘200 OK’, [(‘Content-Type’,‘text/html’)])
return “Hello World”
giovedì 26 aprile 12
![Page 10: Unbit djangoday 20120419](https://reader033.vdocuments.mx/reader033/viewer/2022042814/55582248d8b42a5e468b5057/html5/thumbnails/10.jpg)
Proxy servers and static contents
do not expose your app to the world. NEVERdo not serve static !les with Django. NEVER
giovedì 26 aprile 12
![Page 11: Unbit djangoday 20120419](https://reader033.vdocuments.mx/reader033/viewer/2022042814/55582248d8b42a5e468b5057/html5/thumbnails/11.jpg)
app
appwebserver
app
world
giovedì 26 aprile 12
![Page 12: Unbit djangoday 20120419](https://reader033.vdocuments.mx/reader033/viewer/2022042814/55582248d8b42a5e468b5057/html5/thumbnails/12.jpg)
Once upon a time...
Flup and mod_python
giovedì 26 aprile 12
![Page 13: Unbit djangoday 20120419](https://reader033.vdocuments.mx/reader033/viewer/2022042814/55582248d8b42a5e468b5057/html5/thumbnails/13.jpg)
Flup
FastCGI, SCGI, AJPpure python, preforking-multithread
giovedì 26 aprile 12
![Page 14: Unbit djangoday 20120419](https://reader033.vdocuments.mx/reader033/viewer/2022042814/55582248d8b42a5e468b5057/html5/thumbnails/14.jpg)
mod_python
was a bad idea ?
giovedì 26 aprile 12
![Page 15: Unbit djangoday 20120419](https://reader033.vdocuments.mx/reader033/viewer/2022042814/55582248d8b42a5e468b5057/html5/thumbnails/15.jpg)
The new generation
mod_wsgigunicorn
uWSGI
giovedì 26 aprile 12
![Page 16: Unbit djangoday 20120419](https://reader033.vdocuments.mx/reader033/viewer/2022042814/55582248d8b42a5e468b5057/html5/thumbnails/16.jpg)
mod_wsgiapache module (in C)
2 modes: embedded and daemon
preforking and multithread
mature
solid
Windows support
giovedì 26 aprile 12
![Page 17: Unbit djangoday 20120419](https://reader033.vdocuments.mx/reader033/viewer/2022042814/55582248d8b42a5e468b5057/html5/thumbnails/17.jpg)
# mod_wsgi config
WSGIScriptAlias / /path/to/mysite.com/mysite/wsgi.pyWSGIPythonPath /path/to/mysite.com
WSGIDaemonProcess pippo processes=2 threads=15
<Directory /path/to/mysite.com/mysite> <Files wsgi.py> Order deny,allow Allow from all </Files></Directory>
giovedì 26 aprile 12
![Page 18: Unbit djangoday 20120419](https://reader033.vdocuments.mx/reader033/viewer/2022042814/55582248d8b42a5e468b5057/html5/thumbnails/18.jpg)
gunicorn
pure python
do one thing do it well
preforking (+async extensions)
speaks http
easy (maybe the easiest tool ever written)
giovedì 26 aprile 12
![Page 19: Unbit djangoday 20120419](https://reader033.vdocuments.mx/reader033/viewer/2022042814/55582248d8b42a5e468b5057/html5/thumbnails/19.jpg)
PYTHONPATH=/var/www gunicorn --workers 2 --bind 127.0.0.1:8000 pippo.wsgi:application
# or add gunicorn to INSTALLED_APPS# it will bind to port 8000
python manage.py run_gunicorn
giovedì 26 aprile 12
![Page 20: Unbit djangoday 20120419](https://reader033.vdocuments.mx/reader033/viewer/2022042814/55582248d8b42a5e468b5057/html5/thumbnails/20.jpg)
uWSGIpure C
preforking + multithread + async + plugins + blah blah
feature rich (a blast beat of options)
speaks uwsgi,FastCGI,Mongrel2-zeromq,HTTP and maybe Klingon
fat-beardy-braces_equipped sysadmin friendly
high learning curve
made only for making money
Mr Wolf would wear a uWSGI t-shirt
giovedì 26 aprile 12
![Page 21: Unbit djangoday 20120419](https://reader033.vdocuments.mx/reader033/viewer/2022042814/55582248d8b42a5e468b5057/html5/thumbnails/21.jpg)
uwsgi --http-socket 127.0.0.1:8000 --wsgi-!le /var/ww/pippo/wsgi.py --processes 2 --threads 15
# or
[uwsgi]http-socket = 128.0.0.1:8000wsgi-!le = /var/ww/pippo/wsgi.pyprocesses = 2threads = 15
# or
<uwsgi> <http-socket> 128.0.0.1:8000</http-socket> <wsgi-!le> /var/ww/pippo/wsgi.py</wsgi-!le> <processes>2</processes> <threads>15</threads></uwsgi>
#or .....
giovedì 26 aprile 12
![Page 22: Unbit djangoday 20120419](https://reader033.vdocuments.mx/reader033/viewer/2022042814/55582248d8b42a5e468b5057/html5/thumbnails/22.jpg)
before you ask...
speed is not a problem
giovedì 26 aprile 12
![Page 23: Unbit djangoday 20120419](https://reader033.vdocuments.mx/reader033/viewer/2022042814/55582248d8b42a5e468b5057/html5/thumbnails/23.jpg)
Which One?
no easy answers...but...
giovedì 26 aprile 12
![Page 24: Unbit djangoday 20120419](https://reader033.vdocuments.mx/reader033/viewer/2022042814/55582248d8b42a5e468b5057/html5/thumbnails/24.jpg)
DO NOT LOOK AT BENCHMARKS
...otherwise you will directly go with uWSGI...
giovedì 26 aprile 12
![Page 25: Unbit djangoday 20120419](https://reader033.vdocuments.mx/reader033/viewer/2022042814/55582248d8b42a5e468b5057/html5/thumbnails/25.jpg)
Newbie ?
gunicorn is the easiest choice
giovedì 26 aprile 12
![Page 26: Unbit djangoday 20120419](https://reader033.vdocuments.mx/reader033/viewer/2022042814/55582248d8b42a5e468b5057/html5/thumbnails/26.jpg)
need full apache integration ?
mod_wsgi FTW
giovedì 26 aprile 12
![Page 27: Unbit djangoday 20120419](https://reader033.vdocuments.mx/reader033/viewer/2022042814/55582248d8b42a5e468b5057/html5/thumbnails/27.jpg)
want a full stack ?
uWSGI has no competitors
giovedì 26 aprile 12
![Page 28: Unbit djangoday 20120419](https://reader033.vdocuments.mx/reader033/viewer/2022042814/55582248d8b42a5e468b5057/html5/thumbnails/28.jpg)
on the cloud ?
gunicorn and uWSGI all over the place
giovedì 26 aprile 12
![Page 29: Unbit djangoday 20120419](https://reader033.vdocuments.mx/reader033/viewer/2022042814/55582248d8b42a5e468b5057/html5/thumbnails/29.jpg)
still confused ?
gunicornuWSGI
mod_wsgi
giovedì 26 aprile 12
![Page 30: Unbit djangoday 20120419](https://reader033.vdocuments.mx/reader033/viewer/2022042814/55582248d8b42a5e468b5057/html5/thumbnails/30.jpg)
other choices ?
a lot...
Tornado
Passenger
fapws3
...
giovedì 26 aprile 12
![Page 31: Unbit djangoday 20120419](https://reader033.vdocuments.mx/reader033/viewer/2022042814/55582248d8b42a5e468b5057/html5/thumbnails/31.jpg)
Questions ?
giovedì 26 aprile 12