65
© 2015, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Constantin Gonzalez, AWS (@zalez) Markus Ostertag, Team Internet (@Osterjour) October 2015 Running Lean Architectures How to Optimize for Cost Efficiency ARC302

(ARC302) Running Lean Architectures: Optimizing for Cost Efficiency

Embed Size (px)

Citation preview

© 2015, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

Constantin Gonzalez, AWS (@zalez)

Markus Ostertag, Team Internet (@Osterjour)

October 2015

Running Lean ArchitecturesHow to Optimize for Cost Efficiency

ARC302

What You’ll Get out of this Session

• A lower AWS bill

• A more scalable, robust, dynamic architecture

• More time to innovate

• Real-world customer examples

• Easy implementation

AWS Pricing Philosophy

Ecosystem

Global Footprint

New Features

New Services

More AWS

Usage

More

Infrastructure

Lower

Infrastructure

Costs

Reduced

Prices

More

CustomersInfrastructure

Innovation

50 price

reductions

since 2006Economies

of Scale

AWS Trusted Advisor

aws.amazon.com/premiumsupport/trustedadvisor/

Free with Business or Enterprise Support

Iterate to Optimize Cost

Architecting for Low Cost

#1: Turn off Unused Instances

#1: Turn off Unused Instances

• Developer, test, training instances

• Use simple instance start and stop

• Or tear down and build up all together

using AWS CloudFormation

• Instances are disposable!

Customer Example

Monday Friday End of Vacation Season35% saved

#2: Automate

Automate, automate, automate

• AWS SDKs

• AWS CLI

• AWS CloudFormation

• AWS OpsWorks

• Netflix Janitor Monkey

• Cloudlytics EC2 Scheduler

• Auto Scaling

How Auto Scaling Works

AWS CloudFormation Example Launch Configuration

"LaunchConfig": {

"Type" : "AWS::AutoScaling::LaunchConfiguration",

"Metadata" : {

"AWS::CloudFormation::Init" : {

"config" : {

… packages, sources, files, services …

}

}

},

"Properties": {

"ImageId" : "ami-149f7863",

"InstanceType" : "m1.small",

"SecurityGroups" : [ {"Ref" : "WebServerSecurityGroup"} ],

"KeyName" : "MySSHKey",

"UserData" : { "Fn::Base64" : { "Fn::Join" : ["", [

"#!/bin/bash -v\n",

… your user data script …

]]}}

}

}

AWS CloudFormation ExampleAuto Scaling Group Definition

"WebServerGroup" : {

"Type" : "AWS::AutoScaling::AutoScalingGroup",

"Properties" : {

"AvailabilityZones" : [

"us-east-1a","us-east-1b","us-east-1c",

],

"LaunchConfigurationName" : { "Ref" : "LaunchConfig" },

"MinSize" : “3",

"MaxSize" : “6",

"DesiredCapacity" : “3",

"LoadBalancerNames" : [ { "Ref" : "ElasticLoadBalancer" } ]

}

}

Align Resources with Demand

“But my applications are

too small

for Auto Scaling!”

Amazon EC2 Container Service (Amazon ECS)

• Easily manage Docker containers

• Flexible container placement

• Designed for use with other AWS services

• Extensible

• Performance at scale

• Secure

10%

15%

7%

12%

20%

9%

Consolidate with Amazon ECS

App 1 App 2

App 3 App 4

App 5 App 6

6

12 345

Amazon ECS

Cluster

AWS Lambda

Amazon S3 Bucket Events AWS Lambda

Original object Compressed object

1

2

3

Get Rid of Idle Time with AWS Lambda

• Automatic scaling

• Automatic provisioning

• No need to manage infrastructure

• Just bring your code

• $0.20 per million requests, 1M free

• 100 ms payment granularity

• Never pay for idle

Less than 40% utilization?

Consider using AWS Lambda instead!

#3: Use Reserved Instances

Reserved Instance Basics

1y RI

Break even

3y RI

Break even

Reserved Instances Are Flexible

Can be moved between AZs

Can be moved between EC2-Classic

and EC2-VPC platforms

Size can be modified within the same

instance family

Track Savings over Time

Team Internet

Who Is Team Internet?

Domain monetization business

20 people

HQ in Munich, Germany

Tech-focused

DNTX.com

Reserved Instances – Our Usage

How to RI

Our rule of thumb: “An instance that runs 24/7 for more

than two weeks and can’t be stopped right now needs an

RI.”

Amazon EC2 reports to find On-Demand instances

Need to Buy RIs

#4: Use Spot Instances

Spot Instance Rules

• Price based on supply/demand

• You choose your maximum price/hour

• Your instance is started if the Spot price is lower

• Your instance is terminated if

the Spot price is higher, with 2 minutes notice

• But: You did plan for fault tolerance, didn’t you?

Spot Instance Example

On-Demand:

$0.24

$0.028 (11.7%) $0.026 (10,8%)

$3.28

(1367%)

Spot Instance Use Cases

• Stateless web/app server fleets

• Amazon Elastic MapReduce

• Continuous integration (CI)

• High performance computing (HPC)

• Grid computing

• Media rendering/transcoding

aws.amazon.com/ec2/spot

Spot Bid Advisor

Spot Instances Recap

• Very dynamic pricing

• Opportunity to save 80-90% cost• But there are risks

• Different prices per AZ

• Leverage Auto Scaling!• One group with Spot instances

• One group with On-Demand instances

• Get the best of both worlds

• Spot fleets – Manage thousands of

Spot instances with one API call

#5: Leverage Tiered Storage

Amazon S3

• Designed for durability of

99.999999999% of objects

• Designed for 99.99% availability,

with SLA

• Unlimited storage

• High throughput

• Easy to use

• Starting at $0.03 per GB,

automatic volume discounts

Amazon S3 Standard – Infrequent Access

Storage Class

• Same durability, same performance

• Slightly lower availability: 99.9%

• Starting at $0.0125 per GB of storage• Minimum 30 days, minimum 128K billed per object,

$0.01 retrieval cost per GB

• 58% savings over Standard Storage

• Great for backups and near-term archiving

• Use Amazon S3 lifecycle rules!

Amazon Glacier Storage Class

• Same durability, performance, availability

• 3-5 hour restore time

• Starting at $0.007 per GB of storage• Plus $0.05 per 1000 requests,

extra fees for restores beyond 5% of monthly average storage

• 77% savings over Standard Storage

• Long-term archives and backups

• Use Amazon S3 lifecycle rules!

#6: Optimize for Amazon DynamoDB

Optimize Capacity Units

Read/write capacity units (CUs) determine

most of DynamoDB cost

By optimizing CUs, you can save a lot of money

But:

• Need to provision enough capacity to avoid capacity errors

• Need to prepare for peaks

• Need to constantly monitor/adjust

Use caching to save read capacity units

• Local RAM caches at app server instances

• Check out Amazon ElastiCache

Think of strategies for optimizing CU use

• Use multiple tables to support varied access patterns

• Understand access patterns for time series data

• Compress large attribute values

Use Amazon SQS to buffer over-capacity writes

Amazon SQS Can Buffer Requests

Dynamic DynamoDB

DynamoDB GSI Tweak

Adding rows (1.5 KB – 2.5 KB) to table

Querying rows from Global Secondary Index

GSI with projection ALL

table GSI

DynamoDB GSI Tweak

Writes 1 KB, Reads 4 KB

GSI projection KEYS_ONLY

More reads but lesser writes

table GSI

< 1 KB

#7: Offload Your Architecture

Offload Your Architecture

• The more you can offload, the less

infrastructure you need to maintain, scale,

and pay for

• Three easy ways to offload:

• Introduce caching

• Use Amazon CloudFront

• Leverage existing Amazon web services

Cache Everything

MongoDB DynamoDB Amazon RDS

MongoDB DynamoDB Amazon RDS

ElastiCache

MongoDB Queries

Shut down 8 machines

Caching Saves Money

DynamoDB Reads

Saved 3k reads per second

(>20k reads per second in total)

Without negative caching

Cache Really Everything!

With negative caching

Cache hit ratio 25-30% Cache hit ratio 89-95%

Hit

Miss

Offload Popular Traffic to

Amazon S3 and/or CloudFront

Multiple Regions vs. CloudFront

EUAZAZ

USAZAZ

APAZAZ

Some kind of syncing between

the regions

ELB ELB ELB

Multiple Regions vs. CloudFront

AZAZ

CloudFront

EU APUS

ELB

US

Leverage Existing Services

• Amazon RDS, Amazon DynamoDB or Amazon

ElastiCache for Redis, Amazon Redshift• Instead of running your own database

• Amazon CloudSearch• Instead of running your own search engine

• Amazon Elastic Transcoder

• Amazon Elastic MapReduce

• Amazon Cognito, Amazon SQS, Amazon SNS,

Amazon SWF, Amazon SES, Amazon Kinesis,

and more …

Simple, more reliable, lower cost

Cost Monitoring & Analysis

AWS TCO Calculator

AWS Simple Monthly Calculator

AWS Billing Console

AWS Cost Explorer

AWS Billing Alerts

Let’s Recap

1. Turn off unused instances

2. Automate, automate, automate

3. Use Reserved instances

4. Use Spot instances

5. Leverage storage tiering

6. Optimize for Amazon DynamoDB

7. Offload your architecture

Remember to complete

your evaluations!