SlideShare a Scribd company logo
1 of 31
BY ALEXIS CUADRADO
AWSLAMBDA@SCALE
DESIGNING FOR HIGH LOAD
LAMBDA @ SCALE #NERDEARLA
LOOK, IT SCALES
AUTOMATICALLY!
MANAGED SERVICE
ACCOUNT
CONCURRENCY
COLD STARTS
THROTTLING
BURST
CONCURRENCY
EXECUTION
COSTS
GETTINGOURLAMBDAFUNCTIONSTO
PERFORMASREQUIRED
THE CHALLENGE OF SCALE
THREEPERFORMANCEINDICATORS
$
LATENCY THROUGHPUT
COSTPER
TRANSACTION
seconds or milliseconds transactions per second (TPS) USD
MINIMIZE MAXIMIZE MINIMIZE
TIP: Define proper Service Level Objectives (SLOs)
LAMBDA @ SCALE #NERDEARLA
(meet demand)
MINIMIZING LATENCY
BY ALEXIS CUADRADO
AWSLAMBDA@SCALE
MAKE EVERY MILLISECOND COUNT
ANATOMYOFALAMBDAINVOCATION
1
2
RUNTIME
3
COMPUTE SUBSTRATE
EXECUTION ENVIRONMENT
HANDLER CODE
STATIC CODE
4 5
Download Code Start Environment Bootstrap Runtime Run Static Code Run Handler
1 2 3 4 5
LAMBDA @ SCALE #NERDEARLA
initializing
executing
available
invocation
LONGLIVETHEEXECUTIONENVIRONMENT!
1 2 3
TIME
EXECUTION ENVIRONMENT
LAMBDA @ SCALE #NERDEARLA
STARTEDONTHECOLDFOOT
initializing
executing
available
invocation
1
2
3
E1
E2
4
5
cold start
Download Code Start Environment Set up Runtime Run Static Code Run Handler
1 2 3 4 5
LAMBDA @ SCALE #NERDEARLA
DISSECTING LATENCY
Download Code Start Environment Bootstrap Runtime Run Static Code Run Handler
1 2 3 4 5
COLD START ( INITIALIZATION ) EXECUTION
LAMBDA @ SCALE #NERDEARLA
OPTIMIZEHANDLERLOGIC
EMPLOY EFFICIENT ALGORITHMS
A B
C
Put those hard-won
whiteboarding skills to use
Parallelize I/O operations
(e.g. S3 downloads)
Use Step Functions
LAMBDA @ SCALE #NERDEARLA
AVOID ORCHESTRATION
MOVE WORK OUTSIDE HANDLER
D
MULTI-THREADING
Download Code Start Environment Set up Runtime Run Static Code Run Handler
1 2 3 4 5
Reusable objects should be
statically initialized
TURNUPTHERAM!
Example Python Function: Return all prime numbers between 0 and 10K
MEMORY (MB) EXECUTION DURATION (MS)
128 170
256 80
512 40
1024 20
1536 17
3008 17
MEMORY = vCPU NETWORK THROUGHPUT
lowest latency
negative returns beyond this point
Beware of
LAMBDA @ SCALE #NERDEARLA
Download Code Start Environment Set up Runtime Run Static Code Run Handler
1 2 3 4 5
TIP: Enable Lambda Insights for profiling
STATICINITIALIZATIONDONERIGHT
+ 120 ms
LAMBDA @ SCALE #NERDEARLA
Download Code Start Environment Set up Runtime Run Static Code Run Handler
1 2 3 4 5
PACKAGESIZEMATTERS
Download Deployment Package Start Environment Bootstrap Runtime
Download Deployment
Package
Start Environment Bootstrap Runtime Run Static Code
Run
Handler
50 MB
20 MB
TIPS:
• Audit and remove unused dependencies
• Use minifiers (e.g. node-minify)
LAMBDA @ SCALE #NERDEARLA
1
1
3 4 5
2
3
2
ONCOLDSTARTFREQUENCY
LAMBDA @ SCALE #NERDEARLA
?
?
?
? COLD
WARM
Isn’t that what we’re all asking in our own lives?
HOW CAN WE GET MORE OF THIS?
... AND LESS OF THIS?
CONCURRENCY
t₀ t₁
E3
concurrency = 1 t₂
E1
E2
concurrency = 3
1 2
3
4
TIME
LAMBDA @ SCALE #NERDEARLA
PROVISIONALLTHECONCURRENCY!
t₀
E3
E1
E2
provisioned concurrency = 3
1
2
3
4
5
t₁
concurrency is provisioned
requests start arriving
TIME
NO COLD STARTS!
LAMBDA @ SCALE #NERDEARLA
AUTOSCALING
TIME
DEMAND /
CONCURRENCY
LAMBDA @ SCALE #NERDEARLA
MAXIMIZING
BY ALEXIS CUADRADO
AWSLAMBDA@SCALE
THROUGHPUT
LEAVE NO REQUEST BEHIND
AFUNCTION’STHROUGHPUT
1 2
1 2
1 2 3 4
= 2 TPS
THROUGHPUT =
CONCURRENCY
LATENCY
= 4 TPS
= 4 TPS
= 500 ms
= 1
= 500 ms
= 500 ms = 500 ms
= 2
= 250 ms = 250 ms = 250 ms = 250 ms
= 1 3 4
LAMBDA @ SCALE #NERDEARLA
REDUCINGLATENCYTOGAINTHROUGHPUT
250 ms
1 2 3 4 5 6 7 8
1 2 3 4 5 6 7 8 9 10
1 2 4
3
= 4 TPS
1 sec
100 ms
50 ms
125 ms
1
2
3
4
= 8 TPS
= 10 TPS
= 1
LAMBDA @ SCALE #NERDEARLA
?
OH,THERATELIMITS
1 2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 7 8 9 10
100 ms
50 ms
50 ms
4A
3
4B
= 20 TPS
= 10 TPS
= STILL 10 TPS
= 1
Throughput capped due to rate limiting
Additional invocations will increase
concurrency or be throttled
LAMBDA @ SCALE #NERDEARLA
1 3 5 7 9 11 13 15 17 19
2 4 6 8 10 12 14 16 18 20
ASYNCHRONOUS
INVOCATIONS
SYNCHRONOUS
INVOCATIONS
No limit!
ACCOUNTCONCURRENCY
TIME
E1
E100
E1
E800
THROTTLED
X
concurrency = 200
concurrency = 800
account concurrency = 1000
ANOTHER FUNCTION
OUR FUNCTION
LAMBDA @ SCALE #NERDEARLA
Everyone gets their share
RESERVEDCONCURRENCY
TIME
E1
E300
E1
E100
THROTTLED
X
concurrency = 300
concurrency = 100
account concurrency = 1000
OUR FUNCTION
ANOTHER FUNCTION
reserved concurrency = 900
-1900
LAMBDA @ SCALE #NERDEARLA
BURSTCONCURRENCY
TIME (MINUTES)
CONCURRENCY
(UNITS)
5K
3000
2500
1000 1500
1000
0 0
500 1000
2500
1
0 3
2 4 6
5 7 9
8
2K
1K
3K
4K
+500 +500 +500 +500
+0 +0 +0 +500 +500
BURST QUOTA = 3000
AVAILABLE BURST
ACCOUNT CONCURRENCY = 5000
BURST THROTTLE ZONE
ACCOUNT THROTTLE ZONE
BURST THROTTLE ZONE
FUNCTION CONCURRENCY
Super
(OR HOW FAST CONCURRENCY CAN RISE)
LAMBDA @ SCALE #NERDEARLA
MINIMIZING
BY ALEXIS CUADRADO
AWSLAMBDA@SCALE
$ COSTS
GET THE BIGGEST BANG FOR YOUR BUCK
HOWLAMBDAPRICINGWORKS
$
COSTPER
TRANSACTION
also COST PER EXECUTION
$
= COMPUTE
CHARGES
REQUEST
CHARGES
Rates vary based on Region and CPU Architecture
Free Tier available
Elegible for Savings Plans
fixed fee per request
EXECUTION
DURATION
ALLOCATED
MEMORY
LATENCY
determines
influences
LAMBDA @ SCALE #NERDEARLA
POWERTUNING
alexcasalboni/aws-lambda-power-tuning
OPTIMAL
MEMORY
CONFIGURATION
LAMBDA @ SCALE #NERDEARLA
ARMYOURSELF(WITHGRAVITON2)
COST
LATENCY
LAMBDA @ SCALE #NERDEARLA
PUTTINGITALLTOGETHER
BY ALEXIS CUADRADO
AWSLAMBDA@SCALE
BEFORE OUR BRAINS BURST
WHATWE(HOPEFULLY)LEARNEDTODAY
KEY PERFORMANCE METRICS
Getting our Lambda Functions to perform as required
THE CHALLENGE OF SCALE
COLD STARTS
HOW LAMBDA PROCESSES INVOCATIONS
Execution Environments
CONCURRENCY
HOW LAMBDA SCALES
HOW PRICING WORKS
QUOTAS
CONTROLS
ACCOUNT CONCURRENCY
BURST CONCURRENCY
PROVISIONED CONCURRENCY
RESERVED CONCURRENCY
(how fast)
(how much)
(pre-warm)
(set aside)
POWER TUNING
$
LATENCY - THROUGHPUT - COST PER TRANSACTION
WHAT FACTORS AFFECT LATENCY
THROUGHPUT CONSIDERATIONS
Interplay between memory, execution time and costs
COLD START EXECUTION
Rate Limits, Concurrency Quotas and Controls
Relation to Latency and Concurrency
OPTIMIZATION TECHNIQUES Price-performance gains with arm64 (Graviton2)
LAMBDA @ SCALE #NERDEARLA
LAMBDA @ SCALE #NERDEARLA
THANKYOU
@alexscuadrado
/in/alexis-cuadrado
FOLLOW ME
𝕏
alexis.hashnode.dev

More Related Content

Similar to AWS Lambda at Scale.pdf

Similar to AWS Lambda at Scale.pdf (20)

Scaling Twitter
Scaling TwitterScaling Twitter
Scaling Twitter
 
Load testing with Blitz
Load testing with BlitzLoad testing with Blitz
Load testing with Blitz
 
SDPHP - Percona Toolkit (It's Basically Magic)
SDPHP - Percona Toolkit (It's Basically Magic)SDPHP - Percona Toolkit (It's Basically Magic)
SDPHP - Percona Toolkit (It's Basically Magic)
 
SQL and PLSQL features for APEX Developers
SQL and PLSQL features for APEX DevelopersSQL and PLSQL features for APEX Developers
SQL and PLSQL features for APEX Developers
 
Samplab19
Samplab19Samplab19
Samplab19
 
AWS Lambda from the trenches
AWS Lambda from the trenchesAWS Lambda from the trenches
AWS Lambda from the trenches
 
PagerDuty | OSCON 2016 Failure Testing
PagerDuty | OSCON 2016 Failure TestingPagerDuty | OSCON 2016 Failure Testing
PagerDuty | OSCON 2016 Failure Testing
 
Big data meetup 2012 01-18 - stripped
Big data meetup 2012 01-18 - strippedBig data meetup 2012 01-18 - stripped
Big data meetup 2012 01-18 - stripped
 
Getting Buzzed on Buzzwords: Using Cloud & Big Data to Pentest at Scale
Getting Buzzed on Buzzwords: Using Cloud & Big Data to Pentest at ScaleGetting Buzzed on Buzzwords: Using Cloud & Big Data to Pentest at Scale
Getting Buzzed on Buzzwords: Using Cloud & Big Data to Pentest at Scale
 
Apache Spark Core—Deep Dive—Proper Optimization
Apache Spark Core—Deep Dive—Proper OptimizationApache Spark Core—Deep Dive—Proper Optimization
Apache Spark Core—Deep Dive—Proper Optimization
 
Reactor, Reactive streams and MicroServices
Reactor, Reactive streams and MicroServicesReactor, Reactive streams and MicroServices
Reactor, Reactive streams and MicroServices
 
Crystal is a Rubyists friend (quick anecdote)
Crystal is a Rubyists friend (quick anecdote)Crystal is a Rubyists friend (quick anecdote)
Crystal is a Rubyists friend (quick anecdote)
 
Simplereach: Counters at Scale: A Cautionary Tale
Simplereach: Counters at Scale: A Cautionary TaleSimplereach: Counters at Scale: A Cautionary Tale
Simplereach: Counters at Scale: A Cautionary Tale
 
Counters At Scale - A Cautionary Tale
Counters At Scale - A Cautionary TaleCounters At Scale - A Cautionary Tale
Counters At Scale - A Cautionary Tale
 
Enterprise Network Manager: the Router-On-A-stick
Enterprise Network Manager: the Router-On-A-stickEnterprise Network Manager: the Router-On-A-stick
Enterprise Network Manager: the Router-On-A-stick
 
1.1 Intro to WinDDI.pdf
1.1 Intro to WinDDI.pdf1.1 Intro to WinDDI.pdf
1.1 Intro to WinDDI.pdf
 
Active Record & SQL - Bulk Insert
Active Record & SQL - Bulk InsertActive Record & SQL - Bulk Insert
Active Record & SQL - Bulk Insert
 
MLflow with R
MLflow with RMLflow with R
MLflow with R
 
Reactive Microservices with JRuby and Docker
Reactive Microservices with JRuby and DockerReactive Microservices with JRuby and Docker
Reactive Microservices with JRuby and Docker
 
Serverless in production, an experience report (LNUG)
Serverless in production, an experience report (LNUG)Serverless in production, an experience report (LNUG)
Serverless in production, an experience report (LNUG)
 

Recently uploaded

introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
VishalKumarJha10
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
mohitmore19
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 

Recently uploaded (20)

introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
Exploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfExploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdf
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdf
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfPayment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK Software
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 

AWS Lambda at Scale.pdf