Serverless Tip #17: Don’t overprovision your Lambda functions
For Lambda functions, you can not directly set the CPU you want your functions to have. Instead, you pick a memory configuration between 128 MB and 10 GB, and your function will get CPU performance proportional to that.
With Lambda, you are billed for GB-seconds. Increasing the memory can reduce your execution times while keeping costs constant if your function is CPU-bound.
If your function code cannot use multiple cores, giving them too much memory will only increase costs without increasing performance.
Want to know how much CPU you’ll have at each memory breakpoint? While the actual numbers are not documented by AWS, an old study found the following:
Memory (MB) | vCPU | CPU Ceiling |
---|---|---|
832 | 2 | 0.50 |
1769 | 2 | 1.00 |
3008 | 2 | 1.67 |
3009 | 3 | 1.70 |
5307 | 3 | 2.39 |
5308 | 4 | 2.67 |
7076 | 4 | 2.84 |
7077 | 5 | 3.86 |
8845 | 5 | 4.23 |
8846 | 6 | 4.48 |
10240 | 6 | 4.72 |
So, for a single-threaded application, going above 1769 MB might not have any effect on your execution times, unless you need the extra memory.
To find the optimal configuration for your functions regarding cost vs. performance, profile them with the AWS Lambda Power Tuning tool.