Hi, All,
Like the title.
When we experience swarm mode in docker 1.12. We found it is really important for us to schedule service. Here we have some need that different services should be scheduled to different nodes.
In another word, can swarmkit schedule a service ServiceA to node without ServiceB?
Thanks in Advance.
Swarmkit doesn't support affinity or anti-affinity yet. The constraints are on node and engine labels so far. See constraints in the doc. Current recommendation is to use node engine label to select nodes.
Adding (anti-)affinity is not a big task. But one of the problem with (anti-)affinity is that the evaluation process. If you put a constraint that ServiceA runs on nodes without ServiceB, when instances of ServiceB get rescheduled, they may be scheduled on nodes with ServiceA since ServiceB doesn't have this constraint. It would break the anti-affinity from ServiceA. We can re-evaluate every service on the node to decide if it fits or not, but they would result in heavy computation.
cc @aaronlehmann.
Thanks for your feedback. Maybe we shall find a better scenario or do a future plan in swarmkit. @dongluochen
Any update on this affinity in docker service create ? Now it's supporting or not ?
Did get the question during a conversation with a partner. They need to know when and how we plan to support this?
"Service aware affinity & anti-affinity" is also important for one of my customers. They want to use it in production environment for resource and performance infrastructure optimization.
Lets say Service A replica(s) should run only on a nodes that Service B replica(s) is not running or the other way around, Service A replica(s) should run only on a nodes with running Service B replica(s).
That allows optimized resource usage and/or performance, for example:
Should we expect to see soon "service aware affinity & anti-affinity" constrains supported in swarm kit/swarm mode?
Thanks.
I miss that feature too. Using constraints and managing docker hosts labels is too much overhead. Eventually I ended up running several services in one container, so I don't have to worry about scaling containers over the cluster.
simple workaround
https://github.com/keyolk/swarmkit/commit/212a1900ba4a085d8b8f0f0da56ec9e1ce1f8f2c
$ docker service create --constraint antiaffinity==test --name=one tomcat
$ docker service create --constraint antiaffinity==test --name=two tomcat
two's tasks never be assigned same node which has one's task.
also one's tasks never be assigned on same node.
Most helpful comment
Swarmkit doesn't support affinity or anti-affinity yet. The constraints are on node and engine labels so far. See
constraintsin the doc. Current recommendation is to use node engine label to select nodes.Adding (anti-)affinity is not a big task. But one of the problem with (anti-)affinity is that the evaluation process. If you put a constraint that ServiceA runs on nodes without ServiceB, when instances of ServiceB get rescheduled, they may be scheduled on nodes with ServiceA since ServiceB doesn't have this constraint. It would break the anti-affinity from ServiceA. We can re-evaluate every service on the node to decide if it fits or not, but they would result in heavy computation.
cc @aaronlehmann.