I'm in the process of trying to optimise and consolidate our AWS instances. Part of this involves standardising (where possible) our instance classes, to make optimal use of reservations.

We have a number of applications using the m5d class EC2's, using the ephemeral storage for super-fast swap space. We also have a number of ECS clusters, which are currently using r5 class EC2's.

I'm wondering if anyone knows whether swap space is useful for ECS cluster instances? If docker is able to efficiently use swap space, then it might mean we could use cheaper general purpose "d" instances, rather than having to use the larger more expensive "r5" class instances.


With ECS you have to specify the Memory Reservation for each task and ECS will not let you oversubscribe the available memory. I.e. if your instance has 4GB RAM and you take away a bit for the OS (say 0.5GB) you are left with 3.5GB for your tasks. You can create a 1.5GB task and 2GB task but can't have 2x 2GB tasks.

What that means is that swap space is hardly ever used on ECS nodes - the tasks should fit in the available memory.

Also it's questionable whether r5 is more expensive than m5d - it depends if you are constrained by CPU or RAM. As of today r5.large with 16GB RAM costs $0.126/hr while a comparable m5d.xlarge with 16GB RAM costs $0.226/hr - quite a bit more. With M5D you are getting both RAM, CPU and Disk, hence it's more expensive than RAM-optimised R5 class.

If I were you I would look at AWS Saving Plans that give you much higher flexibility over Reserved Instances. You can choose instance classes, size, and even run your containers in Fargate.

Hope that helps :)

  • Thanks, that is very helpful. I think it will make sense to continue using r5 class for ECS. I'll also do more investigation on savings plans. – user1751825 May 12 '20 at 1:43

Swap space is useful or at least usable for ECS cluster instances. You can find a pretty good documentation in the Amazon ECS Developer Guide.

Basically there are two task definition parameters you can use to control the swap usage: maxSwap and swappiness. Even if you don't provide any of these parameters by default ECS will make use of the swap space. In order to avoid swap usage you need to set the values to 0.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.