Cpu limitation across multiple containers

Dear all,

I’m setting up a new LXD host with several containers. I have two simple classes of service: high priority and low priority.

The desired outcome:

  • when the high priority containers are doing nothing, the low priority containers can use the cpu as they wish to the point that one container may even spike briefly and use all cpus at max
  • whenever the high priority containers are doing stuff, they should split 80% all the cpus among themselves leaving 20% to the low priority class

is this possible?

I was reading https://stgraber.org/2016/03/26/lxd-2-0-resource-control-412/ , the cpu section, and there’s a “Give me 20% of whatever you have” which sounded like the above, but it’s not clear how that’d work with the concept of classes if it does at all. If I set or low priority containers at 20% and one went off, wouldn’t the others immediately be capped at 20%? does it mean the other low container would be capped at 80%? What happens if at that point a high profile container kicks in? all the low profile containers start using 20%?

thank you for your help,

Spike

Not trivially possible as we don’t have support for grouping or hierarchy of containers.

I’d say your best bet is to create two profiles, one for high priority and one for low priority.
Set the “limits.cpu.priority” accordingly, then set “limits.cpu” to 80% for high priority and 20% for low priority.

That’s not going to do exactly what you described, but should be reasonably close.
When the system isn’t loaded, all containers can use as much CPU as they want. If under load, the scheduler will give 80% of the time to the high priority containers and 20% to the others, splitting equally between containers of the same priority.

That’s the theory at least, exact scheduler behavior is pretty hard to predict :slight_smile: