43
Introduction Development Testing Deploying Scaling and Performance Cloud Hosting Providers Monitoring Beta Invites Development, Testing, Deploying, Hosting, Monitoring of your Python Web App. Lakshman Prasad (@becomingGuru) September 18, 2011

Pycon India 12

Embed Size (px)

Citation preview

Page 1: Pycon India 12

Introduction Development Testing Deploying Scaling and Performance Cloud Hosting Providers Monitoring Beta Invites

Development, Testing, Deploying, Hosting,Monitoring of your Python Web App.

Lakshman Prasad (@becomingGuru)

September 18, 2011

Page 2: Pycon India 12

Development is but, one part of the Application ”Growth” Cycle

Page 3: Pycon India 12

Introduction Development Testing Deploying Scaling and Performance Cloud Hosting Providers Monitoring Beta Invites

Common non-Development Tasks

• Distributed log storage and analysis

• Backups and Snapshots

• Graphing, Instrumentation and Monitoring

• HTTP Caching, Memory Caching

• Failover, Node addition/removal

• Auto-scaling for cloud resources

• Data Retention/Archival,

• Data Model Changes, Database sharding

• CDN Management

• API Metering, Rate Limiting

• Handling Multiple Environments, Multiple Versions, Rollbacks

Page 4: Pycon India 12

Introduction Development Testing Deploying Scaling and Performance Cloud Hosting Providers Monitoring Beta Invites

The Application ”Growth” Cycle

• Develop

• Test

• Design Production Environment

• Deploy

• Monitor

• Tune

Page 5: Pycon India 12

Introduction Development Testing Deploying Scaling and Performance Cloud Hosting Providers Monitoring Beta Invites

Introduction

Development

Testing

Deploying

Scaling and Performance

Cloud Hosting Providers

Monitoring

Beta Invites

Page 6: Pycon India 12

17444 Pypi packages

Page 7: Pycon India 12

More open source projects than you think ...

Page 8: Pycon India 12

... one for every size and style

Page 9: Pycon India 12

So-Starving: Same app in 19 Frameworks

Page 10: Pycon India 12

So you wrote a web app.

Page 11: Pycon India 12

Introduction Development Testing Deploying Scaling and Performance Cloud Hosting Providers Monitoring Beta Invites

Jacob on Testing

”Code without tests is broken by design”

Page 12: Pycon India 12

Introduction Development Testing Deploying Scaling and Performance Cloud Hosting Providers Monitoring Beta Invites

Unit Testing

from django . u t i l s import u n i t t e s tfrom myapp . models import Animal

c l a s s AnimalTestCase ( u n i t t e s t . TestCase ) :def setUp ( s e l f ) :

s e l f . l i o n = Animal . o b j e c t s . c r e a t e ( name=” l i o n ” ,sound=” r o a r ” )

s e l f . c a t = Animal . o b j e c t s . c r e a t e ( name=” c a t ” ,sound=”meow” )

def t e s t S p e a k i n g ( s e l f ) :s e l f . a s s e r t E q u a l ( s e l f . l i o n . speak ( ) ,

’ The l i o n s a y s ” r o a r ” ’ )s e l f . a s s e r t E q u a l ( s e l f . c a t . speak ( ) ,

’ The c a t s a y s ”meow” ’ )

Page 13: Pycon India 12

Introduction Development Testing Deploying Scaling and Performance Cloud Hosting Providers Monitoring Beta Invites

Titus Brown on TDD and BDD

”I don’t do test-driven development; I dostupidity-driven testing. When I do something stupid, Iwrite a test to make sure I don’t do it again.”

Page 14: Pycon India 12

Introduction Development Testing Deploying Scaling and Performance Cloud Hosting Providers Monitoring Beta Invites

Feature Testing

>>> from django . t e s t . c l i e n t import C l i e n t>>> c = C l i e n t ( )>>> r e s p o n s e = c . p o s t ( ’ / l o g i n / ’ ,

{ ’ username ’ : ’ j o h n ’ ,’ password ’ : ’ smi th ’ })

>>> r e s p o n s e . s t a t u s c o d e200>>> r e s p o n s e = c . g e t ( ’ / customer / d e t a i l s / ’ )>>> r e s p o n s e . c o n t e n t’<!DOCTYPE html . . . ’

Page 15: Pycon India 12

Introduction Development Testing Deploying Scaling and Performance Cloud Hosting Providers Monitoring Beta Invites

In Browser Testing

• Selenium

• Twill

Page 16: Pycon India 12

Introduction Development Testing Deploying Scaling and Performance Cloud Hosting Providers Monitoring Beta Invites

An idempotent deployment

• Automated - Fabric, Puppet, Capistrano, Buildout

• Isolated - virtualenv, Buildout

• Repeatable - pip, easyinstall

• Dependency Management - Yum, Deb, pip

Page 17: Pycon India 12

Real World Production Environment

Page 18: Pycon India 12

Introduction Development Testing Deploying Scaling and Performance Cloud Hosting Providers Monitoring Beta Invites

To start with

Page 19: Pycon India 12

Introduction Development Testing Deploying Scaling and Performance Cloud Hosting Providers Monitoring Beta Invites

DB Prop

Page 20: Pycon India 12

Introduction Development Testing Deploying Scaling and Performance Cloud Hosting Providers Monitoring Beta Invites

Seperate DB machine (with pooling)

Page 21: Pycon India 12

Introduction Development Testing Deploying Scaling and Performance Cloud Hosting Providers Monitoring Beta Invites

Seperate static server

Page 22: Pycon India 12

Introduction Development Testing Deploying Scaling and Performance Cloud Hosting Providers Monitoring Beta Invites

Together called a web server

Page 23: Pycon India 12

Introduction Development Testing Deploying Scaling and Performance Cloud Hosting Providers Monitoring Beta Invites

Then, a LB and all set to Scale

Page 24: Pycon India 12

Introduction Development Testing Deploying Scaling and Performance Cloud Hosting Providers Monitoring Beta Invites

Then, scale into clusters

Page 25: Pycon India 12

Introduction Development Testing Deploying Scaling and Performance Cloud Hosting Providers Monitoring Beta Invites

Many click-hosting providers

Page 26: Pycon India 12

The (now) Premium Hosting service

Page 27: Pycon India 12

Introduction Development Testing Deploying Scaling and Performance Cloud Hosting Providers Monitoring Beta Invites

Custom APIs

Page 28: Pycon India 12

The BigQuery API

Page 29: Pycon India 12

Prediction API

Page 30: Pycon India 12

By far, the simplest possible Django Hosting

Page 31: Pycon India 12

Enterprise level SLAs

Page 32: Pycon India 12

Standard practices hosting

Page 33: Pycon India 12

Kitchen Sink included, on EC2

Page 34: Pycon India 12

Balance of Features and Flexibility

Page 35: Pycon India 12

Introduction Development Testing Deploying Scaling and Performance Cloud Hosting Providers Monitoring Beta Invites

Monitoring

• Nagios

• Monit

• PingDom

• PagerDuty, ServiceUptime, ...

Page 36: Pycon India 12

Introduction Development Testing Deploying Scaling and Performance Cloud Hosting Providers Monitoring Beta Invites

Monitor Resources, generate pretty graphs

Page 37: Pycon India 12

Fire UDP Packets per each action

Page 38: Pycon India 12
Page 39: Pycon India 12

Introduction Development Testing Deploying Scaling and Performance Cloud Hosting Providers Monitoring Beta Invites

For PyCon India attendees

• epio invite code: pyconindia82731

• django-zoom priority invites!

Page 40: Pycon India 12

Introduction Development Testing Deploying Scaling and Performance Cloud Hosting Providers Monitoring Beta Invites

About Me

• Active Djangonaut and active in Python world

• Part of a few popular open source django applicationsgithub.com/becomingGuru, stackoverflow.com/users/55562

• Co-Authored an ebook ”django-design-patterns”

• Architect and develop django applications at InMobi

• Earlier, Consulting and Development via Agiliq Solutions

• Developed several custom proprietory django applications

• twitter.com/becomingGuru http://becomingguru.com

Page 41: Pycon India 12

Introduction Development Testing Deploying Scaling and Performance Cloud Hosting Providers Monitoring Beta Invites

Resources

So s t a r v i n g :h t t p s : / / g i t h u b . com/ a g i l i q / so−s t a r v i n g

S c a l i n g :” Cal Henderson : B u i l d i n g S c a l a b l e Web S i t e s ”H i g h s c a l a b i l i t y . com , K i t c h e n s o a p . com

Per formance :” S t e v e Souders : Even F a s t e r W e b s i t e s ”

Cloud H o s t i n g :”Ken Cochrane h t t p : / / k e n c o c h r a n e . net / b l o g /”

” Jacob Kaplan Moss : Django i n th e Rea l World ”

Page 42: Pycon India 12

Introduction Development Testing Deploying Scaling and Performance Cloud Hosting Providers Monitoring Beta Invites

Image Attributions

ht tp : //www. f l i c k r . com/ photos / t e j e d o r o d e l u z /3157690060/ht tp : //www. f l i c k r . com/ photos /23820645@N05/4287681570/ht tp : //www. f l i c k r . com/ photos / a i d a n j o n e s /3575000735/ht tp : // j a c o b i a n . org /h t tp : // s a n j u a n c o l l e g e . edu/ l i b / images / p h i l o s o p h y b r a i n . j pgh t tp : //www. f l i c k r . com/ photos /uhop /105062059/ht tp : // s3 . amazonaws . com/memebox/ up load s /136/ e x p o n e n t i a l g r a p h 2 . j pgh t tp : // geekandpoke . typepad . com/geekandpoke / images /2008/06/03/ s e xp l 1 8 . j pgh t tp : //www. f l i c k r . com/ photos /go /253819/ht tp : // a round the sphe r e . f i l e s . wo rdp re s s . com/2009/05/ sw i s s−army−k n i f e . j pgh t tp : //www. f r e e f o t o . com/ images /41/04/41 04 9−−−Keep−Le f t web . j pgh t tp : //www. f l i c k r . com/ photos / o r i n r o b e r t j o h n /114430223/

Page 43: Pycon India 12

@becomingGuru, [email protected]