AWS ECS 任务内存硬限制和软限制 [英] AWS ECS Task Memory Hard and Soft Limits

查看:43
本文介绍了AWS ECS 任务内存硬限制和软限制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对 ECS 任务定义同时具有硬内存和软内存限制的目的感到困惑.

I'm confused about the purpose of having both hard and soft memory limits for ECS task definitions.

IIRC 软限制是调度程序在实例上为任务运行保留多少内存,硬限制是容器在被谋杀之前可以使用多少内存.

IIRC the soft limit is how much memory the scheduler reserves on an instance for the task to run, and the hard limit is how much memory a container can use before it is murdered.

我的问题是,如果 ECS 调度程序根据软限制将任务分配给实例,您可能会遇到使用高于软限制但低于硬限制的内存的任务可能会导致实例超过其最大值内存(假设所有其他任务使用的内存略低于或等于其软限制).

My issue is that if the ECS scheduler allocates tasks to instances based on the soft limit, you could have a situation where a task that is using memory above the soft limit but below the hard limit could cause the instance to exceed its max memory (assuming all other tasks are using memory slightly below or equal to their soft limit).

这是正确的吗?

谢谢

推荐答案

如果您希望运行主要受内存限制而不是 CPU 限制的计算工作负载,那么您应该只使用硬限制,而不是软限制.来自文档:

If you expect to run a compute workload that is primarily memory bound instead of CPU bound then you should use only the hard limit, not the soft limit. From the docs:

您必须为容器定义中的 memory 或 memoryReservation 之一或两者指定一个非零整数.如果同时指定两者,则内存必须大于 memoryReservation.如果您指定 memoryReservation,则该值将从放置容器的容器实例的可用内存资源中减去;否则,使用内存的值.

You must specify a non-zero integer for one or both of memory or memoryReservation in container definitions. If you specify both, memory must be greater than memoryReservation. If you specify memoryReservation, then that value is subtracted from the available memory resources for the container instance on which the container is placed; otherwise, the value of memory is used.

http://docs.aws.amazon.com/AmazonECS/最新/开发者指南/task_definition_parameters.html

通过仅为您的任务指定硬内存限制,您可以避免内存不足,因为 ECS 停止将任务放置在实例上,并且 docker 会杀死任何试图超过硬限制的容器.

By specifying only a hard memory limit for your tasks you avoid running out of memory because ECS stops placing tasks on the instance, and docker kills any containers that try to go over the hard limit.

软内存限制功能专为 CPU 密集型应用程序而设计,在这些应用程序中,您希望保留少量的最小内存(软限制),但允许偶尔突发达到硬限制.在这种 CPU 繁重的工作负载中,您并不真正关心容器的内存使用量的具体值,因为容器在耗尽实例内存之前很久就会耗尽 CPU,因此您可以根据CPU 预留和软内存限制.在这种设置中,硬限制只是一种故障保护,以防万一出现失控或内存泄漏.

The soft memory limit feature is designed for CPU bound applications where you want to reserve a small minimum of memory (the soft limit) but allow occasional bursts up to the hard limit. In this type of CPU heavy workload you don't really care about the specific value of memory usage for the containers that much because the containers will run out of CPU long before they exhaust the memory of the instance, so you can place tasks based on CPU reservation and the soft memory limit. In this setup the hard limit is just a failsafe in case something goes out of control or there is a memory leak.

总而言之,您应该使用负载测试来评估您的工作负载,看看它是先耗尽 CPU 还是先耗尽内存.如果您受 CPU 限制,那么您可以将软内存限制与可选的硬限制一起用作故障保护.如果您受内存限制,那么您将只需要使用硬限制而没有软限制.

So in summary you should evaluate your workload using load tests and see whether it tends to run out of CPU first or out of memory first. If you are CPU bound then you can use the soft memory limit with an optional hard limit just as a failsafe. If you are memory bound then you will need to use just the hard limit with no soft limit.

这篇关于AWS ECS 任务内存硬限制和软限制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆