我有一个问题,我很想得到答案。
我有一个 Lambda 函数,它使用的最大内存为 31 MB 配置的分配内存为 128MB,需要 2556.68 毫秒。
但是,当将分配的内存增加到最大值时 1536 MB 完全执行只需要 621.81 ms,使用的 MAX 内存完全相同,为 31 MB。
为什么在两种情况下使用的内存完全相同时,Lambda 函数执行得更快?
最佳答案
这是因为分配给您的容器的 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 ≅ 1 GHz 的 CPU .在 128 MB 时,您只有大约 1/12。
关于amazon-web-services - 为什么 Lambda 函数在使用 1536 MB 时执行速度要快得多?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47256148/