Re: [Rd] concurrent requests (Rook, but I think the question is more general)

From: Dan Tenenbaum <>
Date: Wed, 24 Oct 2012 11:23:31 -0700

On Wed, Oct 24, 2012 at 11:13 AM, Richard D. Morey <> wrote:
> This question involves Rook, but I think the answer will be general enough
> that it pays to post here. At any rate, I don't know enough to know whether
> this is a Rook only issue or a general R issue.
> Here's what I'd like to do (and indeed, have code that should do this):
> 1. Start R, Rook
> 2. Start an analysis via a HTTP request to Rook. This analysis uses .Call()
> to some compiled C code, if that matters. The C code calls a callback
> function to update a variable with its progress.
> 3. While the analysis is happening, use Rook to obtain current status with
> an HTTP request
> The problem is that once the analysis starts, Rook does not respond to
> requests. All of the status requests to Rook pile up, and then are answered
> when the analysis (step 2) is done. Here is some example code to demonstrate
> what the issue:
> ##########
> library(Rook)
> s <- Rhttpd$new()
> s$add(
> name="pingpong",
> app=Rook::URLMap$new(
> '/ping' = function(env){
> req <- Rook::Request$new(env)
> res <- Rook::Response$new()
> res$write('This is ping.')
> Sys.sleep(20)
> res$finish()
> },
> '/pong' = function(env){
> req <- Rook::Request$new(env)
> res <- Rook::Response$new()
> res$write("This is pong.")
> res$finish()
> },
> '/?' = function(env){
> req <- Rook::Request$new(env)
> res <- Rook::Response$new()
> res$redirect(req$to_url('/pong'))
> res$finish()
> }
> )
> )
> s$start(quiet=TRUE)
> s$browse('pingpong')
> #############################
> If you request /ping, R runs Sys.sleep() for 20 seconds. This is where my
> .Call() statement would be. While the .Call() (Sys.sleep()) function is
> doing its thing, I need to get Rook to respond on /pong (which would simply
> respond with the progress), but if you run this code, request /ping, then
> immediately request /pong, you'll see that the /pong request will not be
> answered until the Sys.sleep() is done.
> Of course, for a progress report to be useful, the requests have to be
> answered immediately. Is this a Rook issue, or an R issue? Or am I asking
> something unreasonable?

One answer would be to start an Rserve instance on your local machine. When your web app initiates processing, it actually starts the long-running task on the server with RS.eval(wait=FALSE). See ?RCC with the RS.client package loaded.
Then when you check for task completion, call RS.collect () with a short timeout, and if it has something for you it will give it to you.

That doesn't give you a numeric progress report, but perhaps if your long-running task writes its status somewhere (to a file?) the progress-checking task could look there as well.


> ______________________________________________
> mailing list
> mailing list Received on Wed 24 Oct 2012 - 18:25:38 GMT

This quarter's messages: by month, or sorted: [ by date ] [ by thread ] [ by subject ] [ by author ]

All messages

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 24 Oct 2012 - 19:20:49 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.

list of date sections of archive