Running Rook on Heroku (with working example)

118 views
Skip to first unread message

Noah

unread,
Sep 25, 2011, 5:30:24 PM9/25/11
to rRook
Hi all-

About a week ago, I succeeded in building R 2.13.1 on Heroku
(www.heroku.com). For those of you who aren't familiar, Heroku is a
popular hosting platform for Ruby on Rails, NodeJS, and other
applications -- it makes it easy to have an application running with
little more than a "git push". Getting R on it ends up being a bit
tricky, since it's not installed by default, it's a read-only
filesystem, and there's no root access to just do a "sudo apt-get
install".

My original purpose in installing R was to call it from a ruby app to
provide some statistics capabilities, but it wasn't a big leap from
there to get Rook running on Heroku. I've put a more detailed readme
(still quite rough) and code for a working example at
https://github.com/noahhl/rookonheroku -- you can see the working demo
at http://rookonheroku.herokuapp.com/custom/RookTest.

I'll leave the full details to the readme on github, but the short
story of how to do this is:
1) Create a dummy Heroku ruby app, push it, get shell access, install
dependencies and build R. Then copy your built R back to your computer
(or start from the demo repo on GH).
2) Build your rook application. Set it to run bound to 0.0.0.0 and on
the port specified by the environment variable PORT.
3) Wrap up your rook application to be run via ruby -- this is needed
because Heroku doesn't know we're running a web server if we directly
launch R, but we can tell it it's launching a webserver via a
config.ru file, and then just do whatever we wish with that file.

It's not as easy as getting a Rails app running on Heroku, but
hopefully folks find this useful. Happy to try to answer any questions
people have.

Noah

Jeroen Ooms

unread,
Sep 25, 2011, 9:31:12 PM9/25/11
to rr...@googlegroups.com
Thanks cool stuff. What exactly is the advantage of running rook on heroku instead of a vps or cloud instance?

Noah Lorang

unread,
Sep 26, 2011, 4:01:42 AM9/26/11
to rr...@googlegroups.com
There's nothing magical about it -- fundamentally, it's just another type of shared hosting running on EC2. It can be a little easier / cheaper for small applications -- their pricing model gets you a single process running 24x7 and a 20MB database for free, and you save a bit of effort in setting up some of the things they provide out of the box:  proxying to multiple instances of R, something to restart processes if they crash, etc.

Aleksandar Blagotić

unread,
Sep 26, 2011, 6:25:47 AM9/26/11
to rr...@googlegroups.com
OK, I definitely gotta start learning Ruby...

--
aL3xa

Jeffrey

unread,
Sep 29, 2011, 10:38:30 AM9/29/11
to rRook
This is fantastic!

So are you only running one instance of the rook application?

On Sep 25, 4:30 pm, Noah <lor...@gmail.com> wrote:
> Hi all-
>
> About a week ago, I succeeded in building R 2.13.1 on Heroku
> (www.heroku.com). For those of you who aren't familiar, Heroku is a
> popular hosting platform for Ruby on Rails, NodeJS, and other
> applications -- it makes it easy to have an application running with
> little more than a "git push". Getting R on it ends up being a bit
> tricky, since it's not installed by default, it's a read-only
> filesystem, and there's no root access to just do a "sudo apt-get
> install".
>
> My original purpose in installing R was to call it from a ruby app to
> provide some statistics capabilities, but it wasn't a big leap from
> there to get Rook running on Heroku. I've put a more detailed readme
> (still quite rough) and code for a working example athttps://github.com/noahhl/rookonheroku-- you can see the working demo
> athttp://rookonheroku.herokuapp.com/custom/RookTest.

Noah Lorang

unread,
Sep 29, 2011, 10:41:19 AM9/29/11
to rr...@googlegroups.com
Right, in this case it's just running a single instance (since I don't want to actually pay for more workers), but you can scale it up at will by running `heroku ps:scale web=10`, which will spawn 10 instances of the rook app. Heroku will then automatically distribute traffic among them, since they're binding to the ports it specifies in the environment variable (I've tested this works with a few web workers spun up). Of course, as in any case where you're running multiple processes, this does mean that your app needs to be stateless.

Noah Lorang

unread,
Sep 29, 2011, 10:47:49 AM9/29/11
to rr...@googlegroups.com
I should also add, with this implementation, you're stuck with the default URLs you get out of Rook, which will all be /custom/ based. You could insert a piece of middleware to rewrite them, but that's kind of irritating. I'd actually rather if R had a greater willingness to allow alternate URLs, but I've long ago given up on patching R-core in any substantive way….


On Sep 29, 2011, at Sep 29 10:38 AM , Jeffrey wrote:

Reply all
Reply to author
Forward
0 new messages