mizu_spawn_workers() spawns additional workers into free registry
slots, up to the max_workers of the pool, and waits for them to join.
mizu_retire_worker() asks one worker to exit cleanly. The request is
non-blocking and never interrupts a task. The worker observes it
between tasks and releases its slot. The remaining workers take over
any work still queued on its deque. A retired worker's process can
linger briefly to keep alive the results it produced that are not yet
collected.
Usage
mizu_spawn_workers(
pool,
n = 1L,
...,
startup_timeout = 30,
launcher = mizu_launcher()
)
mizu_retire_worker(pool, slot)Arguments
- pool
a pool handle from
mizu_pool()ormizu_pool_attach(); inside a task, the evaluating worker's own handle frommizu_current_pool().- n
number of workers to spawn.
- ...
These dots are for future extensions and must be empty.
- startup_timeout
seconds to wait for all workers to join. On expiry, mizu destroys the pool and raises
mizu_error_startup(see mizu_error).- launcher
a
function(token, slot)that arranges for an R process to callmizu:::worker_main(token, slot). The defaultmizu_launcher()spawnsRscriptand propagates the.libPaths()of the host. Itsstdoutandstderrarguments direct the worker output. A custom launcher must arrange the library paths itself.- slot
the slot index of the worker (0-based, as reported by
mizu_pool_dump()).
Value
mizu_spawn_workers() invisibly returns the slot indices
spawned into. mizu_retire_worker() invisibly returns NULL.
Details
Slots free up when workers retire, exit at shutdown, or die and are reaped, so a pool can cycle workers within its registry capacity for its whole lifetime. Only the creating process can resize a pool.
Examples
if (FALSE) { # interactive()
p <- mizu_pool(n_workers = 1L, max_workers = 2L)
mizu_retire_worker(p, 0L)
mizu_spawn_workers(p)
mizu_pool_stop(p)
}