-2

Can anyone share their experience of changing the docker swarm scheduling strategy as there are three (spread, binpack and random). spread is default strategy used by docker swarm and I want it change to binpack.

jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
Niaz Hussain
  • 139
  • 1
  • 9

1 Answers1

0

The Swarm scheduling strategies you've listed are for the Classic Swarm that is implemented as a standalone container that acts as a reverse proxy to various docker engines. Most everyone is using the newer Swarm Mode instead of this, and little development effort happens for Classic Swarm.

The newer Swarm Mode includes a single option for the scheduler that can be tuned. That single option is an HA Spread algorithm. When you have multiple replicas of a single service, it will first seek to spread out those replicas across multiple nodes meeting the required criteria. And among the nodes with the fewest replicas, it will pick the nodes with the fewest other scheduled containers first.

The tuning of this algorithm includes constraints and placement preferences. Constraints allow you to require the service run on nodes with specific labels or platforms. And the placement preferences allow you to spread the workload across different values of a given label, which is useful to ensure all replicas are not running within the same AZ.

None of these configurations in Swarm Mode include a binpacking option. If you wish to reduce the number of nodes in your swarm cluster, then you can update the node state to drain workload from the node. This will gracefully stop all swarm managed containers on that node and migrate them to other nodes. Or you can simply pause new workloads from being scheduled on the node which will gradually remove replicas as services are updated and scheduled on other nodes, but not preemptively stop running replicas on that node. These two options are controlled by docker node update --availability:

$ docker node update --help

Usage:  docker node update [OPTIONS] NODE

Update a node

Options:
      --availability string   Availability of the node ("active"|"pause"|"drain")
      --label-add list        Add or update a node label (key=value)
      --label-rm list         Remove a node label if exists
      --role string           Role of the node ("worker"|"manager")

For more details on constraints and placement preferences, see: https://docs.docker.com/engine/reference/commandline/service_create/#specify-service-constraints---constraint

BMitch
  • 231,797
  • 42
  • 475
  • 450
  • I am trying this ´docker service create --replicas 1 --name bitbucket --placement-pref 'spread=node.labels.mainmashine' bitbucket:1` , but placement pref is not working in my case.It randomly scheduled to one of the worker node. I have two worker node one with label ` "mainmachine": "true" ` and one with label ` "secondmachine": "true" ` @BMitch – Niaz Hussain Dec 02 '19 at 10:43
  • @NiazHussain with only a single replica, that's expected. All nodes are valid targets, and no other replicas are running on one label to force scheduling to prefer the other label. – BMitch Dec 02 '19 at 11:37
  • oh, Yes got it. Actually I was looking --placement-pref in the perspective to fill worker-1 with tasks/services until it has resources and then on worker-2. – Niaz Hussain Dec 02 '19 at 13:18
  • @NiazHussain the placement prefs does not perform any kind of binpacking, it's explicitly designed to spread containers for HA. – BMitch Dec 02 '19 at 15:50