HOSTING PYTHON WEB APPLICATIONS. Graham Dumpleton PyCon Australia Sydney 2011



Similar documents
IERG 4080 Building Scalable Internet-based Services

White Paper. Java versus Ruby Frameworks in Practice STATE OF THE ART SOFTWARE DEVELOPMENT 1

Nginx 1 Web Server Implementation

MASTER THESIS. TITLE: Analysis and evaluation of high performance web servers

socketio Documentation

Understanding Evolution's Architecture A Technical Overview

MAGENTO HOSTING Progressive Server Performance Improvements

Layers of Caching: Key to scaling your website. Lance Albertson -- Narayan Newton

depl Documentation Release depl contributors

Shoal: IaaS Cloud Cache Publisher

BASICS OF SCALING: LOAD BALANCERS

New Relic & JMeter - Perfect Performance Testing

NetIQ Access Manager 4.1

TFE listener architecture. Matt Klein, Staff Software Engineer Twitter Front End

Copyright 1

Table of Contents Introduction and System Requirements 9 Installing VMware Server 35

PHP web serving study Performance report

Magento & Zend Benchmarks Version 1.2, 1.3 (with & without Flat Catalogs)

Web Development Frameworks

A Talk ForApacheCon Europe 2008

How To Use Ngnix (Php) With A Php-Fpm (Php-Fmm) On A Web Server (Php5) On Your Web Browser) On An Ubuntu Web Server On A Raspberry Web 2.5 (Net

Pillars of Python: Six Python Web frameworks compared

SiteCelerate white paper

Deploying and Monitoring Ruby on Rails A practical guide

Wednesday, October 10, 12. Running a High Performance LAMP stack on a $20 Virtual Server

BeBanjo Infrastructure and Security Overview

Using Toaster in a Production Environment

5 Mistakes to Avoid on Your Drupal Website

Oracle WebLogic Server 11g Administration

Web of Things Architecture

The Windows Web Platform. Michael Epprecht Microsoft Switzerland twitter: fastflame

Test Run Analysis Interpretation (AI) Made Easy with OpenLoad

DIY Device Cloud Documentation

Performance Evaluation of Shared Hosting Security Methods

Modern Web Development From Angle Brackets to Web Sockets

CHAPTER 1 - JAVA EE OVERVIEW FOR ADMINISTRATORS

An Oracle White Paper May Oracle Tuxedo: An Enterprise Platform for Dynamic Languages

FileMaker Server 12. Getting Started Guide

A Comparative Study on Vega-HTTP & Popular Open-source Web-servers

Apache Tomcat. Load-balancing and Clustering. Mark Thomas, 20 November Pivotal Software, Inc. All rights reserved.

ArcGIS for Server: Administrative Scripting and Automation

Tomcat Tuning. Mark Thomas April 2009

CentOS Linux 5.2 and Apache 2.2 vs. Microsoft Windows Web Server 2008 and IIS 7.0 when Serving Static and PHP Content

Simple Tips to Improve Drupal Performance: No Coding Required. By Erik Webb, Senior Technical Consultant, Acquia

Application Compatibility Best Practices for Remote Desktop Services

How To Configure Apa Web Server For High Performance

Accelerating Rails with

UNIVERSAL WEB APPLICATION SERVER MAYUMBO NYIRENDA. Department of Computer Science

Accelerating Wordpress for Pagerank and Profit

Web Server Software Architectures

Designing Large-Scale Applications in Python

Installation Manual for Catalog Infinite Scroll extension

Monitoring Nginx Server

Performance Optimization Guide

EWeb: Highly Scalable Client Transparent Fault Tolerant System for Cloud based Web Applications

Apache httpd v2.4: Reverse Proxy. (The Hidden Gem) Jim Jagielski

1 Discussion of multithreading on Win32 mod_perl

Cloud Based Application Architectures using Smart Computing

CloudLinux is a proven solution for shared hosting providers that:

DEPLOYMENT GUIDE Version 1.0. Deploying the BIG-IP LTM with Apache Tomcat and Apache HTTP Server

Resource Utilization of Middleware Components in Embedded Systems

ELIXIR LOAD BALANCER 2

A Tool for Evaluation and Optimization of Web Application Performance

Surviving the Big Rewrite: Moving YELLOWPAGES.COM to Rails. John Straw YELLOWPAGES.COM

MEASURING WORKLOAD PERFORMANCE IS THE INFRASTRUCTURE A PROBLEM?

Top 10 Questions to Ask when Choosing a Secure File Transfer Solution

User Guide. You will be presented with a login screen which will ask you for your username and password.

<Insert Picture Here> Oracle Web Cache 11g Overview

About CloudLinux. LVE Manager. Industry awards. Ruby Selector. Python Selector. CageFS. Mod_lsapi. MySQL Governor. OptimumCache.

Painless Web Proxying with Apache mod_proxy

Intro to Load-Balancing Tomcat with httpd and mod_jk

Adding scalability to legacy PHP web applications. Overview. Mario Valdez-Ramirez

Developing large-scale Applications in Python

CS 188/219. Scalable Internet Services Andrew Mutz October 8, 2015

HDFS Users Guide. Table of contents

Windows Server Performance Monitoring

CSP Gateway Configuration Guide

Operations and Monitoring with Spring

Performance Testing of Java Enterprise Systems

Igor Seletskiy. CEO, CloudLinux

Apache Tomcat Tuning for Production

Glassfish Architecture.

LAVA Project Update. Paul Larson

latest Release 0.2.6

Performance Tuning and Optimizing SQL Databases 2016

Scaling Progress OpenEdge Appservers. Syed Irfan Pasha Principal QA Engineer Progress Software

Internet Information TE Services 5.0. Training Division, NIC New Delhi


This document describes how the Meraki Cloud Controller system enables the construction of large-scale, cost-effective wireless networks.

Caching SMB Data for Offline Access and an Improved Online Experience

ZEN LOAD BALANCER EE v3.04 DATASHEET The Load Balancing made easy

Web Application Frameworks. Robert M. Dondero, Ph.D. Princeton University

Transcription:

HOSTING PYTHON WEB APPLICATIONS Graham Dumpleton PyCon Australia Sydney 2011

WEB APPLICATIONS Only a few well known Python web applications.

WEB FRAMEWORKS Many Python web frameworks for building your own however.

FRAMEWORK SERVERS BaseHttpServer.HttpServer (Django, Werkzeug, Flask) wsgiref.simple_server (Bottle) paste.httpserver (Pylons, Pyramid, TurboGears) Rocket (Web2Py) cherrypy.wsgiserver (CherryPy, web.py) 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.

DEVELOPMENT ONLY BaseHttpServer.HttpServer (Django, Werkzeug, Flask) wsgiref.simple_server (Bottle) 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.

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. 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.

PRODUCTION GRADE? paste.httpserver (Pylons, Pyramid, TurboGears) Rocket (Web2Py) cherrypy.wsgiserver (CherryPy, web.py) 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.

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. 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.

INDEPENDENT SERVERS gunicorn meinheld fapws bjoern diesel gevent eventlet tornado twisted pants Lots of other options. Rather than build new web frameworks, these days the cool thing to do seems to be building new WSGI servers.

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. 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.

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. FRONT END WEB PROXY File System (Static Files) Front End Web Server Back End Web Server

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. 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.

GOOD OPTIONS nginx Cherokee lighttpd Apache 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.

ALTERNATIVES TO File System (Static Files) Front End Web Server FASTCGI Back End Application Server Rather than proxy, 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 protocol. If there is little difference with how things work with however, some argue what is the point.

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. 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.

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. 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.

RECENT ALTERNATIVES uwsgi Phusion Passenger Mongrel 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.

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. 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.

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. 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.

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. 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.

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. 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.

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. EMBEDDED MODE File System (Static Files) Apache Web Server Python Interpreters

DAEMON MODE File System (Static Files) Apache Web Server Daemon Mode Processes ----------------- Python Interpreters 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.

FRONT END + DAEMON File System (Static Files) Front End Web Server Back End Apache Web Server Daemon Mode Processes ----------------- Python Interpreters 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.

FRONT END + EMBEDDED File System (Static Files) Front End Web Server Back End Apache Web Server --------------------- Python Interpreters 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.

SO MANY OPTIONS proxy to gunicorn, paste server, CherryPy WSGI server. FASTCGI/SCGI/AJP uwsgi, Phusion Passenger, Mongrel Apache/mod_wsgi embedded mode. Apache/mod_wsgi daemon mode. proxy to Apache/ mod_wsgi. Bewildering array of options to choose from.

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. 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.

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. MOST POPULAR Apache/mod_wsgi (daemon mode). nginx proxy to Apache/mod_wsgi. nginx 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. 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.

QUESTIONS?