SlideShare ist ein Scribd-Unternehmen logo
1 von 31
Downloaden Sie, um offline zu lesen
Production-grade Servers for
                                 Django
                                 DjangoDay 2012
                              Roberto De Ioris (Unbit)




giovedì 26 aprile 12
python manage.py runserver
                                 Why not ?




giovedì 26 aprile 12
Availability
                       crash happens. always.




giovedì 26 aprile 12
Concurrency
                       there is no “premature optimization” thing in
                                      sysadmins world




giovedì 26 aprile 12
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
Servers are a cost
                       ...and can became the higher cost very easily




giovedì 26 aprile 12
The manager want to scale
                        ...even if he does not know what it means




giovedì 26 aprile 12
Security
                       be ready for the truth




giovedì 26 aprile 12
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
Proxy servers and static
                               contents
                       do not expose your app to the world. NEVER
                       do not serve static files with Django. NEVER




giovedì 26 aprile 12
app


         world
                       webserver   app



                                   app


giovedì 26 aprile 12
Once upon a time...
                          Flup and mod_python




giovedì 26 aprile 12
Flup
                                FastCGI, SCGI, AJP
                       pure python, preforking-multithread




giovedì 26 aprile 12
mod_python
                        was a bad idea ?




giovedì 26 aprile 12
The new generation

                             mod_wsgi
                             gunicorn
                              uWSGI




giovedì 26 aprile 12
mod_wsgi
                            apache module (in C)

                       2 modes: embedded and daemon

                         preforking and multithread

                                  mature

                                   solid

                             Windows support
giovedì 26 aprile 12
# mod_wsgi config

                 WSGIScriptAlias / /path/to/mysite.com/mysite/wsgi.py
                 WSGIPythonPath /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
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
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
uWSGI
                                                   pure 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
uwsgi --http-socket 127.0.0.1:8000 --wsgi-file /var/ww/pippo/wsgi.py --processes 2 --threads 15

    # or

    [uwsgi]
    http-socket = 128.0.0.1:8000
    wsgi-file = /var/ww/pippo/wsgi.py
    processes = 2
    threads = 15

    # or

    <uwsgi>
     <http-socket> 128.0.0.1:8000</http-socket>
     <wsgi-file> /var/ww/pippo/wsgi.py</wsgi-file>
     <processes>2</processes>
     <threads>15</threads>
    </uwsgi>

    #or .....




giovedì 26 aprile 12
before you ask...
                        speed is not a problem




giovedì 26 aprile 12
Which One?
                       no easy answers...but...




giovedì 26 aprile 12
DO NOT LOOK AT BENCHMARKS
                       ...otherwise you will directly go with uWSGI...




giovedì 26 aprile 12
Newbie ?
                       gunicorn is the easiest choice




giovedì 26 aprile 12
need full apache integration ?
                                 mod_wsgi FTW




giovedì 26 aprile 12
want a full stack ?
                        uWSGI has no competitors




giovedì 26 aprile 12
on the cloud ?
                       gunicorn and uWSGI all over the place




giovedì 26 aprile 12
still confused ?




          gunicorn
                                          uWSGI

                          mod_wsgi
giovedì 26 aprile 12
other choices ?
                             a lot...

                            Tornado

                            Passenger

                             fapws3

                               ...

giovedì 26 aprile 12
Questions ?




giovedì 26 aprile 12

Weitere ähnliche Inhalte

Andere mochten auch

Django - The Web framework for perfectionists with deadlines
Django - The Web framework for perfectionists with deadlinesDjango - The Web framework for perfectionists with deadlines
Django - The Web framework for perfectionists with deadlinesMarkus Zapke-Gründemann
 
2016 py con2016_lightingtalk_php to python
2016 py con2016_lightingtalk_php to python2016 py con2016_lightingtalk_php to python
2016 py con2016_lightingtalk_php to pythonJiho Lee
 
2007 - 应用系统脆弱性概论
2007 - 应用系统脆弱性概论 2007 - 应用系统脆弱性概论
2007 - 应用系统脆弱性概论 Na Lee
 
라이트닝 토크 2015 파이콘
라이트닝 토크 2015 파이콘라이트닝 토크 2015 파이콘
라이트닝 토크 2015 파이콘Jiho Lee
 
Overview of Testing Talks at Pycon
Overview of Testing Talks at PyconOverview of Testing Talks at Pycon
Overview of Testing Talks at PyconJacqueline Kazil
 
NoSql Day - Chiusura
NoSql Day - ChiusuraNoSql Day - Chiusura
NoSql Day - ChiusuraWEBdeBS
 
Authentication & Authorization in ASPdotNet MVC
Authentication & Authorization in ASPdotNet MVCAuthentication & Authorization in ASPdotNet MVC
Authentication & Authorization in ASPdotNet MVCMindfire Solutions
 
Django mongodb -djangoday_
Django mongodb -djangoday_Django mongodb -djangoday_
Django mongodb -djangoday_WEBdeBS
 
Django e il Rap Elia Contini
Django e il Rap Elia ContiniDjango e il Rap Elia Contini
Django e il Rap Elia ContiniWEBdeBS
 
Django - The Web framework for perfectionists with deadlines
Django - The Web framework  for perfectionists with deadlinesDjango - The Web framework  for perfectionists with deadlines
Django - The Web framework for perfectionists with deadlinesMarkus Zapke-Gründemann
 
NoSql Day - Apertura
NoSql Day - AperturaNoSql Day - Apertura
NoSql Day - AperturaWEBdeBS
 

Andere mochten auch (16)

Django - The Web framework for perfectionists with deadlines
Django - The Web framework for perfectionists with deadlinesDjango - The Web framework for perfectionists with deadlines
Django - The Web framework for perfectionists with deadlines
 
Digesting jQuery
Digesting jQueryDigesting jQuery
Digesting jQuery
 
2016 py con2016_lightingtalk_php to python
2016 py con2016_lightingtalk_php to python2016 py con2016_lightingtalk_php to python
2016 py con2016_lightingtalk_php to python
 
Html5 History-API
Html5 History-APIHtml5 History-API
Html5 History-API
 
2007 - 应用系统脆弱性概论
2007 - 应用系统脆弱性概论 2007 - 应用系统脆弱性概论
2007 - 应用系统脆弱性概论
 
Website optimization
Website optimizationWebsite optimization
Website optimization
 
라이트닝 토크 2015 파이콘
라이트닝 토크 2015 파이콘라이트닝 토크 2015 파이콘
라이트닝 토크 2015 파이콘
 
Overview of Testing Talks at Pycon
Overview of Testing Talks at PyconOverview of Testing Talks at Pycon
Overview of Testing Talks at Pycon
 
NoSql Day - Chiusura
NoSql Day - ChiusuraNoSql Day - Chiusura
NoSql Day - Chiusura
 
Authentication & Authorization in ASPdotNet MVC
Authentication & Authorization in ASPdotNet MVCAuthentication & Authorization in ASPdotNet MVC
Authentication & Authorization in ASPdotNet MVC
 
EuroDjangoCon 2009 - Ein Rückblick
EuroDjangoCon 2009 - Ein RückblickEuroDjangoCon 2009 - Ein Rückblick
EuroDjangoCon 2009 - Ein Rückblick
 
Django mongodb -djangoday_
Django mongodb -djangoday_Django mongodb -djangoday_
Django mongodb -djangoday_
 
Django e il Rap Elia Contini
Django e il Rap Elia ContiniDjango e il Rap Elia Contini
Django e il Rap Elia Contini
 
Django - The Web framework for perfectionists with deadlines
Django - The Web framework  for perfectionists with deadlinesDjango - The Web framework  for perfectionists with deadlines
Django - The Web framework for perfectionists with deadlines
 
NoSql Day - Apertura
NoSql Day - AperturaNoSql Day - Apertura
NoSql Day - Apertura
 
2 × 3 = 6
2 × 3 = 62 × 3 = 6
2 × 3 = 6
 

Mehr von WEBdeBS

Legal Pirlo
Legal PirloLegal Pirlo
Legal PirloWEBdeBS
 
Nodejsconf 2012
Nodejsconf 2012Nodejsconf 2012
Nodejsconf 2012WEBdeBS
 
Mockup, wireframe e visual: una breve introduzione
Mockup, wireframe e visual: una breve introduzioneMockup, wireframe e visual: una breve introduzione
Mockup, wireframe e visual: una breve introduzioneWEBdeBS
 
Virtualenv
VirtualenvVirtualenv
VirtualenvWEBdeBS
 
Iga workflow
Iga workflowIga workflow
Iga workflowWEBdeBS
 
PepperTweet - Project presentation Startup Weekend Brescia
PepperTweet - Project presentation Startup Weekend BresciaPepperTweet - Project presentation Startup Weekend Brescia
PepperTweet - Project presentation Startup Weekend BresciaWEBdeBS
 
Peppertweet - Presentazione Startup Weekend Brescia
Peppertweet - Presentazione Startup Weekend BresciaPeppertweet - Presentazione Startup Weekend Brescia
Peppertweet - Presentazione Startup Weekend BresciaWEBdeBS
 

Mehr von WEBdeBS (9)

Legal Pirlo
Legal PirloLegal Pirlo
Legal Pirlo
 
Nodejsconf 2012
Nodejsconf 2012Nodejsconf 2012
Nodejsconf 2012
 
Mockup, wireframe e visual: una breve introduzione
Mockup, wireframe e visual: una breve introduzioneMockup, wireframe e visual: una breve introduzione
Mockup, wireframe e visual: una breve introduzione
 
Geodjango
GeodjangoGeodjango
Geodjango
 
Virtualenv
VirtualenvVirtualenv
Virtualenv
 
Fagungis
FagungisFagungis
Fagungis
 
Iga workflow
Iga workflowIga workflow
Iga workflow
 
PepperTweet - Project presentation Startup Weekend Brescia
PepperTweet - Project presentation Startup Weekend BresciaPepperTweet - Project presentation Startup Weekend Brescia
PepperTweet - Project presentation Startup Weekend Brescia
 
Peppertweet - Presentazione Startup Weekend Brescia
Peppertweet - Presentazione Startup Weekend BresciaPeppertweet - Presentazione Startup Weekend Brescia
Peppertweet - Presentazione Startup Weekend Brescia
 

Unbit djangoday 20120419

  • 1. Production-grade Servers for Django DjangoDay 2012 Roberto De Ioris (Unbit) giovedì 26 aprile 12
  • 2. python manage.py runserver Why not ? giovedì 26 aprile 12
  • 3. Availability crash happens. always. giovedì 26 aprile 12
  • 4. Concurrency there is no “premature optimization” thing in sysadmins world giovedì 26 aprile 12
  • 5. 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
  • 6. Servers are a cost ...and can became the higher cost very easily giovedì 26 aprile 12
  • 7. The manager want to scale ...even if he does not know what it means giovedì 26 aprile 12
  • 8. Security be ready for the truth giovedì 26 aprile 12
  • 9. 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
  • 10. Proxy servers and static contents do not expose your app to the world. NEVER do not serve static files with Django. NEVER giovedì 26 aprile 12
  • 11. app world webserver app app giovedì 26 aprile 12
  • 12. Once upon a time... Flup and mod_python giovedì 26 aprile 12
  • 13. Flup FastCGI, SCGI, AJP pure python, preforking-multithread giovedì 26 aprile 12
  • 14. mod_python was a bad idea ? giovedì 26 aprile 12
  • 15. The new generation mod_wsgi gunicorn uWSGI giovedì 26 aprile 12
  • 16. mod_wsgi apache module (in C) 2 modes: embedded and daemon preforking and multithread mature solid Windows support giovedì 26 aprile 12
  • 17. # mod_wsgi config WSGIScriptAlias / /path/to/mysite.com/mysite/wsgi.py WSGIPythonPath /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
  • 18. 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
  • 19. 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
  • 20. uWSGI pure 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
  • 21. uwsgi --http-socket 127.0.0.1:8000 --wsgi-file /var/ww/pippo/wsgi.py --processes 2 --threads 15 # or [uwsgi] http-socket = 128.0.0.1:8000 wsgi-file = /var/ww/pippo/wsgi.py processes = 2 threads = 15 # or <uwsgi> <http-socket> 128.0.0.1:8000</http-socket> <wsgi-file> /var/ww/pippo/wsgi.py</wsgi-file> <processes>2</processes> <threads>15</threads> </uwsgi> #or ..... giovedì 26 aprile 12
  • 22. before you ask... speed is not a problem giovedì 26 aprile 12
  • 23. Which One? no easy answers...but... giovedì 26 aprile 12
  • 24. DO NOT LOOK AT BENCHMARKS ...otherwise you will directly go with uWSGI... giovedì 26 aprile 12
  • 25. Newbie ? gunicorn is the easiest choice giovedì 26 aprile 12
  • 26. need full apache integration ? mod_wsgi FTW giovedì 26 aprile 12
  • 27. want a full stack ? uWSGI has no competitors giovedì 26 aprile 12
  • 28. on the cloud ? gunicorn and uWSGI all over the place giovedì 26 aprile 12
  • 29. still confused ? gunicorn uWSGI mod_wsgi giovedì 26 aprile 12
  • 30. other choices ? a lot... Tornado Passenger fapws3 ... giovedì 26 aprile 12