CPU limit in swarm vs CPU limit in docker run command(without swarm)

Hey therešŸ‘‹

Is there a difference between limiting cpu consumption in swarm and not using swarm?

I feel that when we limit cpu consumption with swarm, a series of configurations are applied that are not applied in normal mode.

I donā€™t know, but what kind of differences did you notice?

For example, when I create a service with swarm, if that service reaches the maximum limited cpu consumption, there would be no problem, but now sometimes when I donā€™t use swarm, if a container reaches the limited maximum cpu consumption, sometimes It slows down and Docker commands donā€™t work.

I donā€™t use Swarm, so I donā€™t speak from experience when it comes to that, but when even docker commands slow down that means either your limits didnā€™t work at all, or the limits of all your services were bigger then the available resources on the machine. If Swarm doesnā€™t allow the machine to slow down when you run the same services with the same limits, it might have a feature which I donā€™t know about and which doesnā€™t let the containers use all the available resources. Without knowing the exact case, I can just guess, so letā€™s wait until someone comes with more Swarm skills.

Swarm allows cpu reserve and limit. Docker just has a cpu limit. Both should work the same, except that plain docker canā€™t reserve the requested amount from the hostā€™s cpu resources for that particular container.
Update: I was wrong about docker not supporting reservation of cpu resources. Both can use it. So please make sure when you compare both, that you use the same reserve and limit settings in both.

I would be surprised if this wouldnā€™t be handled on the runc level through cgroups. I assume docker just delegates the setting to containerd, which delegates it to runc.