amazon-web-servicesamazon-ecscpu-usageaws-fargate

Understanding CPU Utilisation Graph for a task running AWS Fargate


I have a task defined with 0.5vCPU. It has two containers with 0.25vCPU

Can someone explain to me what the below CPU Utilization graph represents?

enter image description here

The above graph is from Health and Metrics section in AWS Console for the sevice.

Since each of my containers has 0.25 vCPU it is expected that the container gets at most 25% of a CPU core every second. Then what does ~115% (max CPU utilisation) mean in the above graph?

Should not the container be killed when it reaches 100% CPU Utilisation? Why is the max cpu utilisation showing more than 100%?


Solution

  • Answer from AWS Support

    We have 2 Option where we can configure CPU/Memory while Creating a Task Definition in ECS.

    1. Task Level CPU/Memory
    2. Container Level CPU/Memory

    Task Level CPU/Memory is required Parameter when Creating a Task Definition for Fargate [1]. This act as Hard Limit. Container Level CPU/Memory is Optional (Soft Limit) For Fargate. [1]

    The CPU/Memory utilization will not go above the defined task-level limit. But it can go beyond what is defined in the Container Level.

    You could check the example in [2].

    In your case, you have 2 Container with 0.25 vCPU defined in Container Level and 0.5 vCPU in Task Level. --> Individually each Container can use upto 0.5 vCPU. This mean individual Container CPU Utilization can reach a Maximum of 200% [(0.5/0.25)*100]

    --> Also the Sum of the CPU usage of both Container cannot go beyong 0.5 vCPU. More Specific example if 1 Container is using 0.4 vCPU then another can use 0.1 vCPU. In % utilization 1 Container 160% [(0.4/0.25)*100] and another one 40%[(0.1/0.25)*100] This is just an example for understanding. CPU Share Allocation is Dynamic. So the Container will not be killed for Spike in CPU utilization crossing more than 100%.

    You could check the references [2,3] for more information.

    Reference:

    1. https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task_definition_parameters.html#task_size
    2. https://docs.aws.amazon.com/AmazonECS/latest/developerguide/cloudwatch-metrics.html#service_utilization
    3. https://repost.aws/knowledge-center/ecs-cpu-allocation