Host assignment
Host assignment decides which worker runs each host. It has two goals:
- a host goes to the same worker at every run, so its sessions can be used again;
- when a worker is added or removed, as few hosts as possible change worker.
Worker identities
A worker's identity has the form <node_id>/<n>: the Ray node ID and the number of the
worker's place on that node, starting at 0. With workers_per_node: 4, a node has the places 0
to 3.
A worker that replaces a stopped worker takes the same place, and therefore the same identity. The hosts of the stopped worker go to the new one.
The method: highest score wins
For each host, the runner computes a score with every worker, and gives the host to the worker with the highest score. The score is a hash of the host's name and the worker's identity.
The values in the diagram are examples. This method is called rendezvous hashing.
- The same inputs give the same worker. The score depends only on the two names, so every run and every process computes the same assignment.
- Removing a worker moves only its hosts. The scores of a host with the other workers do not change. Each host of the removed worker goes to its next highest score.
- Adding a worker moves only the hosts it wins. A host moves only when the new worker has its highest score.
A simpler method, such as the host's position in the list modulo the number of workers, would move most hosts whenever the number of workers changes.
Details
- The hash is
blake2bof the host's name, a zero byte and the worker's identity. The score is the first 8 bytes of the hash. Python's ownhash()is not used, because it gives a different value in each process. - The runner computes the assignment at the start of each run, over the workers that are live at that time.
- The distribution is even on average, not exact. With few hosts, some workers can receive more hosts than others.
- In this version, a host's site does not influence the assignment: a host can go to any worker of any node.