Run on a cluster
With the roles worker and server, the workers run on the nodes of a Ray cluster that you
start. The runner connects to the cluster; it never starts or stops it.
1. Install the packages on every node
Install the same versions on every node, the driver's machine included:
nornir-ray;- the connection plugins your tasks use;
- the packages that define your tasks.
Both sides must run the same version of nornir-ray.
2. Start the cluster
On the first machine, start the head node:
ray start --head --port 6379
On every other machine, join the cluster. Replace 10.0.0.1 with the address of the head
node:
ray start --address 10.0.0.1:6379
Join the machine that runs your script too. The driver must be a node of the cluster. When
it is not, the run fails with RayClusterUnreachableError.
3. Configure the runner
runner:
plugin: ray
options:
address: "10.0.0.1:6379"
role: server
workers_per_node: 4
Or set the address in the environment, and the role in the configuration or in code:
export RAY_ADDRESS=10.0.0.1:6379
When an address is set and no role is set, the role is worker.
4. Choose between worker and server
| Role | Workers run on |
|---|---|
worker | Every node of the cluster, the driver's node included |
server | Every node of the cluster except the driver's node |
Only live nodes with at least one CPU run workers. When no node can run workers, the run fails
with NoWorkerNodeError before any host starts. With the role server, this happens when the
driver's node is the only node of the cluster.
What happens when the cluster cannot be reached
The runner tries to connect for connect_timeout seconds, 10 by default. When it cannot
connect, the run fails with RayClusterUnreachableError, which names the address. No host
starts.
The runner never starts a local Ray in place of the cluster. A script configured for a cluster therefore cannot run the tasks from the wrong machine without you knowing.
What the runner stops
nr.runner.close()stops the runner's workers when no other open runner in the process shares them.- The runner disconnects from the cluster when the last open runner of the process closes.
- The runner never stops the cluster. Stop it with
ray stopon each node.
Check where the hosts ran
Each host's result names its node and worker. Use it to confirm that the role does what you expect:
result = nr.run(task=my_task)
for name, host_results in result.items():
location = getattr(host_results[0], "ray", None)
if location:
print(name, location.node_name, location.worker_id)