Cold Starts in AWS Lambda
This article describes AWS Lambda—the dynamically scaled and billed-per-execution compute service. Instances of Lambdas are added and removed dynamically. When a new instance handles its first request, the response time increases, which is called a cold start.
Read more: Cold Starts in Serverless Functions.
When Does Cold Start Happen?
The very first cold start happens when the first request comes in after deployment.
After that request is processed, the instance stays alive to be reused for subsequent requests. There is no predefined threshold after the instance gets recycled, the empiric data show some variance of the idle period.
The following chart estimates the probability of an instance to be recycled after the given period of inactivity:
Cold starts happen 10 minutes after the previous request. This behavior is different from the past.
Read more: When Does Cold Start Happen on AWS Lambda?
How Slow Are Cold Starts?
The following chart shows the typical range of cold starts in AWS Lambda, broken down per language. The darker ranges are the most common 67% of durations, and lighter ranges include 95%.
View detailed distributions: Cold Start Duration per Language.
Does Package Size Matter?
The above charts show the statistics for tiny “Hello World”-style functions. Adding dependencies and thus increasing the deployed package size will further increase the cold start durations.
Indeed, the functions with many dependencies can be 5-10 times slower to start.
Does Instance Size Matter?
AWS Lambda has a setting to define the memory size that gets allocated to a single instance of a function. Are larger instances faster to load?
There is no visible difference in cold start duration of different instance sizes.
Same comparison for larger functions: Cold Start Duration per Instance Size.
What Is The Effect Of VPC Access?
AWS Lambda might need to access resources inside Amazon Virtual Private Cloud (Amazon VPC). Configuring VPC access slows down the cold starts significantly:
Some VPC-enabled cold starts are still fast, but very often they are much slower and can get up to 14 seconds.
View detailed distributions: Cold Start Duration of VPC-connected Lambda.