ItsEcholot / ContainerNursery

Puts Docker Containers to sleep and wakes them back up when they're needed
MIT License
135 stars 7 forks source link

Optional Enhancement: Stop Containers if Docker Host CPU Usage is High #11

Closed everythingguy closed 2 years ago

everythingguy commented 3 years ago

Enhancement. If the docker host is being overwhelmed CPU-wise the proxy should turn off the least active containers at the time. Only enable this feature for containers that have a boolean flag for it in the config. The other optional enhancement #2 should take priority over this one. That is if a CPU limit is set and that condition is not met then this feature should not turn off the container.

everythingguy commented 3 years ago

A dormant limit may also be needed in the config so containers do not shutdown too fast due to high CPU usage. As well as a configurable max CPU usage before this feature is triggered. It should only shutdown a couple of containers at a time to see how CPU usage is impacted.

everythingguy commented 3 years ago

I am not sure if the application will have trouble reading the CPU usage of the whole host. It may only be able to read the usage within the container. If that is the case to read the CPU usage of the whole host the host path /proc/stat needs to be passed into the container. That file can be read a few times in short intervals to get the current CPU usage of the whole host. Or the node command "os.cpus()" may be able to get a correct reading within the container without jumping through any hoops.

ItsEcholot commented 3 years ago

In my experience docker containers don't use any / not a lot of CPU power when not doing anything. Do you have some examples of containers that would lighten the system CPU load in an overload scenario? In my opinion the biggest savings of stopped containers is the memory that gets released.

everythingguy commented 3 years ago

Perhaps it would be better to focus on memory usage instead of CPU usage then. I was thinking about docker hosts that are hosting a lot of websites for clients where CPU/memory usage could be a real concern.

ItsEcholot commented 2 years ago

On further examination I don't think this is a useful feature. Stoping containers based on system load would make service availability "random". You would never know if the service you're using is gonna be available in 5 minutes or shut down because another service is using more RAM or CPU.