devoxx france 2013 cloud best practices

122
27 au 29 mars 2013 17h - 17h50 - Salle E. Fitzgerald & L. Amstrong Cloud Best Practices

Upload: eric-bottard

Post on 29-Nov-2014

608 views

Category:

Technology


1 download

DESCRIPTION

 

TRANSCRIPT

Page 1: Devoxx France 2013 Cloud Best Practices

27 au 29 mars 2013

17h - 17h50 - Salle E. Fitzgerald & L. Amstrong

Cloud Best Practices

Page 2: Devoxx France 2013 Cloud Best Practices

Cloud Best PracticesEric BOTTARDDeveloper Advocate@ebottard / [email protected]

Page 3: Devoxx France 2013 Cloud Best Practices

Developer Advocate • VMware

t@ebottardÄericbottard

Eric Bottard

Page 4: Devoxx France 2013 Cloud Best Practices

10 in theCLOUD

DOsDON’Ts

&

Page 5: Devoxx France 2013 Cloud Best Practices

Cloud Stack - Classic Pyramid

5

Softwareas a Service

Platform as a Service

Infrastructure as a Service

This Talk

Page 6: Devoxx France 2013 Cloud Best Practices

CONFIDENTIAL

6

Cloud Foundry – The Open Platform as a Service

Target a choice of deployment clouds

Provide a choice of development frameworks

Bind a choice of application services

github.com/cloudfoundry

Page 7: Devoxx France 2013 Cloud Best Practices

7

CloudFoundry.COM – Multi-Tenant PaaS Operated by VMware

Frameworks

Services

VMware

CloudFoundry.COM

Infrastructure

Page 8: Devoxx France 2013 Cloud Best Practices

CONFIDENTIAL

8

CloudFoundry.ORG – Community Open Source Project

DownloadCode

Setup Environment Deploy Behind Firewall

Tool Chain &Scripts

Apache2 license

Your Infrastructure

Cloud Foundry BOSH

CloudFoundry.ORG

Community Frameworks Contributions

Community Services Contributions

Page 9: Devoxx France 2013 Cloud Best Practices

DISCLAIMER

CA

PTA

IN O

BVI

OU

S! t-

shirt

ava

ilabl

e at

thre

adle

ss.c

omD

esig

n by

Nat

han

Stilli

e an

d Jo

shua

Kem

ble

Page 10: Devoxx France 2013 Cloud Best Practices

CA

PTA

IN O

BVI

OU

S! t-

shirt

ava

ilabl

e at

thre

adle

ss.c

omD

esig

n by

Nat

han

Stilli

e an

d Jo

shua

Kem

ble

CA

PTA

IN O

BVI

OU

S! t-

shirt

ava

ilabl

e at

thre

adle

ss.c

omD

esig

n by

Nat

han

Stilli

e an

d Jo

shua

Kem

ble

Page 11: Devoxx France 2013 Cloud Best Practices

CA

PTA

IN O

BVI

OU

S! t-

shirt

ava

ilabl

e at

thre

adle

ss.c

omD

esig

n by

Nat

han

Stilli

e an

d Jo

shua

Kem

ble

Page 12: Devoxx France 2013 Cloud Best Practices

Http TrafficLatency Matters

Page 13: Devoxx France 2013 Cloud Best Practices

Where’s the Data Center?

Page 14: Devoxx France 2013 Cloud Best Practices

Where’s the Data Center?

Page 15: Devoxx France 2013 Cloud Best Practices

LEARNLots of Literature

Page 16: Devoxx France 2013 Cloud Best Practices

DIAGNOSEChrome Dev Tools

YSlowGoogle PageSpeed

Page 17: Devoxx France 2013 Cloud Best Practices

FIX !Unique (e.g. hash) Paths

Far Future Expires HeaderMinification

CSS SpritesCDN

Spring ResourceHandler AbstractionWRO4J / RoR Asset Pipeline

Page 18: Devoxx France 2013 Cloud Best Practices

FileSystemJust pretend it’s not there

Page 19: Devoxx France 2013 Cloud Best Practices

Is your File there? Is it Not?

Page 20: Devoxx France 2013 Cloud Best Practices

Is your File there? Is it Not?

Page 21: Devoxx France 2013 Cloud Best Practices

IT IS THEREBut...

Page 22: Devoxx France 2013 Cloud Best Practices

IT’S EPHEMERAL(disappears on restarts)

Page 23: Devoxx France 2013 Cloud Best Practices

IT’S NOT SHAREDEither

Page 24: Devoxx France 2013 Cloud Best Practices

Use Some Persistent

STORAGE

Page 25: Devoxx France 2013 Cloud Best Practices

Use Some Persistent

STORAGE• Mongo GridFS

Page 26: Devoxx France 2013 Cloud Best Practices

Use Some Persistent

STORAGE• Mongo GridFS

• Database Blob

Page 27: Devoxx France 2013 Cloud Best Practices

Use Some Persistent

STORAGE• Mongo GridFS

• Database Blob

• External Blob Service

Page 28: Devoxx France 2013 Cloud Best Practices

StateIt’s Better Not To Have It

Page 29: Devoxx France 2013 Cloud Best Practices

Try to be

STATELESS

Page 30: Devoxx France 2013 Cloud Best Practices

Try to be

STATELESS• Horizontal Scaling

Page 31: Devoxx France 2013 Cloud Best Practices

Try to be

STATELESS• Horizontal Scaling

• High Availability

Page 32: Devoxx France 2013 Cloud Best Practices

Try to be

STATELESS• Horizontal Scaling

• High Availability

• Zero Downtime Deploy

Page 33: Devoxx France 2013 Cloud Best Practices

The Usual Suspects

Page 34: Devoxx France 2013 Cloud Best Practices

6’6”

6’0”

5’6”

5’0”

4’6”

4’0”

The Usual Suspects

Page 35: Devoxx France 2013 Cloud Best Practices

6’6”

6’0”

5’6”

5’0”

4’6”

4’0”

The Usual Suspects

Page 36: Devoxx France 2013 Cloud Best Practices

6’6”

6’0”

5’6”

5’0”

4’6”

4’0”

The Usual Suspects

Page 37: Devoxx France 2013 Cloud Best Practices

6’6”

6’0”

5’6”

5’0”

4’6”

4’0”

The Usual Suspects

Page 38: Devoxx France 2013 Cloud Best Practices

The Usual Suspects

Page 39: Devoxx France 2013 Cloud Best Practices

IF there is state

PUSH TO CLIENT(e.g. Cookie, HTML5 apps)

Page 40: Devoxx France 2013 Cloud Best Practices

IF there is state

USE CENTRAL SERVICE(e.g. Redis)

Page 41: Devoxx France 2013 Cloud Best Practices

IF there is state

MAKE IT PER USER+ Sticky Sessions

Page 42: Devoxx France 2013 Cloud Best Practices

DatabasesThey Have A Right To Evolve Too

Page 43: Devoxx France 2013 Cloud Best Practices

vmc tunnel (caldecott)$ vmc tunnel

1: foobar-mq2: foobar-pg3: postgresql-handson-cfWhich service instance?> 3

1: none2: psqlWhich client would you like to start?> 2

Opening tunnel on port 10000...

Page 44: Devoxx France 2013 Cloud Best Practices

HUMAN.EQUALS(ERROR)(when they simply don’t forget)

Page 45: Devoxx France 2013 Cloud Best Practices

YOUR CODE IS VERSIONED*Why isn’t your DB?

* It is, right?

Page 46: Devoxx France 2013 Cloud Best Practices

DON’T ROLL YOUR OWN!(and beware of clusters)

Page 47: Devoxx France 2013 Cloud Best Practices

Don’t Roll your Own!

MIGRATIONS

Page 48: Devoxx France 2013 Cloud Best Practices

Hotel CaliforniaBetter Stay Out of It

Page 49: Devoxx France 2013 Cloud Best Practices

Main Risk: Lock InWelcome to the hotel california

Such a lovely place

Such a lovely face

Plenty of room at the hotel california

Any time of year, you can find it here

Last thing I remember, I was

Running for the door

I had to find the passage back

To the place I was before

’relax,’ said the night man,

We are programmed to receive.

You can checkout any time you like,

But you can never leave!

-the Eagles

Page 50: Devoxx France 2013 Cloud Best Practices

Don’t Code to (any) Cloud!

Page 51: Devoxx France 2013 Cloud Best Practices

Don’t Code to (any) Cloud!§Auto-Reconfiguration

Page 52: Devoxx France 2013 Cloud Best Practices

Don’t Code to (any) Cloud!§Auto-Reconfiguration§For the Last 5%

•Insulate your Code•Leverage Frameworks, e.g. Spring Profiles

<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans"...>

<bean id="mongoTemplate" class="org.springframework.data.mongodb.core.MongoTemplate">

<constructor-arg ref="mongoDbFactory" /> </bean>

<beans profile="default"> <mongo:db-factory id="mongoDbFactory"

dbname="test" host="127.0.0.1" port="27017" username="foo" password="bar" />

</beans>

<beans profile="cloud"> <cloud:mongo-db-factory id="mongoDbFactory" service-name="myBoundServiceName" /> </beans></beans>

Page 53: Devoxx France 2013 Cloud Best Practices

Beware of Data!

Page 54: Devoxx France 2013 Cloud Best Practices

SegregationAll Environments Were Created Equal

Page 55: Devoxx France 2013 Cloud Best Practices

Dev vs. Test vs. Staging vs. Prod

Page 56: Devoxx France 2013 Cloud Best Practices
Page 57: Devoxx France 2013 Cloud Best Practices

Traditional Cloud

Machines Dev ≠ Staging ≠ Prod Identical

Process Manual, inconsistent Automated

People Dev ≠ Ops Devops

Page 58: Devoxx France 2013 Cloud Best Practices

Traditional Cloud

Machines Dev ≠ Staging ≠ Prod Identical

Process Manual, inconsistent Automated

People Dev ≠ Ops Devops

Page 59: Devoxx France 2013 Cloud Best Practices

Traditional Cloud

Machines Dev ≠ Staging ≠ Prod Identical

Process Manual, inconsistent Automated

People Dev ≠ Ops Devops

Page 60: Devoxx France 2013 Cloud Best Practices

Traditional Cloud

Machines Dev ≠ Staging ≠ Prod Identical

Process Manual, inconsistent Automated

People Dev ≠ Ops Devops

Page 61: Devoxx France 2013 Cloud Best Practices

One app, Many deploys

Build

Config

Code

Deployment

Page 62: Devoxx France 2013 Cloud Best Practices

One app, Many deploys

Build

Config

Code

Deployment

ONE set ofdeliverables

Page 63: Devoxx France 2013 Cloud Best Practices

One app, Many deploys

Build

Config

Code

Deployment

MANY deploys

ONE set ofdeliverables

Page 64: Devoxx France 2013 Cloud Best Practices

“The Twelve Factor App, http://www.12factor.net

Environment Variables [...] unlike custom config files, or other config mechanisms such as Java System Properties, are a language- and OS-agnostic standard

Page 65: Devoxx France 2013 Cloud Best Practices

S O AThis time, it’s for real

Page 66: Devoxx France 2013 Cloud Best Practices

Do your current apps look like this?

Tomcat

MySQLBrowser Apache.war

Page 67: Devoxx France 2013 Cloud Best Practices
Page 68: Devoxx France 2013 Cloud Best Practices

“ SOA is like Adam Sandler’s career:Do one thing, and do it well.

Rob Spectre, Developer Evangelism, Twilio

Page 69: Devoxx France 2013 Cloud Best Practices

Another way to look at itcut -d" " -f1 < access.log | sort | uniq -c | sort -rn | less

Page 70: Devoxx France 2013 Cloud Best Practices

Chances are your apps will soon look like this..

MySQL

DesktopBrowser

Tomcat

users.war

Tomcat

search.war

Tomcat

orders.war

MongoNativeMobile

App

HTML5 Mobile

App

Node.jsFront End

Message Buse.g. RabbitMQ

Page 71: Devoxx France 2013 Cloud Best Practices

Communication

Page 72: Devoxx France 2013 Cloud Best Practices

SYNCH vs. ASYNCHe.g. HTTP vs. AMQP

Page 73: Devoxx France 2013 Cloud Best Practices

FORMATXML, JSON, PBuffers, Thrift

Page 74: Devoxx France 2013 Cloud Best Practices

LOW TECHDatabase + cron

Page 75: Devoxx France 2013 Cloud Best Practices

When To Do It?

Page 76: Devoxx France 2013 Cloud Best Practices

EARLY ONYAGNI?Slows Progress

Page 77: Devoxx France 2013 Cloud Best Practices

NOWWould be a Good Time

Page 78: Devoxx France 2013 Cloud Best Practices

LATER ONNow You Need ItHard To Refactor

Page 79: Devoxx France 2013 Cloud Best Practices

Spring Integration§Pipes & Filters Architecture§Promotes Loose Coupling

• Handles the Plumbing for you§Declarative Model§ Internal & External Messaging

Page 80: Devoxx France 2013 Cloud Best Practices

DeployDo It Early & Do It Often

Page 81: Devoxx France 2013 Cloud Best Practices
Page 82: Devoxx France 2013 Cloud Best Practices

CONTINUOUS INTEGRATIONAutomatic builds, tests

Page 83: Devoxx France 2013 Cloud Best Practices

CONTINUOUS DELIVERYCI + automatic deploy

Page 84: Devoxx France 2013 Cloud Best Practices

IT’S OKIf it’s not PROD

Page 85: Devoxx France 2013 Cloud Best Practices

Automate!

<build> <plugins> <plugin> <groupId>org.cloudfoundry</groupId> <artifactId>maven-cf-plugin</artifactId> <version>1.0.0.M4-SNAPSHOT</version> <configuration> <server>mycloudfoundry-instance</server> <target>http://api.cloudfoundry.com</target> <appname>spring-integration-rocks</appname> <url>spring-int-rocks.cloudfoundry.com</url> <memory>1024</memory> <services> <service> <name>mysql-test</name> <vendor>mysql</vendor> </service> <service> <name>mongodb-test</name> <vendor>mongodb</vendor> </service> </services> </configuration> </plugin> </plugins></build>

Page 86: Devoxx France 2013 Cloud Best Practices

ScaleYour own Way

Page 87: Devoxx France 2013 Cloud Best Practices

Every app is

DIFFERENT

Page 88: Devoxx France 2013 Cloud Best Practices

Every app is

DIFFERENT• CPU

Page 89: Devoxx France 2013 Cloud Best Practices

Every app is

DIFFERENT• CPU• RAM

Page 90: Devoxx France 2013 Cloud Best Practices

Every app is

DIFFERENT• CPU• RAM• DISK

Page 91: Devoxx France 2013 Cloud Best Practices

Every app is

DIFFERENT• CPU• RAM• DISK• Bugs

Page 92: Devoxx France 2013 Cloud Best Practices

Write your own logic

http://www.sxc.hu/photo/1128191

Page 93: Devoxx France 2013 Cloud Best Practices

Write your own logic

Use system-level metrics

http://www.sxc.hu/photo/1128191

Page 94: Devoxx France 2013 Cloud Best Practices

Write your own logic

Use system-level metrics

$vmc stats myappinstance #0 cpu 0.0% of 2 cores memory 191.6M of 512M disk 15.0M of 2G

http://www.sxc.hu/photo/1128191

Page 95: Devoxx France 2013 Cloud Best Practices

Write your own logic

Use system-level metrics

as well as

business-relatedinfo

$vmc stats myappinstance #0 cpu 0.0% of 2 cores memory 191.6M of 512M disk 15.0M of 2G

http://www.sxc.hu/photo/1128191

Page 96: Devoxx France 2013 Cloud Best Practices

Write your own logic

Use Inter-process scaling

Page 97: Devoxx France 2013 Cloud Best Practices

Write your own logic

Use Inter-process scaling

$vmc scale myapp \ --instances 3 --memory 1G

Page 98: Devoxx France 2013 Cloud Best Practices

Write your own logic

Use Inter-process scaling

$vmc scale myapp \ --instances 3 --memory 1G

as well as

intra-process(thread pools)

Page 99: Devoxx France 2013 Cloud Best Practices

UpgradeWith Zero Downtime

Page 100: Devoxx France 2013 Cloud Best Practices

Blue/Green Deployment

Page 101: Devoxx France 2013 Cloud Best Practices

Blue/Green Deployment$vmc app awesome awesome: running platform: spring on java usage: 512M × 1 instance urls: awesome.cloudfoundry.com services: postgresql-db

Page 102: Devoxx France 2013 Cloud Best Practices

Blue/Green Deployment$vmc app awesome awesome: running platform: spring on java usage: 512M × 1 instance urls: awesome.cloudfoundry.com services: postgresql-db

Users LB / Proxy

Version N Version N

Page 103: Devoxx France 2013 Cloud Best Practices

Blue/Green Deployment

Users LB / Proxy

Version N Version N

Page 104: Devoxx France 2013 Cloud Best Practices

Blue/Green Deployment

$vmc push --name awesome_v2 \ --url awesome_secret.cloudfoundry.com

Users LB / Proxy

Version N Version N

Page 105: Devoxx France 2013 Cloud Best Practices

Blue/Green Deployment

$vmc push --name awesome_v2 \ --url awesome_secret.cloudfoundry.com

Users LB / Proxy

Version N Version N

Version N+1 Version N+1

Page 106: Devoxx France 2013 Cloud Best Practices

Blue/Green Deployment

Users LB / Proxy

Version N Version N

Version N+1 Version N+1

Page 107: Devoxx France 2013 Cloud Best Practices

Blue/Green Deployment$vmc unmpap awesome awesome.cloudfoundry.com$vmc map awesome_v2 awesome.cloudfoundry.com

Users LB / Proxy

Version N Version N

Version N+1 Version N+1

Page 108: Devoxx France 2013 Cloud Best Practices

Blue/Green Deployment$vmc unmpap awesome awesome.cloudfoundry.com$vmc map awesome_v2 awesome.cloudfoundry.com

Users LB / Proxy

Version N Version N

Version N+1 Version N+1

Page 109: Devoxx France 2013 Cloud Best Practices

Blue/Green Deployment$vmc unmpap awesome awesome.cloudfoundry.com$vmc map awesome_v2 awesome.cloudfoundry.com

Users LB / Proxy

Version N Version N

Version N+1 Version N+1

Page 110: Devoxx France 2013 Cloud Best Practices

VariationsCanaryRelease

Page 111: Devoxx France 2013 Cloud Best Practices

1.Have some

(privileged) population

use N+1

VariationsCanaryRelease

Page 112: Devoxx France 2013 Cloud Best Practices

1.Have some

(privileged) population

use N+1

2.then roll out

VariationsCanaryRelease

Page 113: Devoxx France 2013 Cloud Best Practices

Variations

A|B Testing

Page 114: Devoxx France 2013 Cloud Best Practices

Variations

1.Have some share of

the population try

a different version

A|B Testing

Page 115: Devoxx France 2013 Cloud Best Practices

Variations

1.Have some share of

the population try

a different version

2.then decide

A|B Testing

Page 116: Devoxx France 2013 Cloud Best Practices

What about db changes?

Page 117: Devoxx France 2013 Cloud Best Practices

BEFORECode @ Version N

firstnameidPerson

lastnameaddress

Page 118: Devoxx France 2013 Cloud Best Practices

TRANSITIONCode @ Version N & N+1

firstnameidPerson

lastnameaddress

person_ididAddress

cityzipcodestreet

country

Page 119: Devoxx France 2013 Cloud Best Practices

AFTERCode @ Version N+2

firstnameidPerson

lastnameperson_ididAddress

cityzipcodestreet

country

Page 120: Devoxx France 2013 Cloud Best Practices

MIGRATIONS

Page 121: Devoxx France 2013 Cloud Best Practices

Limit your Http TrafficThere is no File System

Strive for StatelessnessAutomate your DB Migrations

Avoid Vendor Lock-inTreat all envs as Identical

It’s all about Loose CouplingUse Frequent DeploymentsTargeted and Custom Scaling

Upgrade with Zero Downtime

Page 122: Devoxx France 2013 Cloud Best Practices

Thank YouEric Bottard

Developer Advocate • VMware

t@ebottardÄericbottard

[email protected]