Re: Concurrent requests?

58 views
Skip to first unread message

Richard Morey

unread,
Nov 24, 2012, 11:47:33 AM11/24/12
to rr...@googlegroups.com
I ended up doing this with Rserve, since Windows doesn't support forking.

On Tuesday, November 13, 2012 3:44:12 PM UTC+1, Daniel Mahler wrote:
Hi Richard,

I think the easiest way to do this is to set up rApache
and deploy your Rook app through that.
You need to run Apache in forking mode.
Whenever Apache for to service a request,
it will fork the embedded R image & your loaded Rook app with it.
I do not think there is an easy way to do it using only Rook
beacuse the built in http server is single threaded.

cheers
Daniel


On Wednesday, October 24, 2012 6:20:38 PM UTC+2, Richard Morey wrote:
I'm writing an interface for an R package, and since I know javascript and HTML I figured Rook would be good to use. Basically, my interface sends requests for analysis results to R via Rook, and R does some analysis. The analysis can take some time, so I'd like to be able to get a progress bar working on the HTML side. My idea is this:

1. JSON request to start the analysis (in my case a .Call() to compiled C code) in R.
2. During the analysis, a callback function updates an R environment in which the progress is recorded as a variable
3. JSON requests during the analysis check the variable every second or so
4. When the analysis is done, Rook returns to my javascript the appropriate final results
5. Scheduled update requests stop

I have code that implements this, but the problem is none of my update requests (step 3) are responded to until the analysis (step 1) is done. R is tied up doing the analysis. This basic code shows what happens:

########
# R code
########

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()
    }
  )
)
## Not run:
s$start(quiet=TRUE)
s$browse('pingpong') 

##################

If you request /ping, the Sys.sleep() function ties up Rook. This is analogous (at least, I think) with what happens with my analysis code. But I'd like requests for /pong to be responded to in that 20 second interval. How can I get this to work? 

Reply all
Reply to author
Forward
0 new messages