AWS Lamda Cold Start

AWS Lambda provides many benefits for developers, including scalability, flexibility, faster release times, and reduced cost. However, also comes with limitations such as cold starts. Cold starts can increase the latency of serverless applications

How Does AWS Lambda Work?

Lambda functions run on their own container. When you create a new function, Lambda packages it into a new container. This container is then executed on a multi-tenant cluster of managed machines.

Before the functions start running, each container is allocated its necessary CPU and RAM capacity. When a function finishes running, the allocated RAM is multiplied by the amount of time the function spent running. AWS charges customers based on the allocated memory and the amount of function run time.

AWS Lambda can simultaneously execute many instances of the same function, or of different functions from the same AWS account. This makes Lambda suitable for deploying highly scalable cloud computing solutions.

What Is an AWS Lambda Cold Start?

When running a Lambda function, it stays active as long as you’re running it. It means that your container stays alive, and ready for execution. AWS can drop the container after a period of inactivity, and your function becomes inactive or cold. A cold start happens when you execute an inactive Lambda function. The execution of an inactive Lamda function happens when there are no available containers, and the function needs to start up a new one. A worm start happens when there are available containers.

Spinning up new containers in a cold start creates a delay. That’s why cold starts make serverless applications respond slower.

5 Ways to Reduce the Impact of Lambda Cold Starts

You cannot entirely avoid cold starts, but you can reduce their duration and frequency by using the following tips. to of cold starts:

  1. Prefer dynamically typed languages—use languages like Node.js or Python instead of statically typed programming languages like C# and Java. Dynamically typed languages check what you type during run-time as opposed to compile-time in statically typed languages.
  2. Avoid using Lambdas in Virtual Private Cloud (VPC)—a VPC is an isolated, secure, private cloud hosted on a public cloud. VPC isolates your computing resources from each other, which can increase the delay time and cause cold starts.
  3. Avoid HTTPS calls inside your lambda—SSL handshake and other security-related calls can create cold starts since they are limited by CPU power.
  4. Avoid dependencies—Java dependencies that scan classpath like Spring can cause cold starts. In addition, loading Java classes can take some time and may lead to a cold start.
  5. Increase the memory on AWS Lambda to get more CPU capacity—this can make the execution time of Lambda faster, and also reduce costs compared to lower memory settings.

Comments

Popular posts from this blog

Java 8 : Find the number starts with 1 from a list of integers

Optional Vs Null Check

How to prevent Singleton Class from Reflection and Serialization