Reputation: 329
I've got a question and I would love to get an answer.
I've a Lambda function that uses Max memory of 31 MB and the allocated memory configured is 128MB it would take 2556.68 ms.
However, when increasing the allocated memory to max 1536 MB it takes only 621.81 ms to be fully executed and the MAX memory used is exactly the same 31 MB.
Why the Lambda function executed much faster when used memory is exactly the same in the two cases?
Upvotes: 4
Views: 3393
Reputation: 178984
This is because the amount of CPU your containers are allocated is proportional to the amount of memory you ask for.
AWS Lambda allocates CPU power proportional to the memory by using the same ratio as a general purpose Amazon EC2 instance type, such as an M3 type. For example, if you allocate 256 MB memory, your Lambda function will receive twice the CPU share than if you allocated only 128 MB.
http://docs.aws.amazon.com/lambda/latest/dg/lambda-introduction-function.html
M3 instances have 8 Xeon E5-2670 or Xeon E5-2670 V2 hyperthreads per 30 GB of RAM, so at that ratio, with 1.5GB of memory, you have approximately 1.5 × (8 ÷ 30) × 2.6 GHz ≅ 1 GHz of CPU. At 128 MB you have only about 1/12 of that.
Upvotes: 8
Reputation: 81336
When you increase the memory allocated to Lambda functions, you also get an increase in CPU power. Note that increasing memory also increase the cost.
Q: How are compute resources assigned to an AWS Lambda function?
In the AWS Lambda resource model, you choose the amount of memory you want for your function, and are allocated proportional CPU power and other resources. For example, choosing 256MB of memory allocates approximately twice as much CPU power to your Lambda function as requesting 128MB of memory and half as much CPU power as choosing 512MB of memory. You can set your memory in 64MB increments from 128MB to 1.5GB.
Upvotes: 2