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.