AWS Lambda Reserved Concurrency
The feature of Concurrency Limits on Individual AWS Lambda Functions has been announced in 2017.
Each Lambda function includes a new configuration option known as Reserved Concurrency, which is simply a single numerical value which you have the chance to get assigned to your Lambda function’s configuration, through either the web console, or the SDK/CLI:
There are 2 effects resulting from this configuration value being set:
- limiting the number of instances for your Lambda function which may possibly be instantiated whenever needed to the value which you specify.
- Making sure to have a minimum of necessary concurrency capability available in your account for running the number of instances being requested.
In the image taken above, the reserved concurrency for this function has been set to 20. Meaning that a maximum of 20 instances of the Lambda shall be running at whatever time needed.
In addition, the account-wide concurrency limit of 1000, there shall always be 20 units worth available for this chosen function. Which inevitably means that 20 instances will keep on running at all times, with Lambda’s load-based general scale-up + scale-down properties being applied as well. Only if 20 instances are required to be running then Lambda’s platform is capable of doing so, regardless of the other operations occurring in the account.
Outcomes of Reserved Concurrency:
– First ly, we will be able to restrict the bad impact of Lambda functions on downstream systems. For now, it’s possible to allow 10 instances of a Lambda function to run, so as to load-protect the database which this function utilizes.
– Secondly, we will be able for the sake of protection from unintended DoS, to include a couple of critical production Lambda functions needed for ensuring a constantly available capacity to run.
What is Function Level Concurrent Execution Limit?
It’s possible for you to reserve concurrency limit for every function basis and this has the name of Reserved Concurrency. The remaining of the concurrency out of the max allowed concurrency for every region has the name of Unreserved Concurrency.
Screenshot: Lambda reserved concurrency being specified for a given function
A Simple Example of this:
– A: Function having 250 reserved concurrent executions.
– B: Function having 100 reserved concurrent executions.
– C: Function having X value of executions being run at this exact moment.
– D: Function having Y value of executions being run at this exact moment.
Hence, X + Y is going to be = or < 650 (1000 – (250 + 100))
A min of 100 Unreserved concurrent executions are specified per every single region. Which means that the max value of reserved concurrency over every one of the functions per specific region is going to be 900 (1000–100).
Why is Reserved Concurrency Required?
- First, this is because it is very useful for allocating concurrency for a function that requires dedicated priority over all the other functions. While we are reserving our concurrency, at a specified period of time, this selected function is capable of running along with this max value of concurrency while not even getting interrupted or waiting.
- A second reason for it is due to the fact that it can handle the whole load of some other related services that are resources based on special VPC.
Let us take an example of having a lambda function that gets executed through a SQS queue while doing a couple of data processing steps and saving them to a specific relational database located in RDS that lies in a VPC.
It is thus a simple matter that Elastic Network Interfaces include a max value of IP addresses which is dependent on your chosen instance type. Hence, this makes it not being capable of saving data just as in the rate of getting them from Lambda, which result in a bottleneck occurring at the ENI.
This means that it is necessary for us to calculate the max rate that is possible for ENI to manage concurrency while limiting the lambda function’s reserved concurrency as necessary so that there is no overload on ENI.
What are the Lambda Concurrency Metrics?
We have 2 metrics available for the Lambda Concurrency in CloudWatch.
– ConcurrentExecutions
Which refers to the total sum of concurrent executions over every single one of the functions located in one region at a specified point in time.
– UnreservedConcurrentExecutions
Which refers to the total sum of the concurrency of the functions not having a specified custom concurrency limit for a specific region at one specific period of time.