Skip to main content

The connection to Ray

This page describes when the runner starts Ray, connects to it and stops it. The rule that guides it: the runner stops only what it started.

Nothing happens before the first run​

Creating a RayRunner checks the options given in code and does nothing else. The runner connects to Ray at the first run.

Role both​

The runner starts the local Ray without the Ray dashboard. It starts a new local Ray even when the machine has joined a cluster.

Roles server and worker​

The TCP check and the connection together must end within connect_timeout. The runner never starts a local Ray in place of a cluster it cannot reach.

One connection and shared pools for a process​

A Python process has one connection to Ray. All the RayRunner objects of the process share it. Runners with the same pool settings also share one worker pool, so their hosts use the same workers and the same sessions.

EventEffect
A runner closes and another open runner shares its poolThe workers continue
A runner closes and no other open runner shares its poolThe workers of the pool stop
The last open runner of the process closesA Ray that the runners started stops. A cluster connection that the runners opened is closed. The cluster itself continues
The process exitsSame as closing the last runner

The nodes that run workers​

The runner starts workers on the live nodes that have at least one CPU. With the role server it leaves out the driver's own node. When no node remains, the run fails with NoWorkerNodeError.

Two details for contributors​

The keeper thread​

On Linux, Ray's processes stop when the thread that started them ends. The first run does not always happen in the main thread: an async run or nr.submit starts it in another thread, which ends before the script does. In that case the runner starts the local Ray from a dedicated thread that lives until the runners stop that Ray.

Ray's uv environment​

Under uv run, Ray builds a uv environment for each worker by default. nornir_ray sets RAY_ENABLE_UV_RUN_RUNTIME_ENV=0 when it is imported, unless the variable is already set, so the workers use the driver's environment. Ray reads the variable when ray is first imported, which is why nornir_ray sets it before it imports Ray.