Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Will 2 threads ever access my Java AWS Lambda concurrently?

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?

like image 861
Duncan McGregor Avatar asked Jun 22 '17 06:06

Duncan McGregor


People also ask

Can AWS Lambda have multiple threads?

Using multithreading in AWS Lambda can speed up your Lambda execution and reduce cost as Lambda charges in 100 ms unit.

Can Lambda handle concurrent requests?

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.

What happens when Lambda concurrency is reached?

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.


1 Answers

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.

like image 183
matsev Avatar answered Sep 28 '22 04:09

matsev