简体   繁体   中英

How to dynamically allocate memory to multi-docker container AWS Elastic Beanstalk environment running Java applications

I want to squeeze out every possible ounce of usage from the free elastic beanstalk tier.

My backend is built as a set of microservices (using ktor). I have 5 microservices to be precise. All of these are dockerized and I'm trying to run them all on the same tiny t2.micro (free) elastic beanstalk instance with the multi-docker image environment

Java being java, it likes to idle around 200 MB RAM per docker container for even the most simplest microservice.

So, t2.micro gives you 1GB RAM. I have 5 microservice docker containers demanding at least 200 MB each = really close.

The trouble is, the memory is almost always hovering fiercely close to 100% nearly all the time.

So, is there a way to dynamically allocate memory to the docker containers depending on how much is free and how desperately one container needs it?

Say that one container is doing some heavy lifting while the others are mostly idle, I want to direct some RAM towards the container doing the heavy task and once the task is over, go back to equal RAM allocation per container.

Is there a way to do this?

You can use docker update --memory-reservation xxx <container> to change the soft limit memory allocation for a container while it's running. Docker will gently push containers down to their soft limits when overall memory is low. So you could set soft limits of, say 150 MB for all your containers, and then bump one of them up when you know it has extra work to do.

The docker documentation on soft limits isn't that great, the kernel documentation for CGroup Memory explains it better.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM