1

This question is an obscure problem - sorry for the length. I'm trying to deploy an app to Heroku. The app runs Rserve - a daemon of the R language, for running statistical reports. This should in principle be no more difficult than getting any daemon, such as memcached, to run in Heroku.

In Mac OSX I just start the daemon in the command line and forget it - all works fine. I'm interfacing with Rserve from node.js, using https://github.com/albertosantini/node-rio (not a factor here though).

But in deploying to Heroku, not having much luck. I'm using a multipack of R and node. Installation runs fine, all build steps exit okay, R starts fine.

Now comes the job of starting the Rserve daemon on the worker dyno.

My procfile looks like this:

web: node server.js
worker: R CMD Rserve --no-save

When I run it, I get the following error in the logs (scroll to end of block):

Rserv started in daemon mode.
heroku[worker.1]: State changed from starting to crashed

The Rserve() config docs are here: http://www.rforge.net/Rserve/doc.html I am not expert at configuring it but perhaps there is something in there that I should be doing for it to work in this environment?

An oddity is that you can run this without error from the Heroku run console, but (see below), it does not seem to actually be running when I try to access it from node.js:

heroku run R CMD Rserve

[Previously saved workspace restored]

Rserv started in daemon mode. >

In node.js (heroku run node), I try testing it thus:

var rio = require('rio');
rio.evaluate("pi / 2 * 2");

which gives the error "Rserve call failed".

This leads me to think something is fundamentally wrong with what I am trying to do or how I am trying to do it.

metalaureate
  • 7,572
  • 9
  • 54
  • 93
  • So I tried a dozen ways to get it started on a worker dyno, but all would crash. I never got to the bottom of all environment issues - I am not very expert at Unix. However... I did get it work by spawning a child process to run Rserve at the end of my server.js initialization script on my web dyno. It works, but does it strike you as crazy or brittle? `childProcess.exec('R CMD Rserve --save', function (error, stdout, stderr) {});` – metalaureate Jul 22 '13 at 00:38
  • My plan is to implement it this way in the worker process and use Web Workers to communicate between the separate environments. https://github.com/pgriess/node-webworker/blob/master/README.md – metalaureate Jul 22 '13 at 02:28

2 Answers2

2

Rserve runs as a daemon by default, so use a script to execute it so it runs "in process".

E.g.

# example R script for executing Rserve
require('Rserve')

# get the port from environment (heroku)
port <- Sys.getenv('PORT')

# run Rserve in process
run.Rserve(debug = FALSE, port, args = NULL, config.file = "rserve.conf")

And then your Procfile will have an entry as follows:

rserve: R -f rserve.r --gui-none --no-save
VirtualStaticVoid
  • 1,656
  • 3
  • 15
  • 21
0

So I tried a dozen ways to get it started on a worker dyno, but all would crash. I never got to the bottom of all environment issues - I am not very expert at Unix. However... I did get it work by spawning a child process to run Rserve at the end of my server.js initialization script on my web dyno. It works.

childProcess.exec('R CMD Rserve --no-save', function (error, stdout, stderr) {});

My plan is to implement it this way in the worker process and use Web Workers to communicate between the separate environments.

metalaureate
  • 7,572
  • 9
  • 54
  • 93