eugene
eugene

Reputation: 41665

ECS, meaning of memoryReservation in task definition

I'm having hard time understanding memoryReservation in ECS task definition.

The soft limit (in MiB) of memory to reserve for the container. When system memory is under contention, Docker attempts to keep the container memory to this soft limit; however, your container can consume more memory when needed, up to either the hard limit specified with the memory parameter (if applicable), or all of the available memory on the container instance, whichever comes first.

So what's the consequence of setting this value?

My uwsgi is getting killed because of memory, and I wonder if changing this value would help.

Upvotes: 3

Views: 3177

Answers (2)

Adiii
Adiii

Reputation: 59896

seems like you have set memory parameter somewhere in the task definition level or in the container level, both have a big difference.

Memory

The amount (in MiB) of memory to present to the container. If your container attempts to exceed the memory specified here, the container is killed.

MemoryReservation

The soft limit (in MiB) of memory to reserve for the container. When system memory is under heavy contention, Docker attempts to keep the container memory to this soft limit. However, your container can consume more memory.

So the best option is to specify the MemoryReservation only, it will help to avoid killing your container if that limit reached.

For example, if your container normally uses 128 MiB of memory, but occasionally bursts to 256 MiB of memory for short periods of time, you can set a memoryReservation of 128 MiB, and a memory hard limit of 300 MiB. This configuration would allow the container to only reserve 128 MiB of memory from the remaining resources on the container instance, but also allow the container to consume more memory resources when needed.

aws-properties-ecs-taskdefinition-containerdefinitions

Upvotes: 3

Rahul Sharma
Rahul Sharma

Reputation: 5995

It means that if you haven't specified memory parameters inside the task definition, then memoryReservation will be used to subtract memory from container instance and will be allocated for running the task. However, if you have specified memory parameter then it will be used to subtract that much memory from the container instance. If you're setting both parameters, then you're required to specify memory and memoryReservation parameters such that memory > memoryReservation. As you must have understood from the doc, memory => hard limit and memoryReservation => soft limit. soft limit is like reservation and hard limit is like the boundary. When your container is under heavy load or contention and requires more memory that soft limit it is allowed to consume upto hard limit of memory after which you might see getting the container killed.

You can try increasing these limits to see if all goes stable and OOM doesn't kill your uwsgi. But also be cautious of any memory leaks inside your code.

Upvotes: 1

Related Questions