How does Docker Swarm balance tasks?
AFAIK, Swarm does zero real-time resource monitoring. It's only as smart as reservations and limits that you set on the Service beforehand.
First, it takes into account if the tasks of that Service are spread out. It will try not to schedule multiple tasks on the same node, and may ignore total task count per node to do so.
Then, it counts the number of tasks per node and finds the one with the least task count.
All these is restricted by resource reservations. If that node doesn't have the room (based only on the reservations you set), it'll look to the next lower task count.
This is also why Swarm alone can't do built-in auto-scaling because it has no way to track metrics over time.
It does know total CPU and memory, so it knows how to track &quot;full&quot; once you've set resource reservations.
More info: https://github.com/docker/swarmkit/blob/master/design/scheduler.md