cloud best practices

74
Cloud Best Practices Eric BOTTARD Developer Advocate @ebottard / [email protected]

Upload: eric-bottard

Post on 25-Jun-2015

801 views

Category:

Documents


4 download

TRANSCRIPT

Page 1: Cloud Best Practices

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

Page 2: Cloud Best Practices

Developer Advocate • VMware

t@ebottardÄericbottard

Eric Bottard

Page 3: Cloud Best Practices

Agenda

10 in theCLOUD

DOsDON’Ts

&

Page 4: Cloud Best Practices

DISCLAIMER

Page 5: Cloud Best Practices

Http TrafficLatency Matters

Page 6: Cloud Best Practices

Where’s the Data Center?

Page 7: Cloud Best Practices

LEARNLots of Literature

Page 8: Cloud Best Practices

DIAGNOSEChrome Dev Tools

YSlowGoogle PageSpeed

Page 9: Cloud Best Practices

FIX !Unique (e.g. hash) Paths

Far Future Expires HeaderMinification

CSS SpritesCDN

Spring ResourceHandler AbstractionWRO4J / RoR Asset Pipeline

Page 10: Cloud Best Practices

FileSystemJust pretend it’s not there

Page 11: Cloud Best Practices

Is your File there? Is it Not?

Page 12: Cloud Best Practices

IT IS THEREBut...

Page 13: Cloud Best Practices

IT’S EPHEMERAL(disappears on restarts)

Page 14: Cloud Best Practices

IT’S NOT SHAREDEither

Page 15: Cloud Best Practices

Use Some Persistent

STORAGE• Mongo GridFS• Database Blob

• External Blob Service

Page 16: Cloud Best Practices

StateIt’s Better Not To Have It

Page 17: Cloud Best Practices

Try to be

STATELESS• Horizontal Scaling• High Availability

• Zero Downtime Deploy

Page 18: Cloud Best Practices

6’6”

6’0”

5’6”

5’0”

4’6”

4’0”

The Usual Suspects

Page 19: Cloud Best Practices

IF there is state

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

Page 20: Cloud Best Practices

IF there is state

USE CENTRAL SERVICE(e.g. Redis)

Page 21: Cloud Best Practices

IF there is state

MAKE IT PER USER+ Sticky Sessions

Page 22: Cloud Best Practices

DatabasesThey Have A Right To Evolve Too

Page 23: 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 24: Cloud Best Practices

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

Page 25: Cloud Best Practices

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

* It is, right?

Page 26: Cloud Best Practices

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

Page 27: Cloud Best Practices

Don’t Roll your Own!

MIGRATIONS

Page 28: Cloud Best Practices

Hotel CaliforniaBetter Stay Out of It

Page 29: 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 30: Cloud Best Practices

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

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

§ For the Last 5%• Insulate your Code

• Leverage Frameworks, e.g. Spring Profiles

Page 31: Cloud Best Practices

Beware of Data!

Page 32: Cloud Best Practices

SegregationAll Environments Were Created Equal

Page 33: Cloud Best Practices

Dev vs. Test vs. Staging vs. Prod

Page 34: Cloud Best Practices

Traditional Cloud

Machines Dev ≠ Staging ≠ Prod Identical

Process Manual, inconsistent Automated

People Dev ≠ Ops Devops

Page 35: Cloud Best Practices

One app, Many deploys

Build

Config

Code

Deployment

MANY deploys

ONE set ofdeliverables

Page 36: 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 37: Cloud Best Practices

S O AThis time, it’s for real

Page 38: Cloud Best Practices

Do your current apps look like this?

Tomcat

MySQLBrowser Apache.war

Page 39: Cloud Best Practices
Page 40: Cloud Best Practices

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

Rob Spectre, Developer Evangelism, Twilio

Page 41: Cloud Best Practices

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

Page 42: Cloud Best Practices

Chances are they 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 43: Cloud Best Practices

Communication

Page 44: Cloud Best Practices

SYNCH vs. ASYNCHe.g. HTTP vs. AMQP

Page 45: Cloud Best Practices

FORMATXML, JSON, PBuffers, Thrift

Page 46: Cloud Best Practices

LOW TECHDatabase + cron

Page 47: Cloud Best Practices

When To Do It?

Page 48: Cloud Best Practices

EARLY ONYAGNI?Slows Progress

Page 49: Cloud Best Practices

NOWWould be a Good Time

Page 50: Cloud Best Practices

LATER ONNow You Need ItHard To Refactor

Page 51: Cloud Best Practices

Spring Integration§ Pipes & Filters Architecture

§ Promotes Loose Coupling• Handles the Plumbing for you

§ Declarative Model

§ Internal & External Messaging

Page 52: Cloud Best Practices

DeployDo It Early & Do It Often

Page 53: Cloud Best Practices
Page 54: Cloud Best Practices

CONTINUOUS INTEGRATIONAutomatic builds, tests

Page 55: Cloud Best Practices

CONTINUOUS DELIVERYCI + automatic deploy

Page 56: Cloud Best Practices

IT’S OKIf it’s not PROD

Page 57: 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 58: Cloud Best Practices

ScaleYour own Way

Page 59: Cloud Best Practices

Every app is

DIFFERENT• CPU• RAM• DISK• Bugs

Page 60: 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 61: 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 62: Cloud Best Practices

UpgradeWith Zero Downtime

Page 63: 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 64: 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 65: 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 66: Cloud Best Practices

Variations

1.Have some

(privileged) population

use N+1

2.then roll out

CanaryRelease

Page 67: Cloud Best Practices

Variations

1.Have some share of

the population try

a different version

2.then decide

A|B Testing

Page 68: Cloud Best Practices

What about db changes?

Page 69: Cloud Best Practices

BEFORECode @ Version N

firstnameidPerson

lastnameaddress

Page 70: Cloud Best Practices

TRANSITIONCode @ Version N & N+1

firstnameidPerson

lastnameaddress

person_ididAddress

cityzipcodestreet

country

Page 71: Cloud Best Practices

AFTERCode @ Version N+2

firstnameidPerson

lastnameperson_ididAddress

cityzipcodestreet

country

Page 72: Cloud Best Practices

MIGRATIONS

Page 73: 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 74: Cloud Best Practices

Thank YouEric Bottard

Developer Advocate • VMware

t@ebottardÄericbottard

[email protected]