How Many Rails Apps on 1 Heroku Dyno

Rails & Heroku: How many workers/dynos do I need

Not sure you're asking the right question. Your real question is "how can I get better performance?" Not "how many dynos?" Just adding dynos won't necessarily give you better performance. More dynos give you more memory...so if your app is running slowly because you're running out of available memory (i.e. you're running on swap), then more dynos could be the answer. If those jobs take 10 seconds each to run, though...memory probably isn't your actual problem. If you want to monitor your memory usage, check out a visualization tool like New Relic.

There are a lot of approaches to solving your problem. But I would start with the code that your wrote. Posting some code on SO might help understand why that job takes 10 seconds (Post some code!). 10 seconds is a long time. So optimizing the queries inside that job would almost surely help.

Another piece of low hanging fruit...switch from resque to sidekiq for your background jobs. Really easy to use. You'll use less memory and should see an instant bump in performance.

what is the tradeoff between using larger dynos vs more dynos on Heroku

As far as I know as you already mentioned Heroku routers don't know and care about load in a specific dyno and sends the request by a random selection algorithm. https://devcenter.heroku.com/articles/http-routing

So it is very likely to see many consecutive requests going to same dyno. I am observing that behaviour with my current applications.

But in your case if a worker need 230MB then you can't use 2 worker in a Standard-1X dyno because their max memory is 512M. So I think you should definitely go for 2X dynos with like 3-4 workers. 2X dynos can use up to 1GB memory.

What is the difference between four 1X dynos and two 2X dynos in heroku?

More dynos give you more concurrency. Based on a single threaded web server such as thin, if you have 4 x 1x dynos, you can serve four requests at the same time.

With 2 x 2x dynos you can only serve two requests.

2x dynos have more memory (1024MB) and more CPU available. This is useful if your application takes up a lot of memory. Most apps should not need 2x dynos.

Heroku have recently added PX dynos as well, which have significantly more power available.

You can read about the different dynos Heroku offers on their website.

Heroku: How to open rails api dyno on port 3001

From the Heroku Procfile docs:

The web process type is special as it’s the only process type that will receive HTTP traffic from Heroku’s routers. Other process types can be named arbitrarily.

If you want to have multiple HTTP applications running, you’re going to have to accomplish that a different way, as you can’t have more than one HTTP process type in an app. One option would be to run a completely separate Heroku app for the other HTTP app.



Related Topics



Leave a reply



Submit