AWS Lambda at Scale - ITBA
AWS Lambda at Scale - ITBA
MANAGED SERVICE
U N T
ACCO NCY COLD S
TARTS
U R R E
CONC
EXECUTION THROTTLING
COSTS
BURST
LAMBDA @ SCALE CONCURRENCY ALEXIS CUADRADO
A SCHEDULED JOB
check age of access keys 2
IAM
1 3 4
notify
trigger daily noncompliance send email
IAM User
EventBridge SNS
Lambda Function
Downstream services
Internet
API Gateway Lambda Function
Booking service
Other function
Downstream services
1M+
requests per minute
(RPM)
Internet
API Gateway Lambda Function
Booking service
Other function
TIME
$
COST PER
LATENCY THROUGHPUT TRANSACTION
seconds or milliseconds transactions per second (TPS) USD
1
STATIC CODE
HANDLER CODE
4 5
2
3 RUNTIME
EXECUTION ENVIRONMENT
COMPUTE SUBSTRATE
1 2 3 4 5
Download Code Start Environment Bootstrap Runtime Run Static Code Run Handler
1 2 3
invocation
initializing
EXECUTION ENVIRONMENT executing
available
TIME
E1 2 5
cold start
invocation
E2
initializing
executing
available
1 2 3 4 5
Download Code Start Environment Set up Runtime Run Static Code Run Handler
1 2 3 4 5
Download Code Start Environment Bootstrap Runtime Run Static Code Run Handler
C
EMPLOY EFFICIENT ALGORITHMS D
MULTI-THREADING
Put those hard-won Parallelize I/O operations
whiteboarding skills to use (e.g. S3 downloads)
1 2 3 4 5
Download Code Start Environment Set up Runtime Run Static Code Run Handler
Download Code Start Environment Set up Runtime Run Static Code Run Handler
.NET
1 2 3 4 5
Download Code Start Environment Set up Runtime Run Static Code Run Handler
1 2 3 4 5
Download Code Start Environment Set up Runtime Run Static Code Run Handler
1 2 3
TIPS:
20 MB • Audit and remove unused dependencies
• Use minifiers (e.g. node-minify)
1 2 3 4 5
? ?
HOW CAN WE GET MORE OF THIS?
E1 3
E2 4
E3
TIME
t₀ concurrency = 1 t₁ t₂ concurrency = 3
E1 2 5
E2 NO COLD STARTS! 3
E3
TIME
t₀ t₁ requests start arriving
LAMBDA @ SCALE ALEXIS CUADRADO
AUTOSCALING
DEMAND /
CONCURRENCY
TIME
= 500 ms = 4 TPS
= 500 ms
= 4 TPS 1 2
=2
1 2 3 4 =1 3 4
1 2 3 4 1 2 3 4 5 6 7 8 9 10
250 ms 100 ms
1 sec
2 4
1 2 3 4 5
= 8 TPS
6 7 8
125 ms
? 50 ms
=1
LAMBDA @ SCALE ALEXIS CUADRADO
OH, THE RATE LIMITS
3
= 10 TPS
1 2 3 4 5 6 7 8 9 10
100 ms
ASYNCHRONOUS SYNCHRONOUS
4A INVOCATIONS 4B INVOCATIONS
No limit! Throughput capped due to rate limiting
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 1 2 3 4 5 6 7 8 9 10
50 ms 50 ms
E999
E1000 X
THROTTLED
TIME
concurrency = 1000 X
ANOTHER FUNCTION
E100 concurrency = 200
E1
OUR FUNCTION
concurrency = 800
E800
TIME
X
LAMBDA @ SCALE ALEXIS CUADRADO
RESERVED CONCURRENCY
E1
OUR FUNCTION
E300 concurrency = 300
reserved concurrency = 900
E1
ANOTHER FUNCTION
concurrency = 100
E100 -1900
TIME
X
LAMBDA @ SCALE ALEXIS CUADRADO
R
NO MORE THAN YOU DESERVE
E1
E2
OUR FUNCTION
E3 concurrency = 1900
reserved concurrency = 1900
E1900 X
THROTTLED
TIME
X
LAMBDA @ SCALE ALEXIS CUADRADO
BURST CONCURRENCY (OR HOW FAST CONCURRENCY CAN RISE)
ACCOUNT THROTTLE ZONE BURST QUOTA = 3000 ACCOUNT CONCURRENCY = 5000
Super
0 0
5K
CONCURRENCY (UNITS)
FUNCTION CONCURRENCY
2K AVAILABLE BURST
2500 2500
1K
3000
alexcasalboni/aws-lambda-power-tuning
LAMBDA @ SCALE ALEXIS CUADRADO
ARM YOURSELF (WITH GRAVITON2)
COST
LATENCY
@alexscuadrado
/in/alexis-cuadrado
alexis.hashnode.dev