startLocalWorkers {doRedis} | R Documentation |
Start one or more background R worker processes on the local system.
Description
Use startLocalWorkers
to start one or more doRedis R worker processes
in the background. The worker processes are started on the local system using
the redisWorker
function.
Usage
startLocalWorkers(
n,
queue,
host = "localhost",
port = 6379,
iter = Inf,
linger = 30,
log = stdout(),
Rbin = paste(R.home(component = "bin"), "R", sep = "/"),
password,
...
)
Arguments
n |
number of workers to start |
queue |
work queue name |
host |
Redis database host name or IP address |
port |
Redis database port number |
iter |
maximum number of tasks to process before exiting the worker loop |
linger |
timeout in seconds after which the work queue is deleted that the worker terminates |
log |
print messages to the specified file connection |
Rbin |
full path to the command-line R program |
password |
optional Redis database password |
... |
optional additional parameters passed to the |
Details
Running workers self-terminate after a linger
period if their work queues are deleted with the
removeQueue
function, or when network activity with Redis remains
inactive for longer than the timeout
period set in the redisConnect
function. That value defaults internally to 3600 (one hour) in startLocalWorkers
.
You can increase it by including a timeout=n argument value.
Value
NULL is invisibly returned.
See Also
Examples
# Only run if a Redis server is running
if (redux::redis_available()) {
## The example assumes that a Redis server is running on the local host
## and standard port.
# Start a single local R worker process
startLocalWorkers(n=1, queue="R jobs", linger=1)
# Run a simple sampling approximation of pi:
registerDoRedis("R jobs")
print(foreach(j=1:10, .combine=sum, .multicombine=TRUE) %dopar%
4 * sum((runif(1000000) ^ 2 + runif(1000000) ^ 2) < 1) / 10000000)
# Clean up
removeQueue("R jobs")
}