Ari
Ari

Reputation: 2004

How do I handle long requests for a Rails App so other users are not delayed too much?

I have a Rails app on a free tier on Heroku and it recently started getting some users. One of the events in my app involves querying another API and can take up to 10 seconds to finish. How do I make sure other users who visit a simple page at the same time (as another user's API event) don't need to wait 10 seconds for their page to load?

Do I need to pay for more Dynos? Is this something that can be solved with the delayed_job gem? Would another host (like AppFog or OpenShift) be able to handle simultaneous requests faster?

Update: This question suggest manually handling threads instead of using delayed_job.

Upvotes: 0

Views: 883

Answers (3)

Rodrigo Zurek
Rodrigo Zurek

Reputation: 4575

Yes you need more dynos, speccialy worker dynos those are the ones that work on the background you can check this railscast on delayed jobs that can help also:

http://railscasts.com/episodes/366-sidekiq

also here is a quick tutorial on adding unicorn and multiple threads to your free heroku instance:

https://devcenter.heroku.com/articles/rails-unicorn

you divide your dyno into two or more instances then each one can handle a different request

Upvotes: 1

usha
usha

Reputation: 29349

What kind of app server are you using? If you are using passenger or unicorn, you can have multiple worker processes that can handle simultaneous requests

http://www.modrails.com/documentation/Users%20guide%20Apache.html#_passengermaxinstancesperapp_lt_integer_gt

Upvotes: 0

bgates
bgates

Reputation: 2373

That sounds like a Delayed Job situation. If the first request is just waiting, the most efficient thing to do is assign a process to wait for it to complete and cut the Rails process loose to handle another request.

Upvotes: 1

Related Questions