내용으로 건너뛰기

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

질문됨 2년 전385회 조회
2개 답변
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.

답변함 2년 전
전문가
검토됨 2년 전
전문가
검토됨 2년 전
전문가
검토됨 2년 전
  • 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
전문가
답변함 2년 전
전문가
검토됨 2년 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

관련 콘텐츠