albertosantini / node-rio

Integration with Rserve, a TCP/IP server for R framework
https://github.com/albertosantini/node-conpa
MIT License
176 stars 35 forks source link

Deploying node-rio on Heroku help #5

Closed metalaureate closed 11 years ago

metalaureate commented 11 years ago

node-rio is genius and a godsend, and has become an essential component in my app locally. But I can't figure out how to deploy it on Heroku. I think this is an Rserver/Heroku issue, and nothing to do with any defect in your module, it's just that I have exhausted all other avenues and don't know who else to ask who might know or have an interest.

I've wrapped up my travails here:

http://stackoverflow.com/questions/17768389/how-to-get-the-daemon-rserve-running-as-worker-dyno-on-heroku

I'd be very sincerely grateful if you had any ideas.

albertosantini commented 11 years ago

Maybe you may try to start Rserve directly, without R console, using a script shell.

When I debug rio on windows, I start Rserve from command line, setting a few environment variables, for instance PATH and maybe R_HOME.

Don't forget finally to configure Rserve.conf to enable remote connections and to set a password: http://www.rforge.net/Rserve/doc.html#conf

You may try locally the new configuration and then you replicate it in Heroku.

If you start Rserve debug version, you might narrow the issue: if there is a problem with the port, if there is a problem with the environment, etc.

metalaureate commented 11 years ago

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? Here's the code:

var childProcess = require('child_process'), rserve;

rserve = childProcess.exec('R CMD Rserve --save', function (error, stdout, stderr) { if (error) { console.log(error.stack); console.log('Error code: '+error.code); console.log('Signal received: '+error.signal); } console.log('Child Process STDOUT: '+stdout); console.log('Child Process STDERR: '+stderr); });

rserve.on('exit', function (code) { console.log('Child process exited with exit code '+code); require('rio').evaluate("pi / 2 * 2"); });

albertosantini commented 11 years ago

Glad to hear you resolved the Heroku issue. Thanks for sharing.

R CMD approach is a good one, because it sets the environment correctly for Rserve. Maybe there is a bit of overhead starting the Rserve process from node, but if it works, it is brittle. :)

metalaureate commented 11 years ago

Ha, yeah.

I was thinking I would use Web Workers to isolate Rserve to a worker process and communicate with it via rio.

https://github.com/pgriess/node-webworker

mikeschaekermann commented 11 years ago

Hi metalaureate!

Great to hear you got this finally working. I am stuck in the same problem! By starting Rserve as a child process from the node.js script, will it keep running as daemon in the background or do you have to restart it every time you want to make a call to rio.evaluate() ?

Btw. have you managed to isolate Rserve into a web worker?

Any help would be greatly appreciated!