The worker
A worker is one process on a node. In Ray terms it is an actor: a process that stays
running, keeps its state between calls and receives calls from the driver. The class is
TaskWorker.
One worker runs many hosts
The number of worker processes does not depend on the number of hosts. Each node runs
workers_per_node workers, and each worker runs up to hosts_per_worker hosts at the same
time.
- Async tasks run on the worker's event loop.
- Sync tasks run in a pool of threads inside the worker.
- A worker admits at most
hosts_per_workercalls at the same time, sync and async together. Further calls wait in the order they arrived. - The thread pool has
hosts_per_worker + max_abandoned_callsthreads. The spare threads are for abandoned calls.
The calls a worker accepts
| Call | What it does |
|---|---|
ready() | Returns when the worker can accept tasks. The driver waits up to worker_start_timeout for it |
run(call) | Waits for a free place, then for the host's lock. Runs the task and sends the events back |
cancel(call_id) | Cancels one call. For an async call, it also cancels the asyncio task |
abandon(call_id) | For sync calls. Marks the call abandoned; see Abandoned calls |
status() | Returns the worker's identity, its node, the abandoned calls still running and the active calls |
close() | Closes the sessions of every kept host |
cancel, abandon, status, ready and close are control calls. The worker serves them
separately from run, so a control call reaches a worker while all its places run tasks.
One call for each host at a time
The worker keeps a lock for each host. Two calls for the same host never run at the same time on a worker, even when two runs of the same process include the host. The second call waits for the first to end.
What a worker does not do
- It applies no deadlines. Nornir applies the deadlines on the driver. The worker stops a
task only when the driver sends
cancelorabandon. - It does not retry. A task that fails is reported as failed.
- It does not restart during a run. The pool starts a new worker in the place of a stopped one at the start of the next run.
When a worker stops during a run
When the process of a worker stops, the driver receives an error from Ray on every call that
the worker was running. Each of those hosts fails with WorkerDiedError, which names the host,
the node and the worker. The pool marks the worker's place as empty and fills it at the next
run. The new worker has the same identity, so the hosts of the old worker go to it.