Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I have a tinder style app that allows users to rate events. After a user rates an Event, a background resque job runs that re-ranks the other events based on user's feedback.

This background job takes about 10 seconds and it runs about 20 times a minute per user.

Using a simple example. If I have 10 users using the app at any given time, and I never want a job to be waiting, what's the optimal way to do this?

I'm confused about Dynos, resque pools, and redis connections. Can someone help me understand the difference? Is there a way to calculate this?

like image 320
Jackson Cunningham Avatar asked Oct 04 '16 22:10

Jackson Cunningham


People also ask

What are Rails used for?

Rails is a development tool which gives web developers a framework, providing structure for all the code they write. The Rails framework helps developers to build websites and applications, because it abstracts and simplifies common repetitive tasks.

Does Netflix use Rails?

Basecamp, GitHub, Shopify, Airbnb, Hulu and Zendesk all retain elements of Ruby On Rails, as does streaming behemoth Netflix. One of the most popular – arguably era-defining – ways of accessing media still uses Rails and does so very successfully – and that's not to be sniffed at.

Is Rails a backend or frontend?

Ruby on Rails is used as a backend framework for web applications. It's known for efficiency and scalability. You can write rich functionality with much fewer lines of code as opposed to what you'd need in Java or Node.

Is GitHub still using Rails 2022?

Many large companies (Imgur, Github, Twitch.tv, and others) still use RoR for their apps. The foundation for a future for the Ruby on Rails framework has been set. As long as RoR's features and functionality are among the best, well-known companies will continue using it in development.


1 Answers

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.

like image 177
toddmetheny Avatar answered Sep 22 '22 11:09

toddmetheny