Slide 1

Slide 1 text

© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved. AWS Lambda function performance tuning Alex Casalboni S V S 2 2 4 - R Technical Evangelist Amazon Web Services

Slide 2

Slide 2 text

Agenda Fundamentals & news Optimization best practices AWS Lambda Power Tuning Real-world examples Whiteboard discussion

Slide 3

Slide 3 text

© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.

Slide 4

Slide 4 text

© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved. “So what does the future look like? All the code you ever write is business logic.” Dr. Werner Vogels CTO of Amazon.com

Slide 5

Slide 5 text

AWS operational responsibility models On-premises Cloud Less More Compute Virtual machine Amazon EC2 AWS Elastic Beanstalk AWS Lambda AWS Fargate Databases MySQL MySQL on EC2 Amazon RDS MySQL Amazon Aurora Aurora Serverless Amazon QLDB/DynamoDB Storage Storage Amazon S3 Messaging ESBs Amazon MQ Amazon Kinesis Amazon EventBridge/SNS/SQS Analytics Hadoop Hadoop on EC2 Amazon EMR Amazon Elasticsearch Service Amazon Athena

Slide 6

Slide 6 text

© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.

Slide 7

Slide 7 text

Provisioned Concurrency for AWS Lambda Simple config to avoid cold starts No more manual pre-warming Predictable performance during spikes Good fit for latency-sensitive apps No code changes required Bound to version or alias AWS CloudFormation support Scheduling with AWS Application Auto Scaling From 1 to account concurrency limit Two new metrics Ramp-up time (500 per minute) Initialization code is executed automatically

Slide 8

Slide 8 text

Provisioned Concurrency for AWS Lambda

Slide 9

Slide 9 text

Provisioned Concurrency for AWS Lambda

Slide 10

Slide 10 text

Monitoring Deployment frameworks

Slide 11

Slide 11 text

© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.

Slide 12

Slide 12 text

Cost & performance optimization best practices Avoid «monolithic» functions Optimize dependencies (and imports) Minify/uglify production code Lazy initialization of shared libs/objs Externalize orchestration Fine-tune resources allocation Lambda Destinations Discard uninteresting events asap Keep in mind retry policies Understand currency controls

Slide 13

Slide 13 text

Cost & performance optimization best practices Avoid «monolithic» functions Optimize dependencies (and imports) Minify/uglify production code Lazy initialization of shared libs/objs Externalize orchestration Fine-tune resources allocation Lambda Destinations Discard uninteresting events asap Keep in mind retry policies Understand currency controls

Slide 14

Slide 14 text

Resources allocation Memory Power

Slide 15

Slide 15 text

CPU-bound example “Compute 1,000 times all prime numbers <= 1M” 128 MB 11.722 sec $0.024628 256 MB 6.678 sec $0.028035 512 MB 3.194 sec $0.026830 1024 MB 1.465 sec $0.024638

Slide 16

Slide 16 text

CPU-bound example “Compute 1,000 times all prime numbers <= 1M” 128 MB 11.722 sec $0.024628 256 MB 6.678 sec $0.028035 512 MB 3.194 sec $0.026830 1024 MB 1.465 sec $0.024638

Slide 17

Slide 17 text

CPU-bound example

Slide 18

Slide 18 text

Cost-aware performance optimization 310ms 400ms 294ms 300ms 5% performance optimization 25% cost optimization 480ms 500ms 408ms 500ms 15% performance optimization 0% cost optimization A B

Slide 19

Slide 19 text

© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.

Slide 20

Slide 20 text

“AWS Lambda Power Tuning” Data-driven cost & performance optimization for AWS Lambda Available as a SAR app Easy to integrate with CI/CD Don’t guesstimate! v1 github.com/alexcasalboni/aws-lambda-power-tuning

Slide 21

Slide 21 text

v2 github.com/alexcasalboni/aws-lambda-power-tuning

Slide 22

Slide 22 text

v3 github.com/alexcasalboni/aws-lambda-power-tuning

Slide 23

Slide 23 text

github.com/alexcasalboni/aws-lambda-power-tuning v1 v2 v3

Slide 24

Slide 24 text

AWS Lambda Power Tuning (input) github.com/alexcasalboni/aws-lambda-power-tuning

Slide 25

Slide 25 text

AWS Lambda Power Tuning (input) github.com/alexcasalboni/aws-lambda-power-tuning

Slide 26

Slide 26 text

AWS Lambda Power Tuning (input) github.com/alexcasalboni/aws-lambda-power-tuning

Slide 27

Slide 27 text

AWS Lambda Power Tuning (input) github.com/alexcasalboni/aws-lambda-power-tuning

Slide 28

Slide 28 text

AWS Lambda Power Tuning (input) github.com/alexcasalboni/aws-lambda-power-tuning

Slide 29

Slide 29 text

AWS Lambda Power Tuning (input) github.com/alexcasalboni/aws-lambda-power-tuning

Slide 30

Slide 30 text

AWS Lambda Power Tuning (output) github.com/alexcasalboni/aws-lambda-power-tuning

Slide 31

Slide 31 text

AWS Lambda Power Tuning (visualization) github.com/alexcasalboni/aws-lambda-power-tuning

Slide 32

Slide 32 text

© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.

Slide 33

Slide 33 text

No-Op (trivial data manipulation <100ms) github.com/alexcasalboni/aws-lambda-power-tuning

Slide 34

Slide 34 text

CPU-bound (numpy: inverting 1500x1500 matrix) github.com/alexcasalboni/aws-lambda-power-tuning

Slide 35

Slide 35 text

CPU-bound (prime numbers) github.com/alexcasalboni/aws-lambda-power-tuning

Slide 36

Slide 36 text

CPU-bound (prime numbers – more granularity) github.com/alexcasalboni/aws-lambda-power-tuning

Slide 37

Slide 37 text

Network-bound (third-party API call) github.com/alexcasalboni/aws-lambda-power-tuning

Slide 38

Slide 38 text

Network-bound (3x DDB queries) github.com/alexcasalboni/aws-lambda-power-tuning

Slide 39

Slide 39 text

Network-bound (S3 download – 150MB) github.com/alexcasalboni/aws-lambda-power-tuning

Slide 40

Slide 40 text

Network-bound (S3 download multithread – 150MB) github.com/alexcasalboni/aws-lambda-power-tuning

Slide 41

Slide 41 text

Cost/Performance patterns github.com/alexcasalboni/aws-lambda-power-tuning

Slide 42

Slide 42 text

Takeaways Memory Power Avoid cold starts with Provisioned Concurrency Optimal resources allocation can be automated (CI/CD) Think in terms of workload categories and cost/performance patterns Visualize optimal trade-offs with /alexcasalboni/aws-lambda-power-tuning

Slide 43

Slide 43 text

© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.

Slide 44

Slide 44 text

Thank you! © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved. Alex Casalboni [email protected] @alex_casalboni