为什么 Lambda 函数在使用 1536 MB 时执行速度要快得多? [英] Why a Lambda function is much faster to execute when using 1536 MB?

查看:21
本文介绍了为什么 Lambda 函数在使用 1536 MB 时执行速度要快得多?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个问题,我很想得到答案.

I've got a question and I would love to get an answer.

我有一个 Lambda 函数,它使用 31 MB 的最大内存,配置的分配内存为 128MB,需要 2556.68 毫秒.

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.

但是,将分配的内存增加到最大1536 MB时,完全执行只需要 621.81 毫秒,并且使用的最大内存完全相同,为 31 MB.

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.

为什么在两种情况下使用的内存完全相同时,Lambda 函数的执行速度要快得多?

Why the Lambda function executed much faster when used memory is exactly the same in the two cases?

推荐答案

这是因为分配给您的容器的 CPU 数量与您要求的内存数量成正比.

This is because the amount of CPU your containers are allocated is proportional to the amount of memory you ask for.

AWS Lambda 使用与通用 Amazon EC2 实例类型(例如 M3 类型)相同的比率来分配与内存成比例的 CPU 功率.例如,如果您分配 256 MB 内存,则您的 Lambda 函数将获得两倍于您仅分配 128 MB 的 CPU 份额.

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 实例每 30 GB RAM 有 8 个 Xeon E5-2670 或 Xeon E5-2670 V2 超线程,因此按照这个比例,使用 1.5GB 内存,您大约有 1.5 × (8 ÷ 30) × 2.6 GHz ≅ 1CPU 的 GHz.在 128 MB 时,您只有大约 1/12.

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.

这篇关于为什么 Lambda 函数在使用 1536 MB 时执行速度要快得多?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆