Does AWS maintain a thread-pool and dispatch concurrent incoming requests to the same Lambda instance, or spin up another instance in these circumstances?
I know that at some load factor another instance will be started, but can I rely on single-threaded access within a Lambda?
Using multithreading in AWS Lambda can speed up your Lambda execution and reduce cost as Lambda charges in 100 ms unit.
The default concurrency limit per AWS Region is 1,000 invocations at any given time. The default burst concurrency quota per Region is between 500 and 3,000, which varies per Region. There is no maximum concurrency limit for Lambda functions.
When the burst concurrency limit is reached, the function starts to scale linearly. If this isn't enough concurrency to serve all requests, additional requests are throttled and should be retried. The function continues to scale until the account's concurrency limit for the function's Region is reached.
A Lambda instance processes one event at the time. If more events arrive before the event is processed, a new instance is spawned. Copied from the AWS Lambda developer guide:
The first time you invoke your function, AWS Lambda creates an instance of the function and runs its handler method to process the event. When the function returns a response, it sticks around to process additional events. If you invoke the function again while the first event is being processed, Lambda creates another instance.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With