Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

(ARC302) Running Lean Architectures: Optimizing for Cost Efficiency

3,840 views

Published on

Whether you’re a cash-strapped startup or an enterprise optimizing spend, it pays to run cost-efficient architectures on AWS. This session reviews a wide range of cost planning, monitoring, and optimization strategies, featuring real-world experience from AWS customers. We’ll cover how you can effectively combine EC2 On-Demand, Reserved, and Spot instances to handle different use cases, leveraging auto scaling to match capacity to workload, choosing the most optimal instance type through load testing, taking advantage of multi-AZ support, and using CloudWatch to monitor usage and automatically shut off resources when not in use. We'll discuss taking advantage of tiered storage and caching, offloading content to Amazon CloudFront to reduce back-end load, and getting rid of your back end entirely, by leveraging AWS high-level services. We will also showcase simple tools to help track and manage costs, including the AWS Cost Explorer, Billing Alerts, and Trusted Advisor. This session will be your pocket guide for running cost effectively in the Amazon cloud.

Published in: Technology

(ARC302) Running Lean Architectures: Optimizing for Cost Efficiency

  1. 1. © 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
  2. 2. 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
  3. 3. 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
  4. 4. AWS Trusted Advisor aws.amazon.com/premiumsupport/trustedadvisor/ Free with Business or Enterprise Support
  5. 5. Iterate to Optimize Cost
  6. 6. Architecting for Low Cost
  7. 7. #1: Turn off Unused Instances
  8. 8. #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!
  9. 9. Customer Example Monday Friday End of Vacation Season 35% saved
  10. 10. #2: Automate
  11. 11. Automate, automate, automate • AWS SDKs • AWS CLI • AWS CloudFormation • AWS OpsWorks • Netflix Janitor Monkey • Cloudlytics EC2 Scheduler • Auto Scaling
  12. 12. How Auto Scaling Works
  13. 13. 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 -vn", … your user data script … ]]}} } }
  14. 14. AWS CloudFormation Example Auto 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" } ] } }
  15. 15. Align Resources with Demand
  16. 16. “But my applications are too small for Auto Scaling!”
  17. 17. 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
  18. 18. 10% 15% 7% 12% 20% 9% Consolidate with Amazon ECS App 1 App 2 App 3 App 4 App 5 App 6 6 12 34 5 Amazon ECS Cluster
  19. 19. AWS Lambda Amazon S3 Bucket Events AWS Lambda Original object Compressed object 1 2 3
  20. 20. 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!
  21. 21. #3: Use Reserved Instances
  22. 22. Reserved Instance Basics 1y RI Break even 3y RI Break even
  23. 23. 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
  24. 24. Track Savings over Time
  25. 25. Team Internet
  26. 26. Who Is Team Internet? Domain monetization business 20 people HQ in Munich, Germany Tech-focused
  27. 27. DNTX.com
  28. 28. Reserved Instances – Our Usage
  29. 29. 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
  30. 30. Need to Buy RIs
  31. 31. #4: Use Spot Instances
  32. 32. 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?
  33. 33. Spot Instance Example On-Demand: $0.24 $0.028 (11.7%) $0.026 (10,8%) $3.28 (1367%)
  34. 34. 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
  35. 35. Spot Bid Advisor
  36. 36. 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
  37. 37. #5: Leverage Tiered Storage
  38. 38. 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
  39. 39. 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!
  40. 40. 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!
  41. 41. #6: Optimize for Amazon DynamoDB
  42. 42. 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
  43. 43. 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
  44. 44. Amazon SQS Can Buffer Requests
  45. 45. Dynamic DynamoDB
  46. 46. 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
  47. 47. DynamoDB GSI Tweak Writes 1 KB, Reads 4 KB GSI projection KEYS_ONLY More reads but lesser writes table GSI < 1 KB
  48. 48. #7: Offload Your Architecture
  49. 49. 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
  50. 50. Cache Everything MongoDB DynamoDB Amazon RDS MongoDB DynamoDB Amazon RDS ElastiCache
  51. 51. MongoDB Queries Shut down 8 machines Caching Saves Money DynamoDB Reads Saved 3k reads per second (>20k reads per second in total)
  52. 52. Without negative caching Cache Really Everything! With negative caching Cache hit ratio 25-30% Cache hit ratio 89-95% Hit Miss
  53. 53. Offload Popular Traffic to Amazon S3 and/or CloudFront
  54. 54. Multiple Regions vs. CloudFront EU AZAZ US AZAZ AP AZAZ Some kind of syncing between the regions ELB ELB ELB
  55. 55. Multiple Regions vs. CloudFront AZAZ CloudFront EU APUS ELB US
  56. 56. 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
  57. 57. Cost Monitoring & Analysis
  58. 58. AWS TCO Calculator
  59. 59. AWS Simple Monthly Calculator
  60. 60. AWS Billing Console
  61. 61. AWS Cost Explorer
  62. 62. AWS Billing Alerts
  63. 63. 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
  64. 64. Thank you! glez@amazon.com markus@teaminternet.de
  65. 65. Remember to complete your evaluations!

×