Skip to content

How to increase "Max Memory Used" as a percentage of Memory Size

0

Here is the CloudWatch report for my Python code run on Lambda

REPORT RequestId: da084fb0-ed9d-4c5e-8d8d-dc8ac32b6f32	Duration: 21647.42 ms	Billed Duration: 21648 ms	Memory Size: 1500 MB	Max Memory Used: 244 MB	Init Duration: 637.73 ms

Only 244 MB used out of 1500 MB. Seems a huge waste of money! But I have tried other memory sizes, and 1500MB gives me the best overall cost. Setting the memory size at 256MB make the running time ~200s instead of 21.6s now. So how to increase "Max Memory Used"? If increasing "Max Memory Used" is possible, will there be a significant reduction in computation time? Thanks

asked a year ago379 views
2 Answers
3

Hello, you can have a look at these references: https://towardsdatascience.com/optimize-aws-lambda-memory-more-memory-doesnt-mean-more-costs-51ba566fecc7 https://docs.aws.amazon.com/lambda/latest/operatorguide/computing-power.html

As the posts mentioned, "increases the amount of CPU, increasing the overall computational power available. If a function is CPU-, network- or memory-bound, then changing the memory setting can dramatically improve its performance." And the Max Memory Used is depended on your code and it's not configured in Lambda. So you could fine tune the code if you want to improve the computation time.

answered a year ago
EXPERT
reviewed a year ago
EXPERT
reviewed a year ago
EXPERT
reviewed a year ago
  • Thanks for your answer. As I explained in the question, I have tried many memory settings and 1500ms gives me the lowest cost=time*memory. Given my situation what is the best strategy to increase memory usage in Python?

  • You're welcome. As I mentioned, it depends on your code and what your function is going to do. If you would like to improve the computation time, the direction should not be only to increase memory usage. You may need to use another algorithm or data structure to improve the performance. So it falls into the performance tuning for python code.

1

The more memory you give your function, the more CPU you get. At ~1760MB, you get a full core. If you function is CPU bound, this will help it run faster, and therefor cost less.

Memory used depends on your application. There is no need to consume more memory of you do not need it. If your code can run faster by utilizing more memory, e.g., using memoization, please do so. You can also create multiple threads, which will probably consume more memory, and can potentially reduce the duration.

AWS
EXPERT
answered a year ago
EXPERT
reviewed a year ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.