containers-roadmap icon indicating copy to clipboard operation
containers-roadmap copied to clipboard

[ECS] Support use of swap memory

Open mhowell-ims opened this issue 9 years ago • 53 comments

I have an ECS workload that requires a very large amount of memory. The performance of the workload is secondary, so using swap memory would be the ideal solution.

This issue is related to #124. In that issue, @samuelkarp suggested opening a new issue if swap support is still needed. Since several others added +1 to #124 after it was closed, I'm opening this issue now.

mhowell-ims avatar Apr 19 '17 15:04 mhowell-ims

This would be fantastic! Personally we are having to pay for larger instances because during deployments we have two containers running (elastic beanstalk stack) at the same time so at this specific window of time we have to use a lot more memory and if you don't have it for those operations your deployment process become a mess. So you basically have to pay for larger instances with more memory just because you will eventually need for deployments. Not good.

igorescobar avatar Apr 19 '17 15:04 igorescobar

Thanks for the feedback, we'll track this as a feature request. The use case details provided is very helpful.

cabbruzzese avatar Apr 19 '17 17:04 cabbruzzese

We have a similar use case for using swap memory.

I'm wondering what would happen if I would add swap to the EC2 instance and use memoryReservation for all containers?

(See http://stackoverflow.com/questions/17173972/how-do-you-add-swap-to-an-ec2-instance)

Would the swap memory be available to the containers?

juhoojala avatar Apr 28 '17 13:04 juhoojala

@juhoojala I tried exactly what you've suggested above, and it didn't work. It appears that when ECS runs your image, it prevents docker from accessing the swap memory. For now we've been forced to abandon ECS and instead install and run docker ourselves on our instances. We'd much rather use ECS, but can't justify the cost of the instances that would have enough RAM for our use case.

mhowell-ims avatar May 09 '17 23:05 mhowell-ims

@mhowell-ims, many thanks for letting me now.

As a workaround, we have chosen to just use more instances, while hoping that AWS will eventually provide a proper solution for this issue. Let's hope its sooner rather than later.

juhoojala avatar May 13 '17 06:05 juhoojala

as stated in the original pr (https://github.com/aws/amazon-ecs-agent/issues/124#issuecomment-183386891) i don't think it's unreasonable to manage swap on the host instance via user data.

azban avatar May 24 '17 02:05 azban

@azban I tried what I think you're suggesting, setting up swap space on the host instances via user data script, but the containers run via ECS on those hosts were unable to access the swap memory, so it doesn't work.

mhowell-ims avatar May 29 '17 14:05 mhowell-ims

+1 for having ability to use swap memory with ECS

rubenhak avatar Oct 01 '17 18:10 rubenhak

+1 - swap memory with ECS would be very helpful

hblanken avatar Nov 05 '17 00:11 hblanken

+1

LuisErnestoZamb avatar Nov 07 '17 19:11 LuisErnestoZamb

+1 This would be definitly usefull!

ElMonty2k avatar Nov 14 '17 15:11 ElMonty2k

@azban that method was broken in a recent version of the ECS-agent. Previously the ecs-agent would set the default swappiness to -1, which would cause docker to use the default swappiness on the machine (in our case, 60, as declared in cat /proc/sys/vm/swappiness). More recent versions of the ecs-agent explicitly set swappiness to 0.

xavi- avatar Nov 28 '17 01:11 xavi-

if the container is using swap- does it use the host swap volume? What happens if the host does not have swap enabled?

pbecotte avatar Dec 06 '17 00:12 pbecotte

@pbecotte If the host does not have swap enabled, the container will not be able to use swap.

adnxn avatar Dec 07 '17 00:12 adnxn

Thanks @adnxn - I learned earlier today that what I was seeing was the container running out of memory for the disk cache and suddenly having to read files from disk instead of the cache, not swap.

pbecotte avatar Dec 07 '17 00:12 pbecotte

I would really like to get an official explanation on why swap is not supported. It simply doesn't make any sense to limit this. Looks like AWS is doing this on purpose to force purchase of more expensive instances even when not needed. Unless swap can be used somethow, looks like I'll have to use something other than ECS.

nvivo avatar Jan 03 '18 22:01 nvivo

With at least ecs-agent version 1.16.1, the behaviour of swap allocation is as follows (empirically tested):

For reference, what ECS refers to as "hard" memory limit defines a container's memory setting, and what ECS refers to as the "soft" limit defines a container's memoryReservation setting.

memory (hard) memoryReservation (soft) swap amount comment
defined defined 2 x hard limit this is docker default behaviour
undefined defined 0 could be interpreted to mean container cannot be swapped
defined undefined 2 x hard limit this is docker default behaviour
undefined undefined n/a not permitted

so ECS clearly does support "swap" for containers, although there's no way of configuring the amount with any finesse.

An important note is that you do not need to have swap configured on the host system for Docker to swap containers -- it will use the docker-pool storage for this.

Also, this is "docker swap"; it is not visible to processes inside the container, for example via the free -m or swapon -s or other commands which report on the host swap configuration

nonspecialist avatar Jan 30 '18 21:01 nonspecialist

@nonspecialist Can you point us to a documentation for the docker-pool swap storage, please?

@samuelkarp We want to disable swap at all that the service fails fast if it reaches next to 100% memory usage. Currently it seems to use swap even on Amazon ECS AMI. Maybe because of the docker-pool storage usage.

The only way I've found to disable swap on Docker is: set memory-swap == memory.

Dominik-K avatar Feb 02 '18 17:02 Dominik-K

We would also like to completely disable swap in ECS. Using swap in production servers is unacceptable for us as performance immediately deteriorates, whatever type of disks we use. Is the above way to disable swap trustworthy then?

pparth avatar Feb 05 '18 18:02 pparth

We ran into issues using swappiness with ECS and wrote up a blog post here: https://engineering.clever.com/2018/02/06/swappiness-amazon-ecs/

We were able to get the default swappiness level of 60 in our containers, but it required setting a swap file in userdata and updating the cgroup setting using docker start hooks.

alsmola avatar Feb 07 '18 18:02 alsmola