Lambda is part of Serverless offering from AWS. Check a detailed post here:
Although, Lambdas are great but it comes with something called Cold Start.
Cold starts may wreak havoc on Lambda performance, especially if you're working on a customer-facing app that needs to respond in real time. They occur because AWS must deploy your code and spin up a new container before the request can begin if your Lambda is not currently running.
This is the typical Request Life Cycle
The first request handled by a new Lambda worker is known as a "cold start." This request takes a little longer to complete because the Lambda service must:
- Identify a EC2 instance
- Initialize the worker
- Initialize the function module
Cold starts account for fewer than 0.25 percent of Lambda requests, but their impact can be significant. This issue is especially important for applications that require real-time execution or rely on split-second timing.
How to solve the cold start?
Using Provisioned Concurrency
Knowing that the time it takes to configure the computational worker nodes is a key cause of cold starts, AWS Provisioned Concurrency solution is straightforward. Those worker nodes are already up and running! There is no extra code needed, just some clicks and your app is always ready to respond to users without any delay.
The idea is that you can now choose how many of these worker nodes you want to keep initialized for your time-sensitive serverless apps. These worker nodes will be frozen, with your code already downloaded and the underlying container infrastructure in place. As a result of not consuming any resources, the benefit here is a guaranteed response time of approximately double that of the previous method.
However, it comes at a price. From the moment you enable provided concurrency, you'll be charged for it unlike normal lambdas, which charge you only when it executes your code.
Therefore, make sure you are aware of the lambdas which has provisioned concurrency and also the number of concurrency you are assigning.
I created this tool, that you can use to fetch all the functions that have provisioned concurrency. Check the code below:
Steps on adding provisioned concurrency:
- Select the Lambda function you want to add provisioned concurrency
- Select configuration tab and then click concurrency
- Click on Add as below
- Select version of app and the number of concurrency. It will also show the additional cost associated. Finally click save
Hope you liked this. Cheers 🍻