Django Deployment Workshop Jacob Kaplan-Moss Frank Wiles OSCON 2010 http://revsys.com/oscon2010

About us

2

So you’ve written a Django site…

3

… now what?

4



API Metering



Distributed Log storage, analysis



Backups & Snapshots



Graphing



Counters



HTTP Caching



Cloud/Cluster Management Tools



Input/Output Filtering



Instrumentation/Monitoring



Memory Caching



Failover



Non-relational Key Stores



Node addition/removal and hashing



Rate Limiting



Autoscaling for cloud resources



Relational Storage



CSRF/XSS Protection



Queues



Data Retention/Archival



Rate Limiting



Deployment Tools



Real-time messaging (XMPP)



Search





Multiple Devs, Staging, Prod



Data model upgrades



Ranging



Rolling deployments



Geo



Multiple versions (selective beta)



Sharding



Bucket Testing



Smart Caching



Rollbacks



CDN Management



Dirty-table management

Distributed File Storage http://randomfoo.net/2009/01/28/infrastructure-for-modern-web-sites

5

What we’re building

6

django

proxy

media

load balancer

media server

django

django

web server cluster

database database server

7

Deployment steps 1. Bootstrap an app instance. 2. Configure the database. 3. Set up application servers. 4. Automate deployment. 5. Scale up to multiple web servers. 6. Start caching. 7. Tune, tune, tune… 8

Deployment steps 1. Bootstrap an app instance. 2. Configure the database. 3. Set up application servers. 4. Automate deployment. 5. Scale up to multiple web servers. 6. Start caching. 7. Tune, tune, tune… 9

Demo

10

Deployment steps 1. Bootstrap an app instance. 2. Configure the database. 3. Set up application servers. 4. Automate deployment. 5. Scale up to multiple web servers. 6. Start caching. 7. Tune, tune, tune… 11

Database servers • SQLite • MySQL • PostgreSQL • Oracle •…

12

Why PostgreSQL?

13

Demo

14

Deployment steps 1. Bootstrap an app instance. 2. Configure the database. 3. Set up application servers. 4. Automate deployment. 5. Scale up to multiple web servers. 6. Start caching. 7. Tune, tune, tune… 15

App servers should… • Have proven reliability. • Be highly stable. • Have predictable resource consumption. • Speak WSGI.

16

Application servers • Old school: Apache + mod_python • New school: Apache + mod_wsgi • Cutting edge: uWSGI, Gunicorn • Avoid: FastCGI, SCGI, AJP, …

17

Recommendation: Apache + mod_wsgi

18

Demo

19

Deployment steps 1. Bootstrap an app instance. 2. Configure the database. 3. Set up application servers. 4. Automate deployment. 5. Scale up to multiple web servers. 6. Start caching. 7. Tune, tune, tune… 20

Deployment should... • Automatically manage dependencies. • Be isolated. • Be automated. • Be repeatable. • Be identical in staging and in production. • Work the same for everyone. 21

Dependency management

Isolation

Automation

apt/yum/...

virtualenv

Capistrano

easy_install

zc.buildout

Fabric

pip

Puppet/Chef

zc.buildout 22

Dependency management • The Python ecosystem rocks! • Python package management doesn’t. • Installing packages — and dependancies — correctly is a lot harder than it should be; most defaults are wrong. • Here be dragons.

23

Vendor packages • APT, Yum, … • The good: familiar tools; stability; handles dependancies not on PyPI. • The bad: small selection; not (very) portable; hard to supply user packages. • The ugly: installs packages system-wide.

24

easy_install • The good: multi-version packages. • The bad: requires ‘net connection; can’t uninstall; can’t handle non-PyPI packages; multi-version packages barely work. • The ugly: stale; unsupported; defaults almost totally wrong; installs system-wide.

25

pip http://pip.openplans.org/

• “Pip Installs Packages” • The good: Just Works™; handles nonPyPI packages (including direct from SCM); repeatable dependancies; integrates with virtualenv for isolation. • The bad: still young; not yet bundled. • The ugly: haven’t found it yet. 26

zc.buildout http://buildout.org/

• The good: incredibly flexible; handles any sort of dependency; repeatable builds; reusable “recipes;” good ecosystem; handles isolation, too. • The bad: often cryptic, INI-style configuration file; confusing duplication of recipes; sometimes too flexible. • The ugly: chronically undocumented. 27

Package isolation • Why? • Site A requires Foo v1.0; site B requires Foo v2.0. • You need to develop against multiple versions of dependancies.

28

Package isolation tools • Virtual machines (Xen, VMWare, EC2, …) • Multiple Python installations. • “Virtual” Python installations. • virtualenv http://pypi.python.org/pypi/virtualenv

• zc.buildout http://buildout.org/

29

Automation

30

Why automate? • “I can’t push this fix to the servers until Alex gets back from lunch.” • “Sorry, I can’t fix that. I’m new here.” • “Oops, I just made the wrong version of our site live.” • “It’s broken! What’d you do!?”

31

Automation basics • SSH is right out. • Don’t futz with the server. Write a recipe. • Deploys should be idempotent.

32

Capistrano http://capify.org/

• The good: lots of features; good documentation; active community. • The bad: stale development; very “opinionated” and Rails-oriented.

33

Fabric http://fabfile.org/

• The good: very simple; flexible; actively developed; Python. • The bad: few high-level commands; not yet “1.0”.

34

Configuration management

• CFEngine, Puppet, Chef, … • Will handle a lot more than code deployment! • Almost a necessity past N = 20 or so.

35

Recommendations Pip, Virtualenv, and Fabric Buildout and Fabric. Buildout, Fabric, Puppet. Utility computing, Fabric, Chef.

36

Demo

37

Deployment steps 1. Bootstrap an app instance. 2. Configure the database. 3. Set up application servers. 4. Automate deployment. 5. Scale up to multiple web servers. 6. Start caching. 7. Tune, tune, tune… 38

Deployment steps 5. Scale up to multiple web servers. A. N > 1. B. Load balancers. C. Database connection middleware

39

Deployment steps 5. Scale up to multiple web servers. A. N > 1. B. Load balancers. C. Database connection middleware

40

Why multiple servers? • Eliminate resource contention. • Easier to optimize for scarcity. • 1 → 2 is much harder than 2 → N

41

“Shared nothing”

42

BALANCE  =  None def  balance_sheet(request):        global  BALANCE        if  not  BALANCE:                bank  =  Bank.objects.get(...)                BALANCE  =  bank.total_balance()        ...

FAIL

43

Global variables are right out

44

from  django.cache  import  cache def  balance_sheet(request):        balance  =  cache.get('bank_balance')        if  not  balance:                bank  =  Bank.objects.get(...)                balance  =  bank.total_balance()                cache.set('bank_balance',  balance)        ...

WIN

45

def  generate_report(request):        report  =  get_the_report()        open('/tmp/report.txt',  'w').write(report)        return  redirect(view_report) def  view_report(request):        report  =  open('/tmp/report.txt').read()        return  HttpResponse(report)

FAIL

46

Filesystem? What filesystem?

47

Dealing with media

48

Demo

49

Deployment steps 5. Scale up to multiple web servers. A. N > 1. B. Load balancers. C. Database connection middleware

50

Why load balancers?

51

Load balancer traits • Low memory overhead. • High concurrency. • Hot failover. • Other nifty features...

52

Load balancers • Apache + mod_proxy • perlbal • nginx • Varnish / Squid

53

Recommendation: Nginx

54

Demo

55

Deployment steps 5. Scale up to multiple web servers. A. N > 1. B. Load balancers. C. Database connection middleware

56

Connection middleware?

57

DATABASE_HOST  =  '10.0.0.100'

FAIL

58

Connection middleware • Proxy between web and database layers • Most implement hot fallover and connection pooling • Some also provide replication, load balancing, parallel queries, connection limiting, … • DATABASE_HOST  =  '127.0.0.1' 59

Connection middleware • PostgreSQL: pgpool (I, II), pgbouncer. • MySQL: MySQL Proxy. • Database-agnostic: sqlrelay. • Oracle: ?

60

pgpool vs. pgbouncer

61

Demo

62

Deployment steps 1. Bootstrap an app instance. 2. Configure the database. 3. Set up application servers. 4. Automate deployment. 5. Scale up to multiple web servers. 6. Start caching. 7. Tune, tune, tune… 63



There are only two hard things in Computer Science: cache invalidation, naming things, and off-by-one errors



64

Caching layers • Low-level (Python API) • Template fragment caching • Per-view cache • Whole site cache • Upstream caches • CDNs 65

Cache backends

66

Production

• Use memcached. • Really.

67

Other cache backends • filesystem • database • local memory

68

Demo

69

Deployment steps 1. Bootstrap an app instance. 2. Configure the database. 3. Set up application servers. 4. Automate deployment. 5. Scale up to multiple web servers. 6. Start caching. 7. Tune, tune, tune… 70

What’s next? • Database redundancy / replication • Monitoring (availability; capacity planning) • Searching, queuing, and locking (oh my!) • NoSQL. • Scaling up and out.

71

Thank you! Us: Jacob Kaplan-Moss Frank Wiles This talk: http://revsys.com/oscon2010 Web: http://revsys.com/ Twitter: @revsys

Django Deployment Workshop - GitHub

Cloud/Cluster Management Tools. • Instrumentation/Monitoring. • Failover. • Node addition/removal ... Set up application servers. 4. Automate deployment. 5.

997KB Sizes 4 Downloads 322 Views

Recommend Documents

deployment database conventions - GitHub
NRSMAI Maria Island. Reference Station. Site ID. A locally unique, meaningful identifier. MAI_0809. Latitude. Site latitude. 42', 94.3'' S. Longitude. Site longitude.

Dan Dietz Greenville Django + Python Meetup - GitHub
Awaken your home: Python and the. Internet of Things. PyCon 2016. • Architecture. • Switch programming. • Automation component. Paulus Schoutsen's talk: ...

3GCII Workshop - GitHub
Page 1. 3GCII. Workshop. Albufeira,. Portugal. Sep 1930, 2011.

Advanced Microcontroller Audio Workshop - GitHub
In this first section, you set up software on your computer, make Teensy play ... Step #1: Plug the card into your laptop and copy all of its files to a .... Page 10 ...

Notes on 2014 workshop - GitHub
o Bulge and plane (W. Clarkson) o Magellanic Clouds (K. Vivas) o Commissioning observing program(C. Claver) o Additional topics invited. • MAF hack session ...

Ansible Tower on Azure: Post Deployment Guide - GitHub
2. Click on Microsoft Azure at the top left corner of the screen, to view the Dashboard. ... http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html. 12.

ALOJA: a Systematic Study of Hadoop Deployment Variables ... - GitHub
1. A cloud of points for Cost vs. Performance vs. Cloud or On-premise ... SSDs, InfiniBand networks, and Cloud services. ...... HadoopPerformanceTuning.pdf.

Barracuda WAF on Azure: Post Deployment Configuration ... - GitHub
Page 1 of 16 ... In the Network Interfaces blade, you can see the Private IP address of ... Service Name : Demo-Websites (Or your custom service name). Type : ...

Metapathways Workshop: Functional Space Reduction - GitHub
e.g. Databases used in NESAP Illumina Analysis: KEGG, COG ... analysis (e.g. R, Matlab, Excel) ... Define groups using either NMS or cluster analysis. 10.

Workshop: Creating stencils with Inkscape and Potrace - GitHub
http://alternativeto.net/software/inkscape/ ... The “Fuzzy selector tool” helps a lot ... We are done with GIMP now we need to save the file in a format that potrace can ... the edges with a white brush. this way if I make a mistake i can recover

Deployment Keynote
9th & 10th grade campus. Over 50% economically disadvantaged. 2013-2014 Enrollment: 1157. 2014-2015 Enrollment: 1220. iPads deployed to all students in 2013-2014, 9th graders only. 2014-2015. Approximately 50 students per school year opted to not tak

GSA Deployment Architectures
GSA administrators: Deploy and configure the GSAs to best serve content .... The web application can make use of the admin API and access ... Page 10 .... Increase the GSA host load, or deploy multiple connectors to increase traversal ...

HCS Bootcamp 1: Technical Interview Workshop Resources - GitHub
Jan 30, 2013 - 3. Glassdoor Interviews, http://www.glassdoor.com/Interview/engineering-interview-questions-SRCH KO0,11.htm. 4. Career Cup, authors of ...

Re-deployment of Certificated Staff
The principal shall share the information with those certificated staff directly ... Careers). Approval Date: April 12, 2016. Reference: School Act​, Section 18, 20, ...

Wireless CleanAir Deployment Guide - Cisco
fail and even be compromised, placing the organization at risk. Figure 1. Smart Business Architecture Model. User. Services. Network. Services. Network.

GSA Deployment Scenario Handbook
IT environment. GSA configured for public search with internet and intranet web sites and file .... Acme Inc. will configure start URLs for top-level pages. For content that .... Page 10 ... hosted on an external server in a Production environment.

django unchained script pdf
Page 1 of 1. File: Django unchained script pdf. Download now. Click here if your download doesn't start automatically. Page 1 of 1. django unchained script pdf.