In this video, we are going to learn concurrency on a lambda result and provision concurrency.
So I would like to start with the memory and time and configuration optimization.
In the last video we learned configurations of a lambda function and one of the important configuration
was the memory and timeout configurations.
The memory settings determines how much CPU power will receive for our lambda function and higher CPU
power decreased the function execution time.
And we can configure timeout value in order to balance enough time to our function to complete.
And we should set the timeout really carefully because one function which to timeout value and not finished
lambda for beastly stop the execution.
Since function calls is tied to memory allocation and the execution time, we should set the memory
and the timeout configuration according to our use case.
This will optimize our cost and maximize our service competing with lambda functions.
So after that, we have understand the configurations of lambda functions.
Now we can go further to advanced concepts, which is the concurrency.
Concurrency is the number of instances of our function that are actively executing a list is lambda
provides two types of concurrency controls.
One is the reserved concurrency, and second is the provision concurrency.
And we can manage the resort concurrency.
Let me start with explaining what is the concurrency?
Concurrency is the number of requests that are function is working at any given time, but none of the
function is invoked.
Lambda allocates an instance of our functions in order to process the incoming event.
When the function code is finished to running, it can handle another request.
If the function is invoked again, while a request is still being processed, another instance is allocated
which increases the functions concurrency.
The total concurrent number of lambda functions in our account is subject to per region quota.
So we said that there are two types of concurrency controls are available.
Let me start one by one.
I would like to start with the concurrency result.
Concurrency guarantees the maximum number of concurrent instance for our function.
When a function has resolved concurrency, no other function can use that concurrency.
There is no charge for configuring result comprehensive for the function.
And we can configure resolve concurrency from a management console.
If you go to a lambda console and open the function page and choose the function and go to configuration
page, that should be a concurrent setup.
Under the concurrent setup, we can set the reserved concurrency and enter the amount of the concurrency
to resolve that function.
For example, we can set 100.
We can also throttle the function.
So this is one of the important features to go through the function.
In order to throw to a function, we can set the result concurrency to zero.
This stops any events from being processed until we remove the limit.
This is a good way to suddenly stop our executions on environment.
For example, if your function is getting errors for all invocations, we can suddenly shut down the
executions by setting concurrency as a zero.
As you can see the image on the slide.
There are two functions with pools of reserve concurrency and unresolved concurrency pools used by another
function.
Throttling errors occurs when all the concurrency input in use.
You can see these lines are errors because these is the limit of the are executions concurrent executions.
And that's why this is the throttling by a.
Look, we can also set result concurrency configuration with using the commands.
We can use the put function concurrent to command.
You can see the example command command on the slide.
Command is set to resort concurrency as a 100.
And this is using the output function Concurrency Command with the Ada Lovelace Lambda SLI command and
it is return back to us result, concurrency, execution result and it is return back to 100 again.
Look, now, I would like to talk about the adverse lambda provision concurrency as you remember that
this is the second type of concurrency control provision concurrency.
Initialize a requested number of execution environments so that they are prepared to respond immediately
to our function invocation.
So provision concurrency is a name suggested.
We can get the provisioned environment before we invocation happened and these will be prepared.
Initialize the request incoming events and prepared for that environment.
We should know that configuring provisioned concurrency incurs charge to our account.
If you want to decrease latency for our functions, we can use provision concurrency, but it comes
with the cost.
When Lambda allocates an instance of our function for the provision concurrency, the runtime loads
are function code and run initialization code that we define outside of the handled like database clients
and so on.
By this way, the function will be prepared for the invocations.
There is also one more very important topic which is the code start.
If our code or dependencies are very large or we create SDK clients during the initial initialization,
this process can take some time when our function has not been used for some time and needs to scale
up or when we update the function.
Lambda Code is a naive execution environments and these calls that some of the requests cannot be handled
immediately.
It takes some time to spin up the lambda function again and it makes an instance to have higher latency.
And we also call this station is a code start.
Code start is very important terminology when it comes to concurrency on a lambda function.
And we should consider the how we can solve the code, start doing your executions or your function.
So in order to solve these code start problem, we can allocate provision concurrency before an increase
in invocations.
We can ensure that all requests are executed by initialized instance with low latency lambda function
configured with the provision concurrency run with the consistent setup latency and making them ideal
for building interactive mobile and web backend and latency sensitive microservices and synchronous
to invoked APIs.
Lambda also integrates with application auto scaling that allowing to manage provisioned concurrency
on a schedule or based on utilization.
You can see auto scaling provision concurrency on the image of the slide and this is automatically scale
and increase the appropriate concurrency in order to accommodate incoming events and invocations for
a lambda function.
So we can use provisioned concurrency for the solution of the code start, but it comes with the cost.
So that's why we should consider the cost and your invocations together.