Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 965
Aditya Anand Avatar asked Jan 16 '20 12:01

Aditya Anand


People also ask

How do I increase the memory allocated to a Docker container?

Set Maximum Memory Access Alternatively, you can use the shortcut -m . Within the command, specify how much memory you want to dedicate to that specific container. The value of memory_limit should be a positive integer followed by the suffix b, k, m, or g (short for bytes, kilobytes, megabytes, or gigabytes).

Which feature in Docker allows us to create and run multi-container applications?

The docker-compose. yml file allows you to configure and document all your application's service dependencies (other services, cache, databases, queues, etc.). Using the docker-compose CLI command, you can create and start one or more containers for each dependency with a single command (docker-compose up).

Which of the following is an appropriate command for defining and running multi-container Docker applications?

Compose is a tool for defining and running multi-container Docker applications. With Compose, you use a YAML file to configure your application's services. Then, with a single command, you create and start all the services from your configuration.


1 Answers

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.

like image 81
CantankerousBullMoose Avatar answered Sep 19 '22 14:09

CantankerousBullMoose