Package doredis. R topics documented: February 19, Type Package

Similar documents
Package doredis. R topics documented: December 15, Type Package. Title Foreach parallel adapter for the rredis package. Version 1.0.

Elastic computing with R and Redis

Introduction to the doredis Package

Package getopt. February 16, 2018

Package callr. August 29, 2016

Package reportr. October 6, 2016

Distributed Computing Patterns in R

Package ssh. June 4, 2018

Package redux. May 31, 2018

Package GenSA. R topics documented: January 17, Type Package Title Generalized Simulated Annealing Version 1.1.

Package inca. February 13, 2018

Package shinyhelper. June 21, 2018

Package rcmdcheck. R topics documented: November 10, 2018

Package rngsetseed. February 20, 2015

Package datasets.load

Package imgur. R topics documented: December 20, Type Package. Title Share plots using the imgur.com image hosting service. Version 0.1.

Package spark. July 21, 2017

Package eulerian. February 19, Index 5

Package future.apply

Package lvec. May 24, 2018

MySQL Proxy. Making MySQL more flexible Jan Kneschke

Package smoother. April 16, 2015

Package curry. September 28, 2016

Package filelock. R topics documented: February 7, 2018

Package furrr. May 16, 2018

Package cgh. R topics documented: February 19, 2015

Package calibrar. August 29, 2016

Package pso. R topics documented: February 20, Version Date Title Particle Swarm Optimization

Package knitrprogressbar

Package fastdummies. January 8, 2018

Package svkomodo. R topics documented: February 20, Type Package Version Date

Package deductive. June 2, 2017

Package MicroStrategyR

Nesting Foreach Loops

Package reval. May 26, 2015

Package Combine. R topics documented: September 4, Type Package Title Game-Theoretic Probability Combination Version 1.

Package pbdrpc. February 2, 2018

Package mdftracks. February 6, 2017

Package testit. R topics documented: June 14, 2018

Package httpcache. October 17, 2017

Package SPIn. R topics documented: February 19, Type Package

Package gpdtest. February 19, 2015

Package RYoudaoTranslate

Automating Administration with Windows PowerShell 2.0

Package RCA. R topics documented: February 29, 2016

Package ssd. February 20, Index 5

Package ECctmc. May 1, 2018

Package biganalytics

Package influxdbr. January 10, 2018

Package iterators. December 12, 2017

Package sessioninfo. June 21, 2017

Package dfoptim. April 2, 2018

Package gsalib. R topics documented: February 20, Type Package. Title Utility Functions For GATK. Version 2.1.

Package SASmarkdown. R topics documented: November 30, Version Date Title 'SAS' Markdown

Package assertive.data

Package sfc. August 29, 2016

Package texpreview. August 15, 2018

Package genelistpie. February 19, 2015

Package tidyselect. October 11, 2018

Package pwrab. R topics documented: June 6, Type Package Title Power Analysis for AB Testing Version 0.1.0

Package parfossil. February 20, 2015

2 sybildynfba-package. Dynamic Flux Balance Analysis

Package catchr. R topics documented: December 30, Type Package. Title Catch, Collect, and Raise Conditions. Version 0.1.0

Interacting with Remote Systems + MPI

Package aws.transcribe

Package subtype. February 20, 2015

Package Rcsdp. April 25, 2016

COMP284 Scripting Languages Lecture 10: PHP (Part 2) Handouts

Package subplex. April 5, 2018

Package dotcall64. January 11, 2018

SAS 9.2 Foundation Services. Administrator s Guide

Package flsa. February 19, 2015

Package callr. January 30, 2018

Package wrswor. R topics documented: February 2, Type Package

IEMS 5722 Mobile Network Programming and Distributed Server Architecture

Package remotes. December 21, 2017

Package ecoseries. R topics documented: September 27, 2017

Package intcensroc. May 2, 2018

Package memoise. April 21, 2017

Package SAENET. June 4, 2015

Package ramcmc. May 29, 2018

Package Ohmage. R topics documented: February 19, 2015

Package raker. October 10, 2017

Package validara. October 19, 2017

Package slam. February 15, 2013

Package lumberjack. R topics documented: July 20, 2018

Package sejmrp. March 28, 2017

Package liftr. R topics documented: May 14, Type Package

Cloud-Native Applications. Copyright 2017 Pivotal Software, Inc. All rights Reserved. Version 1.0

Package Storm. February 19, 2015

Package Rcplex. February 15, 2013

IERG 4080 Building Scalable Internet-based Services

Package nodbi. August 1, 2018

Package qap. February 27, Index 5. Solve Quadratic Assignment Problems (QAP)

Package rgho. R topics documented: January 18, 2017

Package DSL. July 3, 2015

Package rscala. November 25, 2017

Package simplecache. August 22, 2017

Package datamap. February 19, 2015

Package bannercommenter

Transcription:

Type Package Package doredis February 19, 2015 Title Foreach parallel adapter for the rredis package Version 1.1.1 Date 2014-2-25 Author Maintainer A Redis parallel backend for the %dopar% function BugReports https://github.com/bwlewis/doredis/issues Depends R (>= 2.5), rredis (>= 1.6.8), foreach(>= 1.3.0), iterators(>= 1.0.0), utils Suggests boot License GPL-2 LazyLoad yes NeedsCompilation yes Repository CRAN Date/Publication 2014-04-03 18:30:30 R topics documented: doredis-package...................................... 2 redisworker......................................... 3 registerdoredis....................................... 4 removequeue........................................ 6 setchunksize........................................ 7 setexport.......................................... 8 setgettask.......................................... 9 settag............................................ 10 settasklabel........................................ 11 startlocalworkers...................................... 12 Index 15 1

2 doredis-package doredis-package A Redis-based back end for parallel computing with foreach. The doredis package supplies a lightweight, cross-platform parallel back end for the foreach %dopar% function. The foreach package for R defines a modular interface for back end parallel processing implementations. The doredis package imlpements a simple but very flexible parallel back end that uses Redis for inter-process communication. The doredis package requires a connection to an available Redis server (not included with the Two foreach parameters are specific to the doredis back end: chunksize (default value 1), and ftinterval (default value 30). The chunksize option sets the default number of jobs that are doled out to each worker process. Jobs are doled out one at a time by default. Setting the chunk size larger for shorter-running jobs can substantially improve performance. Setting this value too high can negatively impact load-balancing across workers, however. The ftinterval option sets the number of seconds between checks for back end worker failures. Failed jobs will be re-submitted after this interval. References http://cran.r-project.org/web/packages/foreach/index.html See Also foreach # The example assumes that a Redis server is running on the local host # and standard port. # 1. Open one or more worker R sessions and run: redisworker( jobs ) # We use the name jobs to identify a work queue. # 2. Open another R session acting as a master and run this simple

redisworker 3 # sampling approximation of pi: registerdoredis( jobs ) foreach(j=1:10,.combine=sum,.multicombine=true) %dopar% 4*sum((runif(1000000)^2 + runif(1000000)^2)<1)/10000000 redisworker redisworker Initialize a doredis worker R process. redisworker(queue, host = "localhost", port = 6379, iter = Inf, timeout = 30, log = stdout(), connected=false, password=null) queue host port iter timeout log connected password A (character) work queue name, or a list or character vector of queue names. The Redis server host name or (character) I. P. address. The Redis server port number. The maximum number of jobs to execute before exiting the worker loop (defaults to infinity). The worker loop terminates if the work queue is deleted after the specified timeout interval. Log messages to the specified destination (defaults to stdout()). Is the R session creating the worker already connected to Redis? The Redis server password. The redisworker function enrolls the current R session in one or more doredis worker pools specified by the work queue names. The worker loop takes over the R session until either the work queue(s) are deleted or the worker times out waiting for a new task.

4 registerdoredis Nothing is returned but status messages are printed to the log during operation of the worker loop. Note All doredis functions require network access to a Redis server (not included with the doredis See Also registerdoredis redisworker( jobs ) registerdoredis Register the doredis parallel back end with foreach. The doredis package supplies a simple and lightweight parallel back end for the foreach %dopar% function. registerdoredis(queue, host = "localhost", port = 6379, password=null) queue host port password A (character) work queue name. The Redis server host or (character) I. P. address. The Redis server port number. The Redis server password.

registerdoredis 5 Note The doredis package imlpements a simple but flexible parallel back end for foreach that uses Redis for inter-process communication. The work queue name specifies the base name of a small set of Redis keys that the master and worker processes use to exchange data. Back-end worker R processes advertise their availablility for work with the redisworker function. The doredis parallel back end tolerates faults among the worker processes and automatically resubmits failed tasks. It is also portable and supports heterogeneous sets of workers, even across operative systems. The back end supports dynamic pools of worker processes. New workers may be added to work queues at any time and can be immediately used by in-flight foreach computations. Nothing is returned. All doredis functions require network access to a Redis server (not included with the doredis References See Also http://cran.r-project.org/web/packages/foreach/index.html redisworker removequeue ## The example assumes that a Redis server is running on the local host ## and standard port. ## 1. Open one or more worker R sessions and run: redisworker( jobs ) ## 2. Open another R session acting as a master and run this simple ## sampling approximation of pi: registerdoredis( jobs ) foreach(j=1:10,.combine=sum,.multicombine=true) %dopar% 4*sum((runif(1000000)^2 + runif(1000000)^2)<1)/10000000 removequeue( jobs )

6 removequeue removequeue Remove doredis work queues. Use the removequeue function to delete one or more doredis work queues. removequeue(queue) queue A character work queue name or vector or list of queue names. Note This action will terminate the worker loops running on any corresponding back-end workers. Upon termination the workers will clean up any ancillary Redis keys. TRUE is returned if the queues were successfully deleted, FALSE and probably an error condition otherwise. All doredis functions require network access to a Redis server (not included with the doredis See Also registerdoredis # The example assumes that a Redis server is running on the local host # and standard port. # 1. Open one or more worker R sessions and run: redisworker( jobs ) # We use the name jobs to identify a work queue.

setchunksize 7 # 2. Open another R session acting as a master and run this simple # sampling approximation of pi: registerdoredis( jobs ) foreach(j=1:10,.combine=sum,.multicombine=true) %dopar% 4*sum((runif(1000000)^2 + runif(1000000)^2)<1)/10000000 removequeue( jobs ) setchunksize setchunksize Set the default granularity of distributed tasks. setchunksize(value = 1) value The new default chunk size. The setchunksize function lets users set the default number of jobs that are doled out to each worker process. The doredis package doles out jobs one at a time by default. Setting the default chunk size larger for shorter-running jobs can substantially improve performance. Setting this value too high can negatively impact load-balancing across workers, however. This value is overriden by setting the chunksize option in the foreach loop (see the examples). Nothing is returned. Note All doredis functions require network access to a Redis server (not included with the doredis

8 setexport setchunksize(10) ## Override the default value in a loop as shown in the following example: foreach(j=1:1000,.options.redis=list(chunksize=100)) setexport setexport Manually add symbol names to the worker environment export list. setexport(names = c()) names A vector of symbol names to export. The setexport function lets users manually declare symbol names of corresponding objects that should be exported to workers. The foreach function includes a similar.export parameter. We provide this supplemental export option for users without direct access to the foreach function, for example, when foreach is used within a package. Nothing is returned.

setgettask 9 require("doredis") registerdoredis("work queue") startlocalworkers(n=1, queue="work queue") f <- function() pi foreach(1) # Returns the error: # Error in eval(call("f")) : task 1 failed - could not find function "f" # Manuall export the symbol f: setexport("f") foreach(1) # Ok then. #[[1]] #[1] 3.141593 removequeue("work queue") setgettask setgettask Define a function used by workers to pull tasks. setgettask(fn = default_gettask) fn A task pulling function, see details below. The doredis package organizes work into a collections of tasks called a job. One job may contain several uniquely identified task collections, and jobs themselves are uniquely identified. The task collections are labeled by the tasklabel function. A doredis task is specifically a list of two elements: task_id and args, that specify the unique ID of the task collection, and the foreach loop expression arguments, respectively. As of version 1.1.0 of the doredis package, task collections are placed in a Redis hash table identified by the job ID. The gettask function is used by the R worker processes to pull tasks from this hash table. The gettask function must take at least two arguments, queue and job_id that

10 settag Note specify the job queue and job ID, respectively. The function should work with Redis to obtain and return a task collection, or return NULL if no tasks are available. The gettask function almost always defines a short Lua scipt run on the Redis server. The default gettask function removes tasks in the order that they appear in the hash table. Custom gettask functions can be defined often in association with custom tasklabel functions. The custom functions can instruct Redis to perferentially dole out tasks based on network distance to data, for example. Nothing is returned. All doredis functions require network access to a Redis server (not included with the doredis # The default gettask function defines a Redis Lua script that returns the first # listed task or NULL:sk <- function(queue, job_id,...) gettask <- function(queue, job_id,...) { key <- sprintf(" rediseval("local x=redis.call( hkeys,keys[1])[1]; if x==nil then return nil end; local ans=redis.call( hget,keys[1],x); redis.call( hdel,keys[1],x);i return ans",key) } setgettask(gettask) settag settag Set a worker tag reported to the gettask function.

settasklabel 11 settag(label) label A character label. Workers report their tags to the gettask function. They are ignored by this function by default. Use custom tags in combination with custom Redis server-side Lua scripts to define custom task-pulling behavior. Nothing is returned. settasklabel settasklabel Define a function that uniquely labels collections of tasks. settasklabel(fn = I) fn A task labeling function, see details below. The doredis package organizes work into a collections of tasks called a job. One job may contain several uniquely identified task collections, and jobs themselves are uniquely identified. The task collections are labeled by the tasklabel function. The tasklabel function must take exactly one argument, a single integer value. Its output must be coerceable into a character string and the function must be injective. The default gettask function removes tasks in the order that they appear in the hash table. Custom gettask functions can be defined often in association with custom tasklabel functions. The custom functions can instruct Redis to perferentially dole out tasks based on network distance to data, for example.

12 startlocalworkers Nothing is returned. Note All doredis functions require network access to a Redis server (not included with the doredis # The default gettask function defines a Redis Lua script that returns the first # listed task or NULL:sk <- function(queue, job_id,...) gettask <- function(queue, job_id,...) { key <- sprintf(" rediseval("local x=redis.call( hkeys,keys[1])[1]; if x==nil then return nil end; local ans=redis.call( hget,keys[1],x); redis.call( hdel,keys[1],x);i return ans",key) } settasklabel(fn = I) startlocalworkers startlocalworkers Start background R worker processes on the local system. startlocalworkers(n, queue, host = "localhost", port = 6379, iter = Inf, timeout = 30, log = stdout(), Rbin = paste(r.home(component="bin"),"r",sep="/"), password=null)

startlocalworkers 13 n queue host port iter timeout log Rbin password The number of workers to start. A (character) work queue name, or a list or character vector of queue names. The Redis server host name or (character) I. P. address. The Redis server port number. The maximum number of jobs to execute before exiting the worker loop (defaults to infinity). The worker loop terminates if the work queue is deleted after the specified timeout interval. Log messages to the specified destination (defaults to stderr()). The full path to the command-line R program. The Redis server password. Note 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. Running workers self-terminate when their work queues are deleted with the removequeue function. Nothing is returned. Set the log parameter to stdout() to see log messages printed on standard output of the invoking R session. All doredis functions require network access to a Redis server (not included with the doredis See Also registerdoredis redisworker registerdoredis( jobs ) startlocalworkers(n=2, queue= jobs ) print(getdoparworkers()) foreach(j=1:10,.combine=sum,.multicombine=true) %dopar% 4*sum((runif(1000000)^2 + runif(1000000)^2)<1)/10000000 removequeue( jobs )

14 startlocalworkers

Index doredis (doredis-package), 2 doredis-package, 2 foreach, 2 redisworker, 3, 5, 13 registerdoredis, 4, 4, 6, 13 removequeue, 5, 6 setchunksize, 7 setexport, 8 setgettask, 9 settag, 10 settasklabel, 11 startlocalworkers, 12 15