SlideShare a Scribd company logo
HOSTING PYTHON WEB
   APPLICATIONS
     Graham Dumpleton
        PyCon Australia
         Sydney 2011
WEB APPLICATIONS
WEB FRAMEWORKS
FRAMEWORK SERVERS

• BaseHttpServer.HttpServer     (Django, Werkzeug, Flask)

• wsgiref.simple_server   (Bottle)

• paste.httpserver   (Pylons, Pyramid, TurboGears)

• Rocket   (Web2Py)

• cherrypy.wsgiserver   (CherryPy, web.py)
DEVELOPMENT ONLY



• BaseHttpServer.HttpServer     (Django, Werkzeug, Flask)

• wsgiref.simple_server   (Bottle)
SHORT COMINGS

• Non    existent or inadequate concurrency support.

• SSL   support non existent or not of production quality.

• Lack   of good logging support.

• Inadequate    process management.

• No    direct static file serving ability.
PRODUCTION GRADE?


• paste.httpserver   (Pylons, Pyramid, TurboGears)

• Rocket   (Web2Py)

• cherrypy.wsgiserver   (CherryPy, web.py)
GETTING BETTER

• Don’t     provide a full process management solution.

• Still   usually require supervisord/monit to manage them.

• No      direct static file serving ability.

• Still   use Apache/nginx/lighttpd/Cherokee for static files.

• Usually     recommended they sit behind traditional server.
INDEPENDENT SERVERS

• gunicorn       • gevent

• meinheld       • eventlet

• fapws          • tornado

• bjoern         • twisted

• diesel         • pants
MIXED BAG

• The     gunicorn server best of this crowd.

• Still   usually require supervisord/monit to manage it.

• No      direct static file serving ability.

• Still   use Apache/nginx/lighttpd/Cherokee for static files.

• Usually     recommended they sit behind traditional server.
FRONT END WEB PROXY

    Web Browser                                             File System
                                                           (Static Files)
                  HTTP



    Web Browser   HTTP   Front End Web Server

                                                HTTP

                  HTTP                                 Back End Web Server


    Web Browser
PERFORMANCE BENEFITS


• Static   file handling speed far superior.

• Can   implement caching in the front end web server.

• Isolates   dynamic web application from slow clients.

• Removes     need for application server to handle keep alive.
GOOD OPTIONS


• nginx

• Cherokee

• lighttpd

• Apache
ALTERNATIVES TO HTTP

    Web Browser                                               File System
                                                             (Static Files)
                  HTTP



    Web Browser   HTTP   Front End Web Server

                                                FASTCGI
                                                              Back End
                  HTTP                                    Application Server

    Web Browser
GOOD POINTS

• Language    agnostic, can support more than Python.

• Web     server may optionally be able to handle processes.

• If   so, no longer need to use supervisord/monit.

• Run    as distinct user rather than web server user.

• Request    timeouts and controls on rampant processes.
BAD POINTS


• Different   languages don’t have same resource requirements.

• Generally   configured for PHP, which sucks for Python.

• Deployment     for Python is more complicated than necessary.
RECENT ALTERNATIVES


• uWSGI

• Phusion   Passenger

• Mongrel
HOSTING ADOPTION

• FASTCGI     solutions still the incumbent with web hosting.

• Phusion   Passenger used because of Ruby popularity.

• uWSGI     slowly making headway with multi language support.

• Can’t   see the existing PHP hosting world changing at all.

• Better   solutions will only come with new hosting providers.
ELEPHANT IN THE ROOM


• Apache    is still the most popular web server in use.

• System   administrators more likely to know Apache.

• Apache    is more a platform than just a web server.

• Support   for Python in form of mod_python and mod_wsgi.
MOD_PYTHON

• Runs     Python embedded in Apache child worker processes.

• Officially    declared dead by Apache Software Foundation.

• No      longer supported and no new releases.

• Will    not be ported to Python 3.0+.

• Still   suffers memory leaks.

• Bugs     if you deviate off the path.
MOD_WSGI

• Intended    to be a better mod_python.

• Focus   on providing a WSGI compatible API.

• Limited    abilities for Apache authnz providers.

• Good    robust general purpose solution.

• Multiple   modes of operation.
EMBEDDED MODE

 Web Browser                               File System
                                          (Static Files)
               HTTP



 Web Browser   HTTP   Apache Web Server



               HTTP         Python
                         Interpreters
 Web Browser
DAEMON MODE

Web Browser                                File System
                                          (Static Files)
              HTTP



Web Browser   HTTP   Apache Web Server
                                         Daemon Mode
                                           Processes
              HTTP                        -----------------
                                             Python
                                          Interpreters
Web Browser
FRONT END + DAEMON
                                    File
   Web Browser                    System
                                  (Static
                                   Files)
                 HTTP

                         Front
   Web Browser   HTTP   End Web
                         Server
                                   Back     Daemon Mode
                                   End        Processes
                 HTTP
                                  Apache     -----------------
                                   Web          Python
                                  Server     Interpreters
   Web Browser
FRONT END + EMBEDDED
                                     File
    Web Browser                    System
                                   (Static
                                    Files)
                  HTTP

                          Front
    Web Browser   HTTP   End Web
                          Server
                                                   Back End
                                             Apache Web Server
                  HTTP
                                               ---------------------
                                                    Python
                                                 Interpreters
    Web Browser
SO MANY OPTIONS

• HTTP  proxy to gunicorn,      • Apache/mod_wsgi
 paste server, CherryPy          embedded mode.
 WSGI server.
                                • Apache/mod_wsgi   daemon
• FASTCGI/SCGI/AJP               mode.

• uWSGI, Phusion   Passenger,   • HTTP
                                     proxy to Apache/
 Mongrel                         mod_wsgi.
WHAT SHOULD YOU USE?

• The    hosting mechanism is usually never the bottleneck.

• Don’t   believe hello world benchmarks.

• Don’t   believe what people tell you on IRC channels.

• Use    what you have the skills to setup and configure.

• Use    what you find has the qualities you need.

• Test   the configuration you choose with real applications.
MOST POPULAR


• Apache/mod_wsgi     (daemon mode).

• nginx   HTTP proxy to Apache/mod_wsgi.

• nginx   HTTP proxy to gunicorn.

• nginx   to uWSGI.
DON’T WASTE YOUR TIME

• Concentrate   on removing bottlenecks.

• Look   at improving your database performance.

• Look   at implementing/improving page/data caching.

• Look   at improving browser page rendering times.

• Look   at monitoring tools such as New Relic and Munin.

• The   hosting mechanism is only a small part of the problem.
QUESTIONS?

More Related Content

More from Graham Dumpleton

OpenShift, Docker, Kubernetes: The next generation of PaaS
OpenShift, Docker, Kubernetes: The next generation of PaaSOpenShift, Docker, Kubernetes: The next generation of PaaS
OpenShift, Docker, Kubernetes: The next generation of PaaS
Graham Dumpleton
 
Automated Image Builds in OpenShift and Kubernetes
Automated Image Builds in OpenShift and KubernetesAutomated Image Builds in OpenShift and Kubernetes
Automated Image Builds in OpenShift and Kubernetes
Graham Dumpleton
 
PyCon HK 2015 - Monitoring the performance of python web applications
PyCon HK 2015 -  Monitoring the performance of python web applicationsPyCon HK 2015 -  Monitoring the performance of python web applications
PyCon HK 2015 - Monitoring the performance of python web applications
Graham Dumpleton
 
PyCon AU 2015 - Using benchmarks to understand how wsgi servers work
PyCon AU 2015  - Using benchmarks to understand how wsgi servers workPyCon AU 2015  - Using benchmarks to understand how wsgi servers work
PyCon AU 2015 - Using benchmarks to understand how wsgi servers work
Graham Dumpleton
 
PyCon NZ 2013 - Advanced Methods For Creating Decorators
PyCon NZ 2013 - Advanced Methods For Creating DecoratorsPyCon NZ 2013 - Advanced Methods For Creating Decorators
PyCon NZ 2013 - Advanced Methods For Creating Decorators
Graham Dumpleton
 
PyCon US 2013 Making Apache suck less for hosting Python web applications
PyCon US 2013 Making Apache suck less for hosting Python web applicationsPyCon US 2013 Making Apache suck less for hosting Python web applications
PyCon US 2013 Making Apache suck less for hosting Python web applications
Graham Dumpleton
 
PyCon AU 2010 - Getting Started With Apache/mod_wsgi.
PyCon AU 2010 - Getting Started With Apache/mod_wsgi.PyCon AU 2010 - Getting Started With Apache/mod_wsgi.
PyCon AU 2010 - Getting Started With Apache/mod_wsgi.
Graham Dumpleton
 
PyCon US 2012 - State of WSGI 2
PyCon US 2012 - State of WSGI 2PyCon US 2012 - State of WSGI 2
PyCon US 2012 - State of WSGI 2
Graham Dumpleton
 
PyCon AU 2012 - Debugging Live Python Web Applications
PyCon AU 2012 - Debugging Live Python Web ApplicationsPyCon AU 2012 - Debugging Live Python Web Applications
PyCon AU 2012 - Debugging Live Python Web Applications
Graham Dumpleton
 
PyCon US 2012 - Web Server Bottlenecks and Performance Tuning
PyCon US 2012 - Web Server Bottlenecks and Performance TuningPyCon US 2012 - Web Server Bottlenecks and Performance Tuning
PyCon US 2012 - Web Server Bottlenecks and Performance Tuning
Graham Dumpleton
 
DjangoCon US 2011 - Monkeying around at New Relic
DjangoCon US 2011 - Monkeying around at New RelicDjangoCon US 2011 - Monkeying around at New Relic
DjangoCon US 2011 - Monkeying around at New Relic
Graham Dumpleton
 

More from Graham Dumpleton (11)

OpenShift, Docker, Kubernetes: The next generation of PaaS
OpenShift, Docker, Kubernetes: The next generation of PaaSOpenShift, Docker, Kubernetes: The next generation of PaaS
OpenShift, Docker, Kubernetes: The next generation of PaaS
 
Automated Image Builds in OpenShift and Kubernetes
Automated Image Builds in OpenShift and KubernetesAutomated Image Builds in OpenShift and Kubernetes
Automated Image Builds in OpenShift and Kubernetes
 
PyCon HK 2015 - Monitoring the performance of python web applications
PyCon HK 2015 -  Monitoring the performance of python web applicationsPyCon HK 2015 -  Monitoring the performance of python web applications
PyCon HK 2015 - Monitoring the performance of python web applications
 
PyCon AU 2015 - Using benchmarks to understand how wsgi servers work
PyCon AU 2015  - Using benchmarks to understand how wsgi servers workPyCon AU 2015  - Using benchmarks to understand how wsgi servers work
PyCon AU 2015 - Using benchmarks to understand how wsgi servers work
 
PyCon NZ 2013 - Advanced Methods For Creating Decorators
PyCon NZ 2013 - Advanced Methods For Creating DecoratorsPyCon NZ 2013 - Advanced Methods For Creating Decorators
PyCon NZ 2013 - Advanced Methods For Creating Decorators
 
PyCon US 2013 Making Apache suck less for hosting Python web applications
PyCon US 2013 Making Apache suck less for hosting Python web applicationsPyCon US 2013 Making Apache suck less for hosting Python web applications
PyCon US 2013 Making Apache suck less for hosting Python web applications
 
PyCon AU 2010 - Getting Started With Apache/mod_wsgi.
PyCon AU 2010 - Getting Started With Apache/mod_wsgi.PyCon AU 2010 - Getting Started With Apache/mod_wsgi.
PyCon AU 2010 - Getting Started With Apache/mod_wsgi.
 
PyCon US 2012 - State of WSGI 2
PyCon US 2012 - State of WSGI 2PyCon US 2012 - State of WSGI 2
PyCon US 2012 - State of WSGI 2
 
PyCon AU 2012 - Debugging Live Python Web Applications
PyCon AU 2012 - Debugging Live Python Web ApplicationsPyCon AU 2012 - Debugging Live Python Web Applications
PyCon AU 2012 - Debugging Live Python Web Applications
 
PyCon US 2012 - Web Server Bottlenecks and Performance Tuning
PyCon US 2012 - Web Server Bottlenecks and Performance TuningPyCon US 2012 - Web Server Bottlenecks and Performance Tuning
PyCon US 2012 - Web Server Bottlenecks and Performance Tuning
 
DjangoCon US 2011 - Monkeying around at New Relic
DjangoCon US 2011 - Monkeying around at New RelicDjangoCon US 2011 - Monkeying around at New Relic
DjangoCon US 2011 - Monkeying around at New Relic
 

Recently uploaded

leewayhertz.com-AI in predictive maintenance Use cases technologies benefits ...
leewayhertz.com-AI in predictive maintenance Use cases technologies benefits ...leewayhertz.com-AI in predictive maintenance Use cases technologies benefits ...
leewayhertz.com-AI in predictive maintenance Use cases technologies benefits ...
alexjohnson7307
 
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-EfficiencyFreshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
ScyllaDB
 
Building Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and MilvusBuilding Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and Milvus
Zilliz
 
Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)
Jakub Marek
 
GraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracyGraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracy
Tomaz Bratanic
 
Public CyberSecurity Awareness Presentation 2024.pptx
Public CyberSecurity Awareness Presentation 2024.pptxPublic CyberSecurity Awareness Presentation 2024.pptx
Public CyberSecurity Awareness Presentation 2024.pptx
marufrahmanstratejm
 
Fueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte WebinarFueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte Webinar
Zilliz
 
Introduction of Cybersecurity with OSS at Code Europe 2024
Introduction of Cybersecurity with OSS  at Code Europe 2024Introduction of Cybersecurity with OSS  at Code Europe 2024
Introduction of Cybersecurity with OSS at Code Europe 2024
Hiroshi SHIBATA
 
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAUHCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
panagenda
 
Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024
Jason Packer
 
Nordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptxNordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptx
MichaelKnudsen27
 
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
saastr
 
Digital Banking in the Cloud: How Citizens Bank Unlocked Their Mainframe
Digital Banking in the Cloud: How Citizens Bank Unlocked Their MainframeDigital Banking in the Cloud: How Citizens Bank Unlocked Their Mainframe
Digital Banking in the Cloud: How Citizens Bank Unlocked Their Mainframe
Precisely
 
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdfHow to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
Chart Kalyan
 
“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...
“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...
“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...
Edge AI and Vision Alliance
 
JavaLand 2024: Application Development Green Masterplan
JavaLand 2024: Application Development Green MasterplanJavaLand 2024: Application Development Green Masterplan
JavaLand 2024: Application Development Green Masterplan
Miro Wengner
 
Trusted Execution Environment for Decentralized Process Mining
Trusted Execution Environment for Decentralized Process MiningTrusted Execution Environment for Decentralized Process Mining
Trusted Execution Environment for Decentralized Process Mining
LucaBarbaro3
 
Dandelion Hashtable: beyond billion requests per second on a commodity server
Dandelion Hashtable: beyond billion requests per second on a commodity serverDandelion Hashtable: beyond billion requests per second on a commodity server
Dandelion Hashtable: beyond billion requests per second on a commodity server
Antonios Katsarakis
 
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdfMonitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Tosin Akinosho
 
FREE A4 Cyber Security Awareness Posters-Social Engineering part 3
FREE A4 Cyber Security Awareness  Posters-Social Engineering part 3FREE A4 Cyber Security Awareness  Posters-Social Engineering part 3
FREE A4 Cyber Security Awareness Posters-Social Engineering part 3
Data Hops
 

Recently uploaded (20)

leewayhertz.com-AI in predictive maintenance Use cases technologies benefits ...
leewayhertz.com-AI in predictive maintenance Use cases technologies benefits ...leewayhertz.com-AI in predictive maintenance Use cases technologies benefits ...
leewayhertz.com-AI in predictive maintenance Use cases technologies benefits ...
 
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-EfficiencyFreshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
 
Building Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and MilvusBuilding Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and Milvus
 
Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)
 
GraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracyGraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracy
 
Public CyberSecurity Awareness Presentation 2024.pptx
Public CyberSecurity Awareness Presentation 2024.pptxPublic CyberSecurity Awareness Presentation 2024.pptx
Public CyberSecurity Awareness Presentation 2024.pptx
 
Fueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte WebinarFueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte Webinar
 
Introduction of Cybersecurity with OSS at Code Europe 2024
Introduction of Cybersecurity with OSS  at Code Europe 2024Introduction of Cybersecurity with OSS  at Code Europe 2024
Introduction of Cybersecurity with OSS at Code Europe 2024
 
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAUHCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
 
Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024
 
Nordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptxNordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptx
 
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
 
Digital Banking in the Cloud: How Citizens Bank Unlocked Their Mainframe
Digital Banking in the Cloud: How Citizens Bank Unlocked Their MainframeDigital Banking in the Cloud: How Citizens Bank Unlocked Their Mainframe
Digital Banking in the Cloud: How Citizens Bank Unlocked Their Mainframe
 
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdfHow to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
 
“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...
“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...
“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...
 
JavaLand 2024: Application Development Green Masterplan
JavaLand 2024: Application Development Green MasterplanJavaLand 2024: Application Development Green Masterplan
JavaLand 2024: Application Development Green Masterplan
 
Trusted Execution Environment for Decentralized Process Mining
Trusted Execution Environment for Decentralized Process MiningTrusted Execution Environment for Decentralized Process Mining
Trusted Execution Environment for Decentralized Process Mining
 
Dandelion Hashtable: beyond billion requests per second on a commodity server
Dandelion Hashtable: beyond billion requests per second on a commodity serverDandelion Hashtable: beyond billion requests per second on a commodity server
Dandelion Hashtable: beyond billion requests per second on a commodity server
 
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdfMonitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdf
 
FREE A4 Cyber Security Awareness Posters-Social Engineering part 3
FREE A4 Cyber Security Awareness  Posters-Social Engineering part 3FREE A4 Cyber Security Awareness  Posters-Social Engineering part 3
FREE A4 Cyber Security Awareness Posters-Social Engineering part 3
 

PyCon AU 2011 - Hosting Python Web Applications

  • 1. HOSTING PYTHON WEB APPLICATIONS Graham Dumpleton PyCon Australia Sydney 2011
  • 4. FRAMEWORK SERVERS • BaseHttpServer.HttpServer (Django, Werkzeug, Flask) • wsgiref.simple_server (Bottle) • paste.httpserver (Pylons, Pyramid, TurboGears) • Rocket (Web2Py) • cherrypy.wsgiserver (CherryPy, web.py)
  • 5. DEVELOPMENT ONLY • BaseHttpServer.HttpServer (Django, Werkzeug, Flask) • wsgiref.simple_server (Bottle)
  • 6. SHORT COMINGS • Non existent or inadequate concurrency support. • SSL support non existent or not of production quality. • Lack of good logging support. • Inadequate process management. • No direct static file serving ability.
  • 7. PRODUCTION GRADE? • paste.httpserver (Pylons, Pyramid, TurboGears) • Rocket (Web2Py) • cherrypy.wsgiserver (CherryPy, web.py)
  • 8. GETTING BETTER • Don’t provide a full process management solution. • Still usually require supervisord/monit to manage them. • No direct static file serving ability. • Still use Apache/nginx/lighttpd/Cherokee for static files. • Usually recommended they sit behind traditional server.
  • 9. INDEPENDENT SERVERS • gunicorn • gevent • meinheld • eventlet • fapws • tornado • bjoern • twisted • diesel • pants
  • 10. MIXED BAG • The gunicorn server best of this crowd. • Still usually require supervisord/monit to manage it. • No direct static file serving ability. • Still use Apache/nginx/lighttpd/Cherokee for static files. • Usually recommended they sit behind traditional server.
  • 11. FRONT END WEB PROXY Web Browser File System (Static Files) HTTP Web Browser HTTP Front End Web Server HTTP HTTP Back End Web Server Web Browser
  • 12. PERFORMANCE BENEFITS • Static file handling speed far superior. • Can implement caching in the front end web server. • Isolates dynamic web application from slow clients. • Removes need for application server to handle keep alive.
  • 13. GOOD OPTIONS • nginx • Cherokee • lighttpd • Apache
  • 14. ALTERNATIVES TO HTTP Web Browser File System (Static Files) HTTP Web Browser HTTP Front End Web Server FASTCGI Back End HTTP Application Server Web Browser
  • 15. GOOD POINTS • Language agnostic, can support more than Python. • Web server may optionally be able to handle processes. • If so, no longer need to use supervisord/monit. • Run as distinct user rather than web server user. • Request timeouts and controls on rampant processes.
  • 16. BAD POINTS • Different languages don’t have same resource requirements. • Generally configured for PHP, which sucks for Python. • Deployment for Python is more complicated than necessary.
  • 17. RECENT ALTERNATIVES • uWSGI • Phusion Passenger • Mongrel
  • 18. HOSTING ADOPTION • FASTCGI solutions still the incumbent with web hosting. • Phusion Passenger used because of Ruby popularity. • uWSGI slowly making headway with multi language support. • Can’t see the existing PHP hosting world changing at all. • Better solutions will only come with new hosting providers.
  • 19. ELEPHANT IN THE ROOM • Apache is still the most popular web server in use. • System administrators more likely to know Apache. • Apache is more a platform than just a web server. • Support for Python in form of mod_python and mod_wsgi.
  • 20. MOD_PYTHON • Runs Python embedded in Apache child worker processes. • Officially declared dead by Apache Software Foundation. • No longer supported and no new releases. • Will not be ported to Python 3.0+. • Still suffers memory leaks. • Bugs if you deviate off the path.
  • 21. MOD_WSGI • Intended to be a better mod_python. • Focus on providing a WSGI compatible API. • Limited abilities for Apache authnz providers. • Good robust general purpose solution. • Multiple modes of operation.
  • 22. EMBEDDED MODE Web Browser File System (Static Files) HTTP Web Browser HTTP Apache Web Server HTTP Python Interpreters Web Browser
  • 23. DAEMON MODE Web Browser File System (Static Files) HTTP Web Browser HTTP Apache Web Server Daemon Mode Processes HTTP ----------------- Python Interpreters Web Browser
  • 24. FRONT END + DAEMON File Web Browser System (Static Files) HTTP Front Web Browser HTTP End Web Server Back Daemon Mode End Processes HTTP Apache ----------------- Web Python Server Interpreters Web Browser
  • 25. FRONT END + EMBEDDED File Web Browser System (Static Files) HTTP Front Web Browser HTTP End Web Server Back End Apache Web Server HTTP --------------------- Python Interpreters Web Browser
  • 26. SO MANY OPTIONS • HTTP proxy to gunicorn, • Apache/mod_wsgi paste server, CherryPy embedded mode. WSGI server. • Apache/mod_wsgi daemon • FASTCGI/SCGI/AJP mode. • uWSGI, Phusion Passenger, • HTTP proxy to Apache/ Mongrel mod_wsgi.
  • 27. WHAT SHOULD YOU USE? • The hosting mechanism is usually never the bottleneck. • Don’t believe hello world benchmarks. • Don’t believe what people tell you on IRC channels. • Use what you have the skills to setup and configure. • Use what you find has the qualities you need. • Test the configuration you choose with real applications.
  • 28. MOST POPULAR • Apache/mod_wsgi (daemon mode). • nginx HTTP proxy to Apache/mod_wsgi. • nginx HTTP proxy to gunicorn. • nginx to uWSGI.
  • 29. DON’T WASTE YOUR TIME • Concentrate on removing bottlenecks. • Look at improving your database performance. • Look at implementing/improving page/data caching. • Look at improving browser page rendering times. • Look at monitoring tools such as New Relic and Munin. • The hosting mechanism is only a small part of the problem.

Editor's Notes

  1. \n
  2. Only a few well known Python web applications.\n
  3. Many Python web frameworks for building your own however.\n
  4. Most web frameworks bundle in there own web server to make development easier. They often have the ability to perform automatic detection of code changes and will restart automatically. These servers fall into two categories based on how capable they are.\n
  5. The simplest of these are usually based on basic web server functionality provided in the Python standard library. These are definitely only suitable for development and definitely not adequate for production use.\n
  6. Just not up to handling the rigours of a high load production web site, have not been security audited and could just well result in your site blowing up as soon as any one looks at it. \n
  7. Claimed by the developers to be suitable for production usage and do see a lot of use as a result. Reasonably safe option but mileage may vary.\n
  8. Still not a complete solution however. Generally need separate process management to ensure they stay running and definitely not good solutions for static file serving. Will perform better as a result when placed behind a front end web server.\n
  9. Lots of other options. Rather than build new web frameworks, these days the cool thing to do seems to be building new WSGI servers.\n
  10. Gunicorn probably the best standalone WSGI server and is the flavour of the month. Like paste.httpserver, Rocket and cherrypy.wsgiserver still benefits by being placed behind a front end web server.\n
  11. Front end web server handles SSL, virtual hosts and static file serving. All requests for dynamically generated content are proxied through to the back end web server. In this case our Python WGSI server. The idea is here is that no one web server is going to be the best at everything so we start specialising and use a server in front designed to handle static content.\n
  12. In addition to the the benefits we get from improved static file handling, can implement caching and avoid requests getting to Python WSGI server. The architecture of the solution also helps as it isolates the Python WSGI server from slow clients and requests only get to if needed and when ready.\n
  13. Best options for a front end web server are any which are implemented using an asynchronous or event driven system. Use of a threading module is just too heavy weight when dealing with high levels of concurrency. Apache is therefore not a good option for a high volume site, with nginx being arguably the best.\n
  14. Rather than proxy HTTP, then can use FASTCGI. Back end is no longer strictly a web server but an application server using a custom protocol. The WSGI adapter in this case bridges between the FASTCGI wire protocol and the WSGI API rather than the HTTP protocol. If there is little difference with how things work with HTTP however, some argue what is the point.\n
  15. Provides a reasonably robust model when implemented properly. For shared web hosting companies, that it can be used to support multiple languages is very convenient. Web hosting companies don’t want to have to deal with distinct managed processes listening on separate ports. Want a seamless solution that doesn’t need manual setup.\n
  16. Problem with shared web hosting is that the setups are PHP biased and suck for Python. Python needs more memory and processes really need to be persistent. For PHP you can just drop in a .php file, but for Python you can’t just drop in a .wsgi script file and have it work. Deployment experience could be made better quite easily, but no one seems to care.\n
  17. uWSGI started in Python now branching into other languages. Phusion Passenger and Mongrel started in Ruby and now moving into Python. uWSGI has similar architecture to FASTCGI but uses a slight variation on SCGI for wire protocol. Process management is distinct from the web server.\n
  18. Reality is that web hosting companies specialising in PHP will probably never provide a good solution for Python. Some will try to cater for what is popular, but deployment never seamless. Hope comes in the form of new hosting companies with no legacy. DotCloud for multi language and possibly others. For Python, gondor.io, ep.io and djangozoom.\n
  19. Apache is still used in over 60% of web sites. In contrast nginx is used in less than 10%. More collective experience with using Apache than other servers, but it has its detractors. Accusations of being bloated and hard to configure. Python has especially got a raw deal with this because of servers not being set up properly for Python use.\n
  20. It has prime real estate in the name mod_python and is what a lot of people will logically look for when first thinking of Python and Apache. Just don’t go there. The project has been declared dead and best left that way.\n
  21. Learnt from the mistakes of mod_python. Doesn’t try to be a framework in itself but just a bridge to any WSGI application/framework. Can be used in embedded mode or daemon mode.\n
  22. For embedded mode the Python interpreter running the WSGI application is inside of the web server process which are handling static file requests. Not recommended for single threaded prefork MPM where large number of processes as memory requirements much larger. Multi threaded worker MPM preferred. Adequate for most if worker MPM used even though static files handled as well.\n
  23. Effectively the same model as FASTCGI and uWSGI. Being Apache however, you don’t get some of the benefits of using async front end web server. Still the best general purpose configuration for Apache/mod_wsgi when multithreading used as most peoples sites do not see enough traffic to warrant a front end async web server for static files anyway.\n
  24. Popular upgrade path is to put a front end web server in front of Apache/mod_wsgi. Good solution if also using Apache for other purposes such as access control, authentication, authorisation or other languages such as PHP. If Apache only being used for the single Python web application, could instead use embedded mode with worker MPM.\n
  25. Need to ensure that Apache is configured properly for running fat Python web applications. Start all processes up front and don’t allow them to be killed off when idle. Preload WSGI application, don’t allow lazy loading. Should only be used if you know how to configure Apache/mod_wsgi properly. Will be best performing solution when using Apache/mod_wsgi.\n
  26. Bewildering array of options to choose from.\n
  27. Nearly any solution will work for most people because the hosting mechanism is not the bottleneck. Use what you feel comfortable being able to administer. Identify that different servers have different strengths and no one server may be the perfect solution. Custom Python async web server (non WSGI) may be the answer for parts of your application.\n
  28. FASTCGI usually only gets used where people have no choice. Tendency is for people to use Apache/mod_wsgi, gunicorn and uWSGI. Apache/mod_wsgi is acknowledged as very stable and predictable, even if boring, but you may find Apache can be a pain to setup. Still hear occasional questions marks over reliability of uWSGI and to lesser extent gunicorn but they are improving all the time.\n
  29. The hosting mechanism is only a small part of the problem. Don’t prematurely optimise by trying to find what you think is the fastest hosting mechanism. Your application/database overhead will dwarf any benefits one server may have over another. Tuning your application gives benefits for any solution. Use production monitoring to know what is going on.\n
  30. \n