简体   繁体   中英

memory and cpu management on docker containers

I'm running selenium grid on Docker containers. I have one container that runs selenium hub and five other containers running chrome-nodes (each with maximum of 5 sessions). Problem is that, the test team request random number of chrome session. Generally, when there is about 5 chrome session request memory usage goes upto 80% and CPU goes upto 95%. One more request and all containers go down making selenium unavailable for everyone.

My question is how do I prevent this from happening? Since I do not have control of how many sessions test team will request, I want to cap percentage of RAM and CPU available to Docker containers. Do I have to do this on each container or just once for Docker application?

AFIK, you will have to limit each container resources in docker run . From Docker Run Reference :

Runtime constraints on CPU and memory

The operator can also adjust the performance parameters of the container:

-m="": Memory limit (format: <number><optional unit>, where unit = b, k, m or g) -c=0 : CPU shares (relative weight)

The operator can constrain the memory available to a container easily with docker run -m. If the host supports swap memory, then the -m memory setting can be larger than physical RAM.

Similarly the operator can increase the priority of this container with the -c option. By default, all containers run at the same priority and get the same proportion of CPU cycles, but you can tell the kernel to give more shares of CPU time to one or more containers when you start them via Docker.

The flag -c or --cpu-shares with value 0 indicates that the running container has access to all 1024 (default) CPU shares. However, this value can be modified to run a container with a different priority or different proportion of CPU cycles.

Eg, If we start three {C0, C1, C2} containers with default values (-c OR --cpu-shares = 0) and one {C3} with (-c or --cpu-shares=512) then C0, C1, and C2 would have access to 100% CPU shares (1024) and C3 would only have access to 50% CPU shares (512). In the context of a time-sliced OS with time quantum set as 100 milliseconds, containers C0, C1, and C2 will run for full-time quantum, and container C3 will run for half-time quantum ie 50 milliseconds.

You can also specify the cores used by the container using the option --cpuset . Eg.: --cpuset=0-3 , --cpuset=0 or --cpuset=3,4

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