Wondering how to allocate memory to tasks in ECS? We can help you.
Here, at Bobcares, we assist our customers with several AWS queries as part of our AWS Support Services.
Today, let us see how our Support techs assist with this query.
How to allocate memory to tasks in ECS?
Amazon ECS uses two parameters for allocating memory to tasks. They are memoryReservation and memory.
The value for each parameter is subtracted from the available memory units of an Amazon ECS container instance when a task is running.
The calculation is based on the soft limit or hard limit of a task definition.
Today, let us see the steps followed by our Support Techs to perform this task.
Before you start, check to see that you have an Amazon ECS cluster that includes an Amazon Elastic Compute Cloud (Amazon EC2) instance.
View the memory allocations of a container instance
- Firstly, open the Amazon ECS console.
- Then, in the navigation pane, choose Clusters.
- Next, choose the cluster that you created.
- Choose the ECS Instances view, and then choose the container instance included with the cluster that you created from the Container Instance column.
Please note the Details pane shows that the memory in the Available column is equal to the memory in the Registered column. - For statistics on the resource usage of the instance, connect to the instance using SSH, and then run the docker stats command.
Create a task definition with a soft limit
- From the Amazon ECS console, in the navigation pane, choose Task Definitions.
- Then, choose Create new Task Definition.
- For the launch type, choose EC2, and then choose Next step.
- For Task Definition Name, enter a name.
- In the Container Definitions section, choose Add container.
- Then for Container name, enter a name.
- For Image, enter nginx or the appropriate Docker image for your environment.
- For Memory Limits (MiB), choose Soft limit, and then enter 700.
- Choose Add, and then choose Create.
Run the task definition with a soft limit
- From the Amazon ECS console, in the navigation pane, choose Clusters, and then choose the cluster that you created.
- Choose the Tasks view, and then choose Run new Task.
- Then, choose Run Task.
- When the Last status column of the task with a soft limit shows as RUNNING, choose Clusters from the navigation pane.
- Choose the ECS Instances view, and then choose the instance from the Container Instance column.
- For statistics on the resource usage of the instance, connect to the instance using SSH, and then run the docker stats command.
- Next, choose Clusters from the navigation pane, and then choose the cluster.
- Choose the Tasks view, select the task with a soft limit, and then choose Stop.
- Choose the ECS Instances view, and then choose the instance from the Container Instance column.
Create a new revision of a task definition with a hard limit
- From the Amazon ECS console, in the navigation pane, choose Task Definitions.
- Select the task definition that you created with a soft limit, and then choose Create new revision.
- In the Container Definitions section, in the Container Name column, choose the container that you added for the task definition with a soft limit.
- For Memory Limits (MiB), choose Hard limit, and then enter 1000.
- Choose Update, and then choose Create.
Run the revised task definition with a hard limit
- From the Amazon ECS console, in the navigation pane, choose Clusters, and then choose the cluster that you created.
- Choose the Tasks view, and then choose Run new Task.
- For Task Definition, choose the task definition with a hard limit that you created, and then choose Run Task.
- When the Last status column of the revised task with a hard limit shows as RUNNING, choose Clusters from the navigation pane.
- Choose the ECS Instances view, and then choose the instance from the Container Instance column.
- For statistics on the resource usage of the instance, connect to the instance using SSH, and then run the docker stats command.
- Then, choose Clusters from the navigation pane, and then choose the cluster.
- Choose the Tasks view, select the task with a hard limit, and then choose Stop.
- Choose the ECS Instances view, and then choose the instance from the Container Instance column.
Create a new revision of a task definition with both a soft limit and a hard limit
- From the Amazon ECS console, in the navigation pane, choose Task Definitions.
- Select the task definition that you created with a hard limit, and then choose Create new revision.
- In the Container Definitions section, in the Container Name column, choose the container that you added for the task definition with a hard limit.
- For Memory Limits (MiB), choose Soft limit, and then enter 700.
- Choose Add Hard limit, and then enter 1200.
- Choose Update, and then choose Create.
Run the revised task definition with both a soft limit and a hard limit
- From the Amazon ECS console, in the navigation pane, choose Clusters, and then choose the cluster that you created.
- Choose the Tasks view, and then choose Run new Task.
- For Task Definition, choose the task definition that you created with both a soft limit and a hard limit, and then choose Run Task.
- When the Last status column of the task shows as RUNNING, choose Clusters from the navigation pane.
- Then, choose Clusters from the navigation pane, and then choose the cluster.
- Choose the Tasks view, select the task with both a soft limit and a hard limit, and then choose Stop.
- Choose the ECS Instances view, and then choose the instance from the Container Instance column.
- For statistics on the resource usage of the instance, connect to the instance using SSH, and then run the docker stats command.
[Need help with the process? We’d be happy to assist]
Conclusion
In short, we saw how our Support Techs allocate memory to tasks in ECS.
0 Comments