Limiting CPU usage in multi-container environment via docker compose

Hello community,

I’m trying to effectively limit each of my containers CPU usage in a multi-container environment.

The resin documentation lists a subset of docker compose version 2.1, but also lists “cpus” as a possible value, while the docker documentation lists this attribute as introduced in compose version 2.2
It’s all fine, “cpus” results in:

[Error]    Could not parse compose file
[Error]      data/services/$name should NOT have additional properties
[Error]    Not deploying release.

So I guess it’s just a documentation error, however I’m trying to use cpu_quota and cpu_period now, since they should be available in 2.1 cpu_period is neither mentioned in the supported nor in the unsupported section of the resin documentation though. But I tried and it is not available currently.

This again is fine in my case, but I need the value of cpu_period to find out which cpu_quota I have to supply the containers with. I couldn’t find anything on a default value in resin, but I know the default docker value should be 100000 (microsecond units I believe, even though the docker documentation lists the default at 100 microseconds - again a documentation error, as I came to believe after googling about it).

My question is whether this value is maintained in resin? So that I can safely assume, that I will use max 1 CPU if I supply my container with a quota of 100000.

The documentation articles I am referring to are:


Thanks in advance,
Tarek

Hi,

The value of the cpu_period is 100ms, so 100000. If you set cpu_quota to 100000 the container will get 100ms of computation every 100ms. If you run this application on a RPI3, which has 4 cores, this would mean you limit the container to 25% overall CPU power. But this will not limit the container to run on just one specific core. If you want to limit the container to run on just one specific core you can use cpuset.

We do not set this value, so the value defaults to it default value, which is defined here: (https://www.kernel.org/doc/Documentation/scheduler/sched-bwc.txt). So if this default value changes in the kernel, it would also affect your quota.

I hope this anwers your question.

Best regards,
Andreas

Hi Andreas,

Yes, that was exactly what I wanted to know :slight_smile:
I do use it in conjunction with cpuset to limit the containers to specific cores.

Thank you very much and have a great day!
Tarek