66
Optimizing for Cost in the Cloud Jinesh Varia @jinman Technology Evangelist

Optimizing for Cost in the Cloud

  • Upload
    banyan

  • View
    49

  • Download
    0

Embed Size (px)

DESCRIPTION

Optimizing for Cost in the Cloud. Jinesh Varia @ jinman Technology Evangelist. Multiple dimensions of optimizations. Cost Performance Response time Time to market High-availability Scalability Security Manageability ……. Optimizing for Cost. - PowerPoint PPT Presentation

Citation preview

Page 1: Optimizing for Cost in the Cloud

Optimizing for Cost in the Cloud

Jinesh Varia@jinman

Technology Evangelist

Page 2: Optimizing for Cost in the Cloud

Multiple dimensions of optimizations

CostPerformanceResponse timeTime to marketHigh-availabilityScalabilitySecurityManageability…….

Page 3: Optimizing for Cost in the Cloud

Optimizing for Cost

Page 4: Optimizing for Cost in the Cloud

When you turn off your cloud resources, you actually stop paying for them

Page 5: Optimizing for Cost in the Cloud

Continuous optimization in your architecture results in recurring savings in your next month’s bill

Page 6: Optimizing for Cost in the Cloud

Elasticity is one of the fundamental properties of the cloud that drives many of its

economic benefits

Page 7: Optimizing for Cost in the Cloud

#1 Use only what you need (use Auto Scaling Service, modify–db)

Optimizing for Cost…

Page 8: Optimizing for Cost in the Cloud

Turn off what you don’t need (automatically)

Page 9: Optimizing for Cost in the Cloud

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 240

2

4

6

8

10

12

14

Daily CPU Load

Hour

Lo

ad 25% Savings

Optimize by the time of day

Page 10: Optimizing for Cost in the Cloud

Availability Zone #2

Availability Zone #1

Auto Scaling group : App Tier

Auto Scaling group : Web Tier

Elastic Load Balancer

www.MyWebSite.com(dynamic data)

media.MyWebSite.com (static data)

Amazon Route 53(DNS)

Amazon EC2

Amazon RDS AmazonRDS

Amazon S3

AmazonCloudFront

Page 11: Optimizing for Cost in the Cloud

1 5 9 13 17 21 25 29 33 37 41 45 49

Week

Web

Ser

vers

Optimize during a year

50% Savings

Page 12: Optimizing for Cost in the Cloud

Auto scaling : Types of Scaling

Scaling by Schedule• Use Scheduled Actions in Auto Scaling Service

• Date• Time• Min and Max of Auto Scaling Group Size

• You can create up to 125 actions, scheduled up to 31 days into the future, for each of your auto scaling groups. This gives you the ability to scale up to four times a day for a month.

Scaling by Policy• Scaling up Policy - Double the group size • Scaling down Policy - Decrement by 1

Page 13: Optimizing for Cost in the Cloud

Auto scaling Best Practices

Use Auto Scaling TagsUse Auto scaling Alarms and Email NotificationsScale up and down symmetricallyScale up quickly and scaling down slowlyAuto Scaling across Availability ZonesLeverage Suspend and Resume Processes

Page 14: Optimizing for Cost in the Cloud

Scale up by 10%

if CPU utilization is greater than 60%

for 5 minutes,

Scale down by 10%

if CPU utilization is less than 30%

for 20 minutes.

Example:

Page 15: Optimizing for Cost in the Cloud

Ag

g.

CP

UIn

stan

ces

Page 16: Optimizing for Cost in the Cloud

1 3 5 7 9 11 13 15 17 19 21 23 25 27 29

Days of the Month

RD

S D

B S

erve

rs75% Savings

Optimize during a month

Page 17: Optimizing for Cost in the Cloud

End of the month processing

Expand the cluster at the end of the month• Expand/Shrink feature in Amazon Elastic MapReduce

Vertically Scale up at the end of the month• Modify-DB-Instance (in Amazon RDS) (or a New RDS DB Instance )• CloudFormation Script (in Amazon EC2)

Page 18: Optimizing for Cost in the Cloud

Tip: Use “Reminder scripts”

Disassociate your unused EIPs Delete unassociated EBS volumes Delete older EBS snapshots Leverage S3 Object Expiration

Page 19: Optimizing for Cost in the Cloud

Pick the Right Instance Type

Page 20: Optimizing for Cost in the Cloud

Basic recommendations on Instance Type

Choose the EC2 instance type that best matches the resources required by the application• Start with memory requirements and architecture type (32bit or 64-

bit)• Then choose the closest number of virtual cores required

Scaling across AZs• Smaller sizes give more granularity for deploying to multiple AZs

Page 21: Optimizing for Cost in the Cloud

AWS Support – Trusted Advisor – Your personal cloud assistant

Page 22: Optimizing for Cost in the Cloud

Tip – Instance Optimizer

Instance

Amazon CloudWatchAlarm

Free MemoryFree CPUFree HDDAt 1-min intervals

Custom Metrics

PUT 2 weeks

“You could save a bunch of money by switching to a small instance, Click on CloudFormation Script to Save”

Page 23: Optimizing for Cost in the Cloud

#1 Use only what you need (use Auto Scaling Service, modify–db)

#2 Invest time in Reserved Pricing analysis (EC2, RDS)

Optimizing for Cost…

Page 24: Optimizing for Cost in the Cloud

Your Best Option: Reserved + On-Demand

Page 25: Optimizing for Cost in the Cloud

Save more when you reserve

On-demandInstances

• Pay as you go

• Starts from $0.02/Hour

ReservedInstances

• One time low upfront fee + Pay as you go

• $23 for 1 year term and $0.01/Hour

1-year and 3-year terms

Heavy Utilization RI

Medium Utilization RI

Light Utilization RI

Page 26: Optimizing for Cost in the Cloud

Utilization Sweet Spot Feature Savings over On-Demand

<10% On-Demand No Upfront Commitment

10% - 40% Light Utilization RI Ideal for Disaster Recovery Up to 56% (3-Year)

40% - 75% Medium Utilization RI Standard Reserved Capacity Up to 66% (3-Year)

>75% Heavy Utilization RI Lowest Total Cost Ideal for Baseline Servers

Up to 71% (3-Year)

0% 10%

20%

30%

40%

50%

60%

70%

80%

90%

100%

$-

$2,000

$4,000

$6,000

$8,000

$10,000

$12,000

$14,000

Heavy UtilizationMedium UtilizationLight UtilizationOn-Demand

Utilization

Co

st

m2.xlarge running Linux in US-East Region over 3 Year period Break-even

point

Page 27: Optimizing for Cost in the Cloud

Recommendations

Steady State Usage Pattern• For 100% utilization

• 3-Year Heavy RI (for maximum savings over on-demand)

Spiky Predictable Usage Pattern• Baseline

• 3-Year Heavy RI (for maximum savings over on-demand)• 1-Year Light RI (for lowest upfront commitment) + savings over on-demand

• Peak: On-Demand

Uncertain and unpredictable Usage Pattern• Start out small with On-Demand Instances (risk-free and commitment-free)• Switch to some combination of Reserved and On-Demand, if application is

successful • If not successful, you walk away having spent a fraction of what you would pay

to buy your own technology infrastructure

Page 28: Optimizing for Cost in the Cloud

Example: Simple 3-Tier Web Application

Description Option 1 Option 2 Option 3 Option 4

2 Web servers 2 On-Demand 2 On-Demand 1 On-Demand and 1 Reserved Medium Utilization

1 On-Demand and 1 Reserved Light Utilization

2 App servers 2 On-Demand 2 On-Demand 1 On-Demand and 1 Reserved Medium Utilization

1 On-Demand and 1 Reserved Light Utilization

2 Database servers 2 On-Demand 2 Reserved Medium Utilization

2 Reserved Medium Utilization

2 Reserved Heavy Utilization

Page 29: Optimizing for Cost in the Cloud

Savings Option 1 Option 2 Option 3 Option 4

Calculator Calculator Calculator Calculator

Monthly Cost $702.72 $374.78 $256.20 $238.63

One-Time Cost 1 Year Term - $1280.00 $1600.00 $1698.00

3 Year Term - $2000.00 $2500.00 $2612..60

Total Cost 1 Year Term (x12) $8432.64 $5777.36 $4674.40 $4561.56

3 Year Term (x36) $25297.92 $15492.08 $11723.20 $11203.28

Savings(Over Option 1)

1 Year Term n/a 32% 44% 45%

3 Year Term n/a 39% 54% 54%

Example: Simple 3-Tier Web Application

Page 30: Optimizing for Cost in the Cloud

#1 Use only what you need (use Auto Scaling Service, modify–db)

#2 Invest time in Reserved Pricing analysis (EC2, RDS)

#3 Architect for Spot Instances (bidding strategies)

Optimizing for Cost…

Page 31: Optimizing for Cost in the Cloud

Optimize by using Spot Instances

Heavy Utilization RI

Medium Utilization RI

Light Utilization RI

1-year and 3-year terms

On-demandInstances

• Pay as you go

• Starts from $0.02/Hour

ReservedInstances

• One time low upfront fee + Pay as you go

• $23 for 1 year term and $0.01/Hour

SpotInstances

• Requested Bid Price and Pay as you go

• $0.005/Hour as of today at 9 AM

Page 32: Optimizing for Cost in the Cloud

What are Spot Instances?

Availability Zone

Region

Availability Zone

Unused

Unused

Unused

Unused

Unused

Unused

Sold at 50% Discount!

Sold at 56% Discount!

Sold at 66% Discount!

Sold at 59% Discount!

Sold at 54% Discount!

Sold at 63% Discount!

Page 33: Optimizing for Cost in the Cloud

What is the tradeoff?

Availability Zone

Region

Availability Zone

Unused

Unused

Unused

Unused

Unused

Unused

Reclaimed

Reclaimed

Page 34: Optimizing for Cost in the Cloud

Spot Use cases

Use Case Types of Applications

Batch Processing Generic background processing (scale out computing)

Hadoop Hadoop/MapReduce processing type jobs (e.g. Search, Big Data, etc.)

Scientific Computing Scientific trials/simulations/analysis in chemistry, physics, and biology

Video and Image Processing/Rendering

Transform videos into specific formats

Testing Provide testing of software, web sites, etc

Web/Data Crawling Analyzing data and processing itFinancial Hedgefund analytics, energy trading, etcHPC Utilize HPC servers to do embarrassingly parallel jobs

Cheap Compute Backend servers for Facebook games

Page 35: Optimizing for Cost in the Cloud

Save more money by using Spot Instances

Reserved Hourly Price > Spot Price < On-Demand Price

Page 36: Optimizing for Cost in the Cloud

Spot: Example Customers

63%

50%

57%

50%

50%

66%

56%

50%

Page 37: Optimizing for Cost in the Cloud

Typical Spot Bidding Strategies

1. Bid near the Reserved Hourly Price

2. Bid above the Spot Price History

3. Bid near On-Demand Price

4. Bid above the On-Demand Price30

.0%

40.0

%50

.0%

60.0

%70

.0%

80.0

%90

.0%

100.

0%11

0.0%

120.

0%13

0.0%

140.

0%15

0.0%

160.

0%17

0.0%

180.

0%19

0.0%

200.

0%

0%

2%

4%

6%

8%

10%

12%

14%

16%

18%

20%

Bid Distribution (for last 3 months)

Bid Price as Percentage of the On-Demand Price

Pe

rce

nta

ge

of

the

Dis

trib

uti

on

Page 38: Optimizing for Cost in the Cloud

$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $$ $ $ $ $ $

1. Bid Near the Reserved Hourly Price

66% Savings over On-Demand

Page 39: Optimizing for Cost in the Cloud

2. Bid above the Spot Price History

50% Savings over On-Demand

Page 40: Optimizing for Cost in the Cloud

3. Bid near the On-Demand Price

50% Savings over On-Demand

Page 41: Optimizing for Cost in the Cloud

4. Bid above the On-Demand Price

57% Savings over On-Demand

Page 42: Optimizing for Cost in the Cloud

Managing Interruption

Page 43: Optimizing for Cost in the Cloud

Amazon Elastic MapReduceHadoop Cluster

HDFS

TaskNode

TaskNode

Core Node

CoreNode

Input Data

OutputData

Amazon S3

Metadata

Amazon SimpleDB

BI Apps

Upload large datasets or log files directlyData

Source

Code/Scripts

Amazon S3

Service

Amazon ElasticMapReduce

HiveQLPig LatinCascading

Mapper Reducer

Runs multiple JobFlow Steps

NameNode

JDBC/ODBC

HiveQLPig Latin

Query

Amazon EMR (Hadoop): Run Task Nodes on Spot

Page 44: Optimizing for Cost in the Cloud

#1: Cost without Spot4 instances *14 hrs * $0.45 = $25.20

Allocate 4 instances

Job Flow

14 HoursDuration:

Scenario #1

Add 5 Spot Instances

Duration:

Job Flow

7 Hours

Scenario #2

#2: Cost with Spot4 instances *7 hrs * $0.45 = $12.60 +5 instances * 7 hrs * $0.225 = $7.875Total = $20.475

Time Savings: 50% Cost Savings: ~19%

Amazon EMR: Reducing Cost with Spot

Page 45: Optimizing for Cost in the Cloud

Use Case: Web crawling/Search using Hadoop type clusters. Use Reserved Instances for their DB workloads and Spot instances for their indexing clusters. Launch 100’s of instances.Bidding Strategy: Bid a little above the On-Demand price to prevent interruption. Interruption Strategy: Restart the cluster if interrupted

Made for each other: MapReduce + Spot

66% Savings over On-Demand

Page 46: Optimizing for Cost in the Cloud

On-demand + Spot

Amazon S3

Amazon SQS

Amazon SimpleDB

Job

Metadata

Status

Raw D

ata

Amazon S3

Amazon SQS

Amazon SimpleDB

CompletedJob

LogsExceptions

Proce

ssed

Data

ReportsWebsite

Amazon CloudWatch

Amazon Elastic Compute Cloud

Amazon EC2

Amazon EC2

Amazon EC2

Input Queue

Output Queue

InputBucket

OutputBucket

Website(Job

Manager)

Intranet

Video Transcoding Application Example

Page 47: Optimizing for Cost in the Cloud

Use of Amazon SQS in Spot Architectures

VisibilityTimeOut Amazon EC2 Spot Instance

Page 48: Optimizing for Cost in the Cloud

Optimizing Video Transcoding Workloads

Free Offering• Optimize for reducing cost• Acceptable Delay Limits

Implementation• Set Persistent Requests• Use on-demand Instances, if

delay

Maximum Bid Price < On-demand RateGet your set reduced price for your workload

Premium Offering Optimized for Faster response times No Delays

Implementation Invest in RIs Use on-demand for Elasticity

Maximum Bid Price >= On-demand RateGet Instant Capacity for higher price

Page 49: Optimizing for Cost in the Cloud

Persistent Requests

Page 50: Optimizing for Cost in the Cloud

Architecting for Spot Instances : Best Practices

Manage interruption• Split up your work into small increments• Checkpointing: Save your work frequently and periodically

Test Your ApplicationTrack when Spot Instances Start and StopSpot Requests• Use Persistent Requests for continuous tasks• Choose maximum price for your requests

Page 51: Optimizing for Cost in the Cloud

#1 Use only what you need (use Auto Scaling Service, modify–db)

#2 Invest time in Reserved Pricing analysis (EC2, RDS)

#3 Architect for Spot Instances (bidding strategies)

#4 Leverage Application Services (ELB, SNS, SQS, SWF, SES)

Optimizing for Cost…

Page 52: Optimizing for Cost in the Cloud

Optimize by converting ancillary instances into services

Monitoring: CloudWatchNotifications: SNSQueuing: SQSSendMail: SESLoad Balancing: ELBWorkflow: SWFSearch: CloudSearch

Page 53: Optimizing for Cost in the Cloud

Elastic Load Balancing

Elastic Load BalancingPros

Elastic and Fault-tolerantAuto scalingMonitoring included

ConsFor Internet-facing traffic only

Software LB on EC2Pros

Application-tier load balancer

ConsSPOFElasticity has to be implemented manuallyNot as cost-effective

Page 54: Optimizing for Cost in the Cloud

Web Servers

vs.

$0.08per hour

(small instance)

Availability Zone

$0.025per hour

Web Servers

Availability Zone

EC2 instance+ software LB

Elastic Load Balancer

DNS

DNS

Page 55: Optimizing for Cost in the Cloud

Application Services

SNS, SQS, SES, SWFPros

Pay as you goScalabilityAvailabilityHigh performance

Software on EC2Pros

Custom features

ConsRequires an instanceSPOFLimited to one AZDIY administration

Page 56: Optimizing for Cost in the Cloud

vs.

Producer

SQS queue

Consumers

Consumers

Producer

EC2 instance+ software queue

$0.01 per

10,000 Requests ($0.000001 per Request)

$0.08per hour

(small instance)

Page 57: Optimizing for Cost in the Cloud

#1 Use only what you need (use Auto Scaling Service, modify–db)

#2 Invest time in Reserved Pricing analysis (EC2, RDS)

#3 Architect for Spot Instances (bidding strategies)

#4 Leverage Application Services (ELB, SNS, SQS, SWF, SES)

#5 Implement Caching (ElastiCache, CloudFront)

Optimizing for Cost…

Page 58: Optimizing for Cost in the Cloud

Optimize for performance and cost by page caching and edge-caching static content

caching

Page 59: Optimizing for Cost in the Cloud

When am I charged?Paris

Singapore

London

Amazon Simple Storage Service

(S3)

Edge Location

Edge Location

Edge Location

Client

Client

Client

Amazon Elastic Compute Cloud

(EC2)

Page 60: Optimizing for Cost in the Cloud

When content is popular…Paris

Singapore

London

Amazon Simple Storage Service

(S3)

Edge Location

Edge Location

Edge Location

Client

Client

Client

Amazon Elastic Compute Cloud

(EC2)

Page 61: Optimizing for Cost in the Cloud

Architectural Recommendations

Use Amazon S3 + CloudFront as it will reduce the cost as well as reduce latency for static data• Depends on cache-hit ratio

For Video Streaming, use CloudFront as there is no need of a separate streaming server running Adobe FMSUse managed caching service (Amazon ElastiCache)

Page 62: Optimizing for Cost in the Cloud

#1 Use only what you need (use Auto Scaling Service, modify–db)

#2 Invest time in Reserved Pricing analysis (EC2, RDS)

#3 Architect for Spot Instances (bidding strategies)

#4 Leverage Application Services (ELB SNS, SQS, SWF, SES)

#5 Implement Caching (ElastiCache, CloudFront)

Number of ways to further save with AWS…

Page 63: Optimizing for Cost in the Cloud

[email protected]: @jinman

Thank you!

Page 64: Optimizing for Cost in the Cloud

http://aws.amazon.com

Page 65: Optimizing for Cost in the Cloud

Steady State Usage Pattern

(Example: Corporate Website)

Web Application Usage Patterns

Spiky Predictable Usage Pattern

(Example: Marketing Promotions Website)

Uncertain unpredictable Usage Pattern

(Example: Social game or Mobile Website)

Page 66: Optimizing for Cost in the Cloud

Availability Zone #2

Availability Zone #1

Auto Scaling group : App Tier

Auto Scaling group : Web Tier

Elastic Load Balancer

www.MyWebSite.com(dynamic data)

media.MyWebSite.com (static data)

Amazon Route 53(DNS)

Amazon EC2

Amazon RDS AmazonRDS

Amazon S3

AmazonCloudFront

Example: TCO of a 3-tier Web Application