9

I’m writing a webserver that sometimes has to pass data through a R script.

Unfortunately startup is slow, since i have to load some libraries which load other libraries etc.

Is there a way to either

  • load libraries, save the interpreter state to a file, and load that state fast when invoked next time? Or

  • maintain a background R process that can be sent messages (not just lowlevel data streams), which are delegated to asynchronous workers (i.e. sending a new message before the previous is parsed shouldn’t block)

R-Websockets is unfortunately synchronous.

9
  • have you looked at opencpu? <public.opencpu.org/api.html> and <public.opencpu.org/jslib.html>
    – Troy
    Commented Jan 29, 2014 at 13:26
  • 2
    i’ll look at it. thanks to the “cloud to butt” addon, its homepage looks very promising: “Scientific computing in my butt” Commented Jan 29, 2014 at 14:56
  • @Troy sorry, this doesn’t seem to do what i want. it seems to be a REST interface, but i just need to invoke R from server software running on the same machine. sorry for the confusion. Commented Jan 29, 2014 at 15:59
  • OK but you can persist objects in the opencpu session (to keep state) - then the next time you call them by objectID (e.g. on localhost) you don't need to go through the computation and load overhead. But not sure if that was what you were after?
    – Troy
    Commented Jan 29, 2014 at 16:12
  • Rserve and FastRWeb might be helpful. Commented Jan 29, 2014 at 17:47

1 Answer 1

3

Rserve and RSclient is an easy way to do create and use an Async server.

Open two R sessions.

in the first one type:

require(Rserve)
run.Rserve(port=6311L)

in the second one type:

require(RSclient)
rsc = RS.connect(port=6311L)
# start with a synchronous call
RS.eval(rsc, {x <<- vector(mode="integer")}, wait=TRUE)
# continue with an asynchronous call
RS.eval(rsc, {cat("begin")
              for (i in 1:100000) x[[i]] <-i
              cat("end")
              TRUE
        }, 
        wait=FALSE)
# call collect until the result is available
RS.collect(rsc, timeout=1)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.