40
Best Practices for Python in the Cloud Presented by: Gisle Aas, Senior Developer, ActiveState Best Practices for Python in the Cloud: Lessons Learned @ActiveState

EuroPython 2011: ActiveState - Best Practices for Python in the Cloud

Embed Size (px)

DESCRIPTION

Whether you’re an independent developer or development manager in a large company, “the cloud” is on everyone’s mind. But just because it’s in the cloud, doesn’t mean development and deployment is effortless. The cloud presents infrastructure and development challenges in a new way. In this presentation, ActiveState shares best practices in building and deploying (a) Python-centric LAMP stack(s) on the cloud for a range of web-based applications froma simple Django site to HPC GPU Clusters. Based on ActiveState’s experiences, the presentation will discuss the challenges faced and lessons learned in building an infrastructure to deploy web applications to the cloud with Python. • Which Python packages are critical for a secure, Python-centric LAMP stack (and what it takes to build them)! • Tips for developing, deploying, and scaling Python applications in the cloud • How to use Python to connect and build infrastructure to support and manage your deployment

Citation preview

Page 1: EuroPython 2011: ActiveState - Best Practices for Python in the Cloud

Best Practices forPython in the Cloud

Presented by:

Gisle Aas, Senior Developer, ActiveState

Best Practices for Python in the Cloud:Lessons Learned @ActiveState

Page 2: EuroPython 2011: ActiveState - Best Practices for Python in the Cloud

Gisle [email protected]@gislegithub.com/gisle

whoami?

Page 3: EuroPython 2011: ActiveState - Best Practices for Python in the Cloud

Agenda

About ActiveStateWhat’s a Cloud Anyway?Python in the CloudThe ActiveState ExperienceBest PracticesBuilding for PaaS (Stackato)

Page 4: EuroPython 2011: ActiveState - Best Practices for Python in the Cloud

About ActiveState

Founded 19972 million developers, 97% of Fortune 1000 rely on ActiveStateDevelopment, management, distribution solutions for dynamic languages Core languages: Python, Perl, TclOther languages: PHP, Ruby, JavascriptRelated products: Komodo IDE, Stackato

Page 5: EuroPython 2011: ActiveState - Best Practices for Python in the Cloud

ActiveState Solutions help developers

Page 6: EuroPython 2011: ActiveState - Best Practices for Python in the Cloud

Just What Is A Cloud?

Page 7: EuroPython 2011: ActiveState - Best Practices for Python in the Cloud

Essential Characteristics:On-demand self-serviceBroad network accessResource poolingRapid elasticityMeasured Service

Page 8: EuroPython 2011: ActiveState - Best Practices for Python in the Cloud

Service models: IaaS, PaaS, SaaS

Page 9: EuroPython 2011: ActiveState - Best Practices for Python in the Cloud

Deployment models:Private cloudCommunity cloudPublic cloudHybrid cloud

Page 10: EuroPython 2011: ActiveState - Best Practices for Python in the Cloud

The Cloud

http://xkcd.com/908/

Page 11: EuroPython 2011: ActiveState - Best Practices for Python in the Cloud

Python in the Cloud

Page 12: EuroPython 2011: ActiveState - Best Practices for Python in the Cloud

Who is using Python in the Cloud?

even michaelmoore.com uses python!

Page 13: EuroPython 2011: ActiveState - Best Practices for Python in the Cloud

What ActiveState Learned along the way…

Page 14: EuroPython 2011: ActiveState - Best Practices for Python in the Cloud

Our Cloud Experience

Page 15: EuroPython 2011: ActiveState - Best Practices for Python in the Cloud

Our Best Practices Guidelines

1. Simple2. Isolated3. Disposable4. Relocatable5. Portable6. Open

Page 16: EuroPython 2011: ActiveState - Best Practices for Python in the Cloud

Keep it Simple

Page 17: EuroPython 2011: ActiveState - Best Practices for Python in the Cloud

Keep Your App Simple

Keep your code and concepts simpleUse simplest database that can possibly workLAMP Stacks work

Page 18: EuroPython 2011: ActiveState - Best Practices for Python in the Cloud

ActivePython AMI LAMP Stack for Python Web Applications

Ubuntu 10.04LTS 64-bitNginx

For static content and route web-traffic to multiple worker instances

Apache (2.2.16), running mod_wsgi (3.3.7)

ActivePython, with PyPM packaging manager

virtualenv (1.5.1) & virtualenvwrapper Django (1.2.3)SQLite3, MySQL 5.1, memcached

State of the art … 1 year ago!The art changes quickly in the cloud

Page 19: EuroPython 2011: ActiveState - Best Practices for Python in the Cloud

Make Deploying Apps Simple

Developers just want to DevelopDevelopers want to leverage familiar tools

VCS, IDE, etc.

Resolve Dependencies AutomaticallyDevelopers do not want to be sysadmins

No firewall managementNo database installsNo network management

Page 20: EuroPython 2011: ActiveState - Best Practices for Python in the Cloud

Manage your Packages!

Use package managers such as yum and aptitude for tools such as ApachePyPM and Pip for Python package dependencies

Use pre-built package repositoriesPyPM pulls from a single central repository of pre-built binaries that have been tested to work on a number of platforms. pip pulls resources from multiple sources, potentially delaying an install if one of the dependencies is temporarily inaccessible.

Page 21: EuroPython 2011: ActiveState - Best Practices for Python in the Cloud

Keep it Isolated

Page 22: EuroPython 2011: ActiveState - Best Practices for Python in the Cloud

Create in Isolated Environments

Compartmentalize and isolate your build environmentDominant tools are virtualenv and virtualenvwrapper

http://pypi.python.org/pypi/virtualenv http://www.doughellmann.com/projects/virtualenvwrapper/.Easily setup and switch between multiple, isolated python environments

Developers like the isolation Fearlessly install new tools for experimentation without corrupting other environmentsAllows incompatible version dependencies

Page 23: EuroPython 2011: ActiveState - Best Practices for Python in the Cloud

A Choice of Solutions

FreeBSD JailSolaris ContainersIBM AIX PartitionsLinux-VServerParallels VirtuozzoOpenVZLXCFull OS virtualization

Page 24: EuroPython 2011: ActiveState - Best Practices for Python in the Cloud

Make it Disposable

Page 25: EuroPython 2011: ActiveState - Best Practices for Python in the Cloud

Disposable Instances

Treat instances as temporary, disposable instances that can easily be rebuilt from scratch

Manage state changes from a build scriptAvoid logging-in via ssh to run installs or to edit configurations

Tools like Fabric are designed to handle multi-step, multi-machine deployment

A fabfile becomes executable documentation of how to build your instance, run tests, and bring the system live

Simplifies software updates or altering configurationsUseful for adjusting instance sizes or replication for load-balancing

Page 26: EuroPython 2011: ActiveState - Best Practices for Python in the Cloud

Disposable Data

What parts of your data is disposableHow to persist data

Locally managed dataOff-system data stores

MirroringFor high-availabilityFor safety

Backups … need I say more?

Page 27: EuroPython 2011: ActiveState - Best Practices for Python in the Cloud

Make it Relocatable

Page 28: EuroPython 2011: ActiveState - Best Practices for Python in the Cloud

Relocatable Components

Communicate through socketsUse distinct hostnames, no IP addressesMake cloning easy that allows retargeting hostnamesSeparate primary services (e.g. db and web app)

Allows cloning the right services for scalingBackups can happen only for key componentsFail-over and recovery become easier to implementNginx front-end should be able to run separately from the underlying web server(s)

Page 29: EuroPython 2011: ActiveState - Best Practices for Python in the Cloud

Make it Portable

Page 30: EuroPython 2011: ActiveState - Best Practices for Python in the Cloud

Portability

Between IaaS providersAmazon, Linode, RackSpace, …

Between PaaS systemsMinimize DependenciesRely on the web app framework

It provides many abstractions already

Page 31: EuroPython 2011: ActiveState - Best Practices for Python in the Cloud

Object Relational Mappers

Abstracts working with databasesChange in response to load or storage needsDecouple the database from the application

An adapter between different styles of database access

Design for scalability from the outset

Page 32: EuroPython 2011: ActiveState - Best Practices for Python in the Cloud

Keep it Open

Page 33: EuroPython 2011: ActiveState - Best Practices for Python in the Cloud

6 Simple Rules to Live By

SimpleIsolatedDisposableRelocatable Portable Open Source

Page 34: EuroPython 2011: ActiveState - Best Practices for Python in the Cloud

Working with a PaaS Platform

The Stackato Experience

Page 35: EuroPython 2011: ActiveState - Best Practices for Python in the Cloud

Stackato in 6 Simple Rules

Simple3 step application deployment

IsolatedSecurity by isolation

DisposableReusable VMsCode separated from instance

Page 36: EuroPython 2011: ActiveState - Best Practices for Python in the Cloud

Stackato in 6 Simple Rules

RelocatableOptions of VMs or AMI

PortableBoth with the VM and code by design

Open SourceBased on Cloud FoundryLAMPy stack

Page 37: EuroPython 2011: ActiveState - Best Practices for Python in the Cloud

Cloud Controller

http router

DEAs

mysql

redis

mongo

Stackato Client

mail mq Services

Stackato Architecture

Based on Cloud Foundry

Designed to be:Infrastructure IndependentScalableExtensible

Page 38: EuroPython 2011: ActiveState - Best Practices for Python in the Cloud

Stackato from a Developer Perspective

3 Step App Deployment Install the 'stackato' client with pypm Set the 'target' URLRun 'stackato push’

Client bundles the application and pushes it to the serverConfig files in the application directory tell the cloud controller what additional software is requiredThe application environment is assembled, and the application is deployed to one or more worker nodes

Page 39: EuroPython 2011: ActiveState - Best Practices for Python in the Cloud

Questions?

Next Steps:Find out more about Stackato

activestate.com/cloud

Request Information:[email protected]

Page 40: EuroPython 2011: ActiveState - Best Practices for Python in the Cloud