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

后端 未结 3 970
醉梦人生
醉梦人生 2021-01-26 02:43

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 t

相关标签:
3条回答
  • 2021-01-26 03:02

    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

    0 讨论(0)
  • 2021-01-26 03:10

    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.

    0 讨论(0)
  • 2021-01-26 03:10

    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

    0 讨论(0)
提交回复
热议问题