Skip to content

Understanding memory in ECS EC2 task

0

How can I tell an ECS container that it cannot use more than 10GB of memory?

I don't give the task any limits because I need alltogether in all container more than 10 CPU units and EC2 has a limit of 10 CPUs in the task definition.

In the container definition I give the container a memoryReservationMiB of 10GB and cpu of 6. But the container doesn't seem to care. I want to prevent the container from terminating if too much memory is used, so I don't set memoryLimitMiB but only memoryReservationMiB.

Unfortunately the application crashes in the ECS EC2 task with a memory error, but in EKS the container runs through with the same settings.

          resources:
            requests:
              cpu: "4"
              memory: "4Gi"
            limits:
              cpu: "6"
              memory: "10Gi

Is the approach wrong?

1 Answer
5

Hello,

When creating a Task Definition on ECS, you can set the CPU and memory allocation in the Resource allocation limits field (see screenshot below). If you've set CPU to 6 vCPU and Memory soft limit to 10GB it should work. If your container is crashing, have you checked if your EC2 instance can actually handle more than 10GB of memory? Also, do you know how much memory your task might actually need at peak usage?

Hope it helps :)

Enter image description here

EXPERT

answered 2 years ago

EXPERT

reviewed 2 years ago

  • I have a EC2 with 16 CPU and 64 GM Memory I think this is not the issue. The container contains a modern software and a modern software consume as much memory it can get. So I think the problem is that ECS will not limit the memory, it will just terminate the container if the limit is reached. EKS will not and I ask me why. Is there no powerful task possible on ECS?

  • What about your application logs, the ecs agent logs? Why not trying to configure at least the memory for the task?

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.