LocalStack to the Max - Invoking 50 Functions

LocalStack to the Max - Invoking 50 Functions

·

2 min read

Ok, we’ve been pretty serious so far, so let’s take a few moments to step outside of our day-to-day software-building responsibilities and try something new.

I received this question a few times and thought it was finally time to put it to the test: Can you create X Lambdas on LocalStack?

Let’s see what happens when we want to create 50 Lambdas and invoke them sequentially…twice. It’s for science, ok?

The code and the scripts for creating and invoking the functions can be found, as always, in the Stack Bytes repository.

The setup is pretty basic: We have a Lambda function that takes an input and prints out a message using said input. To make it less boring and more unique, each function will receive its own number. We use the local AWS CLI to create all the functions using a loop, meaning this will take a while. So let’s take out our time measuring devices and see:

I was surprised it only took approximately two minutes to create 50 Lambdas. I don’t want to know how long this would take on AWS. But while we’re on the topic, a bit of a disclaimer: my setup is, by today’s standards (Aug. 2023), on the middle-upper side. There are people out there getting by with a lot less and others with a lot more, but as a developer, I’d say it’s a good place to be in:

Now think of all the things one can do with all the fancy new chips.

Let’s move on and invoke all 50 of our Lambdas:

A little discouraging and slightly disappointing that it wasn’t exactly the 5-minute mark. And if we check the logs of a randomly picked container, the message is there as expected:

The slow invocations happen because the Lambda environment provisions resources and initializes the runtime environment to execute the function code. For Java Lambda functions, this includes starting the JVM, loading classes, and performing any initialization tasks specified in your code or dependencies.

Once the Lambda function is "warmed up," meaning the runtime environment is initialized, subsequent invocations of the function are typically faster because the JVM is already running. Let’s check again with the warm starts, the second round of invocations:

Now that’s more like it. And with the dawn of the CRaC project, I’m really excited to leave the cold starts in the past.

PS: I’m looking forward to reading your stories of taking things even further ;).