Configuring an AWS Lambda function is considered a very complex task because, among all parameters, you will have to pick the memory size for your function, which is very confusing. Developers never test their code’s memory consumption, definitely not in every use case. It then makes us select a random memory size for our function. Not everyone knows, but the memory selection affects proportionally on the allocated CPU. Currently, AWS Lambda supports 128MB up to 3008MB to choose from.

More CPU allocated basically means:

  1. Faster function duration — In some cases it means less latency for your customers!
  2. Higher costsPricing increases proportionally.

But then, the following question arises:

If a function is running faster, will it be cheaper?
So the answer is not that simple. We will try to cover that with the following benchmark and results.

Benchmarking: Fibonacci recursion in Python

To visualize performance results in charts, we built a simple Python code that calculates Fibonacci sequence in recursion and loaded it to a Lambda function.

Fibonacci sequence Loaded to AWS Lambda Function

Fibonacci sequence Loaded to AWS Lambda Function

With an automated benchmark script, we could easily test all possibilities of memory size. The benchmark script already pre-warmed the function so we won’t have any cold start delays.

Results

Without any further ado, let’s explore the chart:

Lambda duration results

AWS Lambda Duration Results

We can definitely observe that (memory) size matters! More memory dramatically reduces duration.

Duration improvement and price

Duration Improvement and Price

Price vs performance

Price vs Performance

As we can see, there’s a high correlation between shorter durations and price differences for different memory sizes. Besides, we see that at some point (2048MB => 3008MB) the performance does not increase at the expected rate, while the price does.

aws lambda memory price and duration performance

Memory, Price, and Duration

AWS Lambda Memory Performance Conclusion

So it’s definitely an important task to pick the right amount of memory for our functions. The tradeoff is potentially higher costs vs. shorter duration times, which leads to lower latency if the function is facing customers and users. Our recommendation is to run a few manual tests on functions to have a clue about their durations and then decide according to the results.

You can find the Fibonacci function with the benchmark script at Epsagon’s open-source repository: lambda-memory-performance-benchmark. Feel free to contribute!

UPDATE: you can now use the benchmark tool to test your own functions! looking forward to seeing results.

More about AWS Lambda:

How to Effectively Monitor AWS Lambda

The Curse of Dead AWS Lambda Functions

Epsagon Achieves AWS Lambda Ready Designation

Exploring AWS Lambda – Part 1

Exploring AWS Lambda – Part 2

The Most Popular Serverless Deployment Tools