jay
jay

Reputation: 12495

Running multiple rails servers for same app

So I was wondering, Heroku can run multiple dynos to handle a growing number of requests. This scalability is one of the greatest value propositions.

Is it possible to something similar locally? Essentially, I am developing an app and it runs a lot of requests and calculations that I am testing out. For the time being, much of the calculation is run by the rails server, so a request to load a page with sorted material can take a minute or more. Eventually I am going to move these calculations to the background using delayed_job, but I'm still developing my algorithm so I am not trying to make that change yet.

SO what I am wondering is, can I run multiple rails servers so that on one I can click around the website and on the other run these calculations? I tried opening two on different ports, but they don't run well concurrently (to the point of almost not running at all).

Any advice is greatly appreciated!

Upvotes: 1

Views: 1027

Answers (3)

Steve Wilhelm
Steve Wilhelm

Reputation: 6260

I would echo the others that have said it would be good to eventually split out your calculations into workers. I would recommend looking at Resque as an alternative to delayed_job. We use Resque in combination to RedisToGo in development as well as with all our Heroku-based production applications. We at Euclid Inc. are big fans of Heroku and Redis.

In the mean time, you can get dyno like behavior in development with Unicorn and Foreman. Again we use Unicorn in production to make our Heroku-based applications even more efficient.

Unicorn is easy to configure. Just set add the appropriate gems and create a Procfile and you get multiple processes with no code changes.

Upvotes: 0

Hauleth
Hauleth

Reputation: 23556

Yes U can do it for example by:

$ for port in `seq 3000 3005`; do run server --on-port $port; done

Then you will have 5 servers on port from 3000 to 3005. And then use some reverse proxy to catch all request's on one port and then sending them to servers.

You can try also foreman to do this, but IMHO if you need to do this for testing then there is something wrong in application design not in server. Maybe you shall move some tasks to for example EventMachine and run them in external process (for example generating some documents or parsing data).

Upvotes: 0

Michael Durrant
Michael Durrant

Reputation: 96454

My advice is to start using the background job method now. All you'll be doing is having the same code running... in the background. You should be able to do it in 5 minutes. Right now you're probably spending a lot of time on other solutions that can be spent on the code. Once you start using delayedJob, bachgrouddrb or another option you won't look back.
There is a good post here that may help you:
http://www.tobinharris.com/past/2009/3/9/6-ways-to-run-background-jobs-in-rubyonrails/ and also
Ruby on Rails: How to run things in the background?

Upvotes: 1

Related Questions