leveraging elastic web scale computing with aws

57
Leveraging Elastic Web-Scale Computing with AWS Shiva Narayanaswamy

Upload: shiva-narayanaswamy

Post on 16-Apr-2017

161 views

Category:

Internet


3 download

TRANSCRIPT

Page 1: Leveraging Elastic Web Scale Computing with AWS

LeveragingElasticWeb-ScaleComputingwithAWS

Shiva Narayanaswamy

Page 2: Leveraging Elastic Web Scale Computing with AWS

EC2BasicsInstanceLifecycleEC2InstanceTypesUsingAmazonMachineImagesBootstrappingEC2InstancesMonitoring EC2withCloudWatchAutoscaling

Page 3: Leveraging Elastic Web Scale Computing with AWS

EC2BasicsInstanceLifecycleEC2InstanceTypesUsingAmazonMachineImagesBootstrappingEC2InstancesMonitoring EC2withCloudWatchAutoscaling

Page 4: Leveraging Elastic Web Scale Computing with AWS

EC2 Basics

Virtual Servers in the Cloud• One instance to thousands of instances• In any public AWS region• Create, start, stop, configure, monitor as desired• Install any software: web, business, client/server,

batch processing• Pay only for capacity you use• Variety of cost models AmazonEC2

Page 5: Leveraging Elastic Web Scale Computing with AWS

EC2 Basics: costmodels

On-Demand Reserved Spot Dedicated

Payupfrontinexchangeforhourlypricesthatare50-75%lowerthan

On-Demand

Payforcomputecapacitybythehour.Nolong-term

commitments

BidforunusedAmazonEC2capacity

LaunchinstancesinVPCondedicatedcustomerhardware

Customerscancombinemultiplepurchasetypestooptimizepricingbasedoncurrentandforecastcapacityneeds.

Spikyworkloads Committedutilization Time-insensitiveworkloads Highlysensitiveworkloads

Page 6: Leveraging Elastic Web Scale Computing with AWS

EC2BasicsInstanceLifecycleEC2InstanceTypesUsingAmazonMachineImagesBootstrappingEC2InstancesMonitoring EC2withCloudWatchAutoscaling

Page 7: Leveraging Elastic Web Scale Computing with AWS

Provisioning and Lifecycle

• Create -> Start -> Stop -> Terminate• Manually in console• Automate via API (or other tools)• Automatically based on demand

(demand curve)

Page 8: Leveraging Elastic Web Scale Computing with AWS

EC2BasicsInstanceLifecycleEC2InstanceTypesUsingAmazonMachineImagesBootstrappingEC2InstancesMonitoring EC2withCloudWatchAutoscaling

Page 9: Leveraging Elastic Web Scale Computing with AWS

Instance TypesGPU

EnabledGeneralPurpose

StorageandIOOptimized

ComputeOptimized

MemoryOptimized

M3 C3 I2

CG1M1 C1 CR1CC2 HI1 HS1

G2

M3 C3 I2 HS1

M2

R3G2

AddedInstance

Types

Page 10: Leveraging Elastic Web Scale Computing with AWS

EC2BasicsInstanceLifecycleEC2InstanceTypesUsingAmazonMachineImagesBootstrappingEC2InstancesMonitoring EC2withCloudWatchAutoscaling

Page 11: Leveraging Elastic Web Scale Computing with AWS

Amazon Machine Images

Yourmachineimages

AMIsyouhavecreatedfromEC2instancesCanbekeptprivateorsharedwithother

accounts

Amazonmaintained

SetofLinuxandWindowsimagesKeptuptodatebyAmazonineach

region

Communitymaintained

ImagespublishedbyotherAWSusersManagedandmaintainedbyMarketplace

partners

Page 12: Leveraging Elastic Web Scale Computing with AWS

Amazon Machine Images

Page 13: Leveraging Elastic Web Scale Computing with AWS

EC2BasicsInstanceLifecycleEC2InstanceTypesUsingAmazonMachineImagesBootstrappingEC2InstancesMonitoring EC2withCloudWatchAutoscaling

Page 14: Leveraging Elastic Web Scale Computing with AWS

Bootstrapping:metadataanduserdata

• EveryEC2Instancehasaccesstolocalinstancemetadataanduserdataservice

Instance request

Userdata

Instance

Meta-dataservice

Page 15: Leveraging Elastic Web Scale Computing with AWS

Bootstrapping:metadata anduserdata

• Metadata:immutableinformationabouttheinstance• AccessiblefromwithintheinstanceviaHTTPathttp://169.254.169.254/latest/meta-data/

• Script(s)oninstancemayretrieveusefulinformationabouttheinstance,suchas:

• Hostname• AMIID• InstanceID• Public/PrivateDNS• AvailabilityZone

Page 16: Leveraging Elastic Web Scale Computing with AWS

Bootstrapping:metadataanduserdata

• UserData:passupto16KBoftexttoaninstanceonlaunch• AccessiblefromwithintheinstanceviaHTTPathttp://169.254.169.254/latest/user-data/

• Textcanbeparsedbyscriptoninstanceandusedtoconfigurethemachine

Page 17: Leveraging Elastic Web Scale Computing with AWS

Custom script on AMI

(script_runner.py) fetches userdata,

parses it, and configures EC2 Instance

on boot

Bootstrapping:metadataanduserdata

Page 18: Leveraging Elastic Web Scale Computing with AWS

• CloudInit executesUserDataonfirstbootifUserDatabeginswith:• #!(Linux)• <script>(Windows;technically,EC2Config,notCloudInit,doesthis)

• CloudInit isinstalledonAmazonLinux,Ubuntu,andRHELAMIs• EC2ConfigisinstalledonWindowsServerAMIs• Bothmaybeinstalledonotherdistributionsviaapackagerepoorsource

Bootstrapping:UserData andCloudInit

Page 19: Leveraging Elastic Web Scale Computing with AWS

• UserDatatoinstallApacheandMySQLonboot,andattachanEIP:

#!/bin/bash

# Install Apache, PHP, and MySQLyum install –y httpd mysql-server

# Attach an Elastic IP to this instanceec2-associate-address \

23.34.45.56 \-i $(curl http://169.254.169.254/latest/meta-data/instance-id)

Bootstrapping:UserData andCloudInit

Page 20: Leveraging Elastic Web Scale Computing with AWS

Bootstrapping

BakeanAMI

Startaninstance

Configuretheinstance

CreateanAMIfromyourinstance

StartnewonesfromtheAMI

Configuredynamically

Launchaninstance

Usemetadataserviceandcloud-init toperformactionson

instancewhenitlaunches

Useconfig managementtoolslikePuppet/Chef/Opsworks

vs

Page 21: Leveraging Elastic Web Scale Computing with AWS

Bootstrapping

BakeanAMI Configuredynamically

Buildyourbaseimagesandsetupcustominitialisation

scripts

Maintainyour‘golden’base

Usebootstrappingtopasscustominformationinandperformpostlaunchtasks.

+

Sweetspot

Page 22: Leveraging Elastic Web Scale Computing with AWS

Bootstrapping: AMIs

Linux

JEE

YourCode

Log4J

Spring

Hibernate

Struts

Tomcat

Apache

JavaAppStack

Example full stack required to run your application.

Let’s use the 3 bootstrapping

techniques

Page 23: Leveraging Elastic Web Scale Computing with AWS

Bootstrapping: AMIbake

Fully-functional AMI is pre-build and ready to launch from the AMI inventory

InventoryofAMIs

Linux

JEE

YourCode

Log4J

Spring

Hibernate

Struts

Tomcat

Apache

AmazonEC2

Linux

JEE

YourCode

Log4J

Spring

Hibernate

Struts

Tomcat

Apache

Linux

JEE

YourCode

Log4J

Spring

Hibernate

Struts

Tomcat

Apache

Linux

JEE

YourCode

Log4J

Spring

Hibernate

Struts

Tomcat

Apache

Linux

JEE

YourCode

Log4J

Spring

Hibernate

Struts

Tomcat

Apache

JavaAMI

Page 24: Leveraging Elastic Web Scale Computing with AWS

Bootstrapping: Configuredynamically

Base OS AMI

An AMI with minimal components (OS, J2EE, and Chef/Puppet) is launched.

All configuration occurs via Chef/Puppet after instance launch

InventoryofAMIs

AmazonEC2

OSAMI

Fetchonboot

Linux

JEE

YourCode

S3

Hibernate

Tomcat

Log4J

Spring

Struts

Apache

Linux

JEE

Linux

JEEChef/Puppet

Chef/Puppet

scripts

Page 25: Leveraging Elastic Web Scale Computing with AWS

Bootstrapping: Sweetspot

Partially-configured AMI

A “Golden Image” is launched, with scripts fetching/installing app code

and other supporting components on boot

InventoryofAMIs

AmazonEC2

JavaAMI

YourCode

S3

Log4J

Spring

Struts

Linux

JEE

Hibernate

Tomcat

Apache

Fetchonboot

Fetchonboot

Linux

JEE

Hibernate

Tomcat

Apache

Linux

JEE

Hibernate

Tomcat

Apache

Linux

JEE

Hibernate

Tomcat

Apache

Linux

JEE

Hibernate

Tomcat

Apache

Page 26: Leveraging Elastic Web Scale Computing with AWS

Whydothis?

AutomationLessfingers,lessmistakes

AvailabilityDrivehigher

availabilitywithself-healing

SecurityInstanceslockeddownbydefault

FlexibleShell,

Powershell,CloudFormation,Chef,Puppet,OpsWorks

ScaleManagelargescale

deploymentsanddriveautoscaling

EfficiencyAuditandmanageyourestatewithlesstime&effort

Page 27: Leveraging Elastic Web Scale Computing with AWS

Do Don’t

Somedosanddon’ts

UseIAMroles

Gokeylessifyoucan

StrikeabalancebetweenAMIanddynamicbootstrapping

PutyourAPIaccesskeysintocode(andthenpublishtoGIT)orbake

intoAMIs(andshare)

L

Page 28: Leveraging Elastic Web Scale Computing with AWS

EC2BasicsInstanceLifecycleEC2InstanceTypesUsingAmazonMachineImagesBootstrappingEC2InstancesMonitoring EC2withCloudWatchAutoscaling

Page 29: Leveraging Elastic Web Scale Computing with AWS

Monitoring EC2 with CloudWatch

Page 30: Leveraging Elastic Web Scale Computing with AWS

EC2BasicsInstanceLifecycleEC2InstanceTypesUsingAmazonMachineImagesBootstrappingEC2InstancesMonitoring EC2withCloudWatchAutoscaling

Page 31: Leveraging Elastic Web Scale Computing with AWS

TypesofScaling

• VerticalScaling• Changinginstancesize• IncreasingEBSCapacity

• HorizontalScaling• Adding/removinginstances• ELB• Autoscaling

r3.8xlarge

c3.2xlarge

m3.medium

m3.medium m3.medium m3.medium

m3.medium m3.medium m3.medium

Page 32: Leveraging Elastic Web Scale Computing with AWS

VerticalScaling

• DifferentEC2instancetype• Highmemoryinstances• HighCPUinstances• HighI/Oinstances• Highstorageinstances

• Easytochangeinstancesizes• Willhitanendpointeventually• Requiresinstancetobestopped

r3.8xlarge

c3.2xlarge

m3.medium

Page 33: Leveraging Elastic Web Scale Computing with AWS

TraditionalITUsagePatterns

OnandOff FastGrowth

Variablepeaks Predictablepeaks

Page 34: Leveraging Elastic Web Scale Computing with AWS

TraditionalITUsagePatterns

OnandOff FastGrowth

Variablepeaks Predictablepeaks

PoorService

WASTE

Page 35: Leveraging Elastic Web Scale Computing with AWS

CloudITUsagePatterns(AutoScaling)

OnandOff FastGrowth

Variablepeaks Predictablepeaks

Page 36: Leveraging Elastic Web Scale Computing with AWS

AutoScaling• Automaticresizingofcomputeclustersbasedondemand• Defineminimumandmaximumnumberofinstances• Definewhenscalingoutandinoccurs• UsemetricscollectedinAmazonCloudWatchtodrivescaling• RunAutoScalingforOn-DemandandSpotinstancetypes• ItsFree! Amazon

CloudWatch

UsageMetrics

ScalingInstructions

AutoScalingGroup

QueueMetrics

AutoScaling

Page 37: Leveraging Elastic Web Scale Computing with AWS

DescribeswhatAutoScalingwillcreatewhenadding

Instances- Similartoec2-run-instancesAPIcommand

AMIInstanceTypeSecurityGroupInstanceKeyPair

Onlyoneactivelaunchconfigurationatatime

AutoScalingwillterminateinstanceswitholdlaunch

configurationfirstrollingupdate

AutoScalingmanagedgroupingofEC2instances

Automatichealthchecktomaintainpoolsize

Automaticallyscalethenumberofinstancesbypolicy– Min,Max,

Desired

AutomaticIntegrationwithELB

Automaticdistribution&balancingacrossAZs

ParametersforperforminganAutoScalingaction

ScaleUp/Downandbyhowmuch

ChangeInCapacity (+/- #)ExactCapacity (#)

ChangeInPercent (+/- %)

CoolDown(seconds)

PolicycanbetriggeredbyCloudWatch events

Launch Configuration Auto-Scaling Group Auto-Scaling Policy

Page 38: Leveraging Elastic Web Scale Computing with AWS

Scalingplan

• Scalebasedondemand• Manualscaling• Scalebasedonschedule• Maintaincurrentinstancelevelsatalltime

AutoScaling

Page 39: Leveraging Elastic Web Scale Computing with AWS

AutoScalingLifecycles

Page 40: Leveraging Elastic Web Scale Computing with AWS

Autoscaling

Page 41: Leveraging Elastic Web Scale Computing with AWS

Autoscaling

Page 42: Leveraging Elastic Web Scale Computing with AWS

Autoscaling

Page 43: Leveraging Elastic Web Scale Computing with AWS

Autoscaling

Page 44: Leveraging Elastic Web Scale Computing with AWS

Autoscaling

Page 45: Leveraging Elastic Web Scale Computing with AWS

Availability Zone A Availability Zone B

Autoscaling: AutoScalingGroup

Page 46: Leveraging Elastic Web Scale Computing with AWS

Availability Zone A Availability Zone B

Autoscaling: AutoScalingGroup

Page 47: Leveraging Elastic Web Scale Computing with AWS

Availability Zone A Availability Zone B

Autoscaling: AutoScalingGroup

Page 48: Leveraging Elastic Web Scale Computing with AWS

Availability Zone A Availability Zone B

Autoscaling: AutoScalingGroup

Page 49: Leveraging Elastic Web Scale Computing with AWS

Availability Zone A Availability Zone B

Autoscaling: AutoScalingGroup

Page 50: Leveraging Elastic Web Scale Computing with AWS

Latency

CloudWatchAutoScaling

ELB

Auto scaling Group

Autoscaling: ELB+CloudWatch

Page 51: Leveraging Elastic Web Scale Computing with AWS

• ToolsUsed:• CloudFormation script–

• Createamulti-AZ,loadbalancedandAutoScaledsamplewebsiterunningonanApacheWebServer(m1.small).TheapplicationisconfiguredtospanallAvailabilityZonesintheregionandisAuto-ScaledbasedontheCPUutilizationofthewebservers.

• BeeswithMachineGuns– Performancetestingtool• Acloudformation scriptthatspinsupadistibuted performancetestingtoolbasedonapacheeb tool.ThistoolwillhittheELBwith1000’sofconcurrentrequestsforatotalof100’softhousandsofrequest,thusloadingthewebserverbehindtheELB.

• Expectedresult• TheApachewebserverwillscaletoservetrafficwithoutanycustomerimpact.

Autoscaling: DEMO

Page 52: Leveraging Elastic Web Scale Computing with AWS

• CloudFormation script(Autoscalingapachewebserver)• Auto-scalinggroupconfiguration:

• Min:1• Max:3• Cooldown:300

• ScalingPolicies:• ScalingUp:

• CPUUtilization>20%for1consecutiveperiodof60seconds• Action:Add1instance• Thenwait:60secondsbeforenextoperation

• ScalingDown:• CPUUtilization<10%for2consecutiveperiodsof60seconds• Action:Remove1instance• Thenwait:60secondsbeforenextoperation

• BeeswithMachineguns(NASTY)

Demo Information

Page 53: Leveraging Elastic Web Scale Computing with AWS

Autoscaling isn’tonesizefitsall

• Choosetherightmetrics• CPUUsage• QueueDepth• Numberofconcurrentusers

• Scaletooaggressively• Overprovisioning:increasescosts• Bounciness:Addmorethanyouneedandhavetopartiallyscalebackshortlyafterscalingup,increasingcosts.

• Scaletootimidly• Poorperformance• Outagesduetolackofcapacity

• Scaleoutearly/Scaleinslowly

Page 54: Leveraging Elastic Web Scale Computing with AWS

Stopdoingthese:Provisioningandfixingservers

TreatingcomputeasphysicalthingsThinkingofcomputeasafinitecommitment

Page 55: Leveraging Elastic Web Scale Computing with AWS

andstartdoingthese

SecurityBuildsystemssecureby

default

ElasticityStatelessautoscaling

applications

ReplacenotfixBuildfromscratch,don’t

fixsomethingUnconstrainedSaygoodbyeto

traditionalcapacityplanning

BecostawareTagresources,playwith

instancetypes

AutomationCreateinstanceswhenyouneedthem,drop

themwhennot

Page 56: Leveraging Elastic Web Scale Computing with AWS

What’smore?

• Attach/DetachInstancesfromAutoScalingGroups• PlaceinstancesintoStandbyStatetoTroubleshoot• HoldinstancesinPendingstateforinstallingsoftware/retrievelogs• CreateanAutoScalingGroup/LaunchConfigurationbasedonarunninginstance

• AutoscalingLifecyclehooks

Page 57: Leveraging Elastic Web Scale Computing with AWS

Questions?