A WorkerPool
manages multiple workers.
Details
The implementation for a WorkerPool
is essentially a container that holds
one or more Worker
objects, and posesses methods that allow it to instruct
them to assign, start, and complete Task
s. It can also check to
see if any of the R sessions associated with the Worker
s have crashed or
stalled, and replace them as needed.
Methods
Method get_pool_state()
Return a summary of the worker pool
Returns
A named character vector specifying the current state of each worker ("starting", "idle", "busy", or "finished"). Names denote worker ids, and the interpretations of each return value is as follows:
"starting"
: the R session is starting up."idle"
: the R session is ready to compute."busy"
: the R session is computing."finished"
: the R session has terminated.
Method try_assign()
Attempt to assign tasks to workers. This method is
intended to be called by Queue
objects. When called, this method
will iterate over tasks in the list and workers in the pool, assigning
tasks to workers as long as there are both idle workers and waiting
tasks. It returns once it runs out of one resource or the other. Note
that this method assigns tasks to workers: it does not instruct the
workers to to start working on the tasks. That is the job of
try_start()
.
Method try_start()
Iterates over Workers
in the pool and asks them to
start any jobs that the have been assigned but have not yet started.
This method is intended to be called by Queue
objects.
Method try_finish()
Iterate over Workers
in the pool and checks to see if
any of the busy sessions are ready to return results. For those that
are, it finishes the tasks and ensures those results are returned to
the Task
object. This method is intended to be called by Queue
objects.
Method refill_pool()
Check the WorkerPool
looking for Workers
that
have crashed or been shutdown, and replace them with fresh workers.
Method shutdown_pool()
Terminate all workers in the pool.
Method shutdown_overdue_workers()
Terminate workers that have worked on their current task for longer than a pre-specified time limit.