'cpu'参数在aws容器服务中是什么意思?

What does 'cpu' parameter mean in aws container service?

我要在 t2.medium 的容器服务中注册一个新任务。 我看到 cpu 参数等于 0 的示例。 我正在尝试找出它是什么以及我需要在此处放置多少来完成一项任务。

根据这个问题我能找到的所有内容: http://docs.aws.amazon.com/AmazonECS/latest/developerguide/task_definition_parameters.html?shortFooter=true http://docs.aws.amazon.com/AmazonECS/latest/developerguide/example_task_definitions.html

"The number of cpu units to reserve for the container. A container instance has 1,024 cpu units for every CPU core. This parameter specifies the minimum amount of CPU to reserve for a container, and containers share unallocated CPU units with other containers on the instance with the same ratio as their allocated amount. This parameter maps to CpuShares in the Create a container section of the Docker Remote API and the --cpu-shares option to docker run."

A t2.medium 有 2 个 vCPU,因此它有 2,048 个可用的 CPU 单位要安排。如果您只想在主机上放置一个容器 运行,您可以预算所有 2,048 CPU 个单元,但不会在该主机上放置其他容器。

容器始终保证在需要时至少达到预算CPU。此外,关于 CPU 单位的一个巧妙之处在于,如果没有其他容器占用资源,则容器可以突破其分配的单位。例如,如果您在 t2.medium 上有两个任务 运行,每个任务都有 1,024 个预算 CPU 单位,如果另一个任务完全空闲,则每个任务可以单独突增至 2,048 个。当您开始以这种方式共享主机时,您真的可以从使用 ECS 中节省成本。

此外,如果所有 CPU 单元都没有预算,ECS 会自动将剩余的 CPU 单元按其预算 CPU 单元的比例分配给每个容器.因此,如果您在 t2.medium 上有两个任务 运行,每个任务具有 0 CPU 个单元,则每个容器将有效地获得 1,024 CPU 个单元,因为没有其他容器保留它们。

这里要注意的一件事是内存的工作方式有点不同;这是一个硬性限制。如果容器试图分配比预算更多的内存,task/container 将退出。您可以供应不足 CPU 个单元并且通常可以侥幸逃脱(因为容器可以超出其供应),但您需要确保您保持在内存限制内。


示例: 如果将其设置为 0,它将按比例占用未保留的 CPU。假设这些场景在 t2.mediums 上有 2,048 CPU 个单元:

任务 #1 - 0 CPU 个单元, 任务 #2 - 0 CPU 个单位: 在这种情况下,Task#1 和 Task#2 都将获得 1,024 CPU 个单位,因为有 2,048 个未保留的单位。由于任务是 1:1 CPU 个单位预留,因此它们都将获得相等份额的可用 CPU 个单位。

任务 #1 - 0 CPU 个单元, 任务 #2 - 1,024 CPU 个单位: 任务 #2 将获得 2,048 CPU 个单位,任务 #1 将获得 0,因为它试图以 0:1,024.[= 的比例分配 1,024 个未使用的 CPU 单位。 11=]

任务 #1 - 0 CPU 个单位: 如果机器上只有一个任务,它将获得所有 2,048 CPU 个单元,因为所有单元都未使用,它们按预留比例分配给容器。