我如何处理Rails应用程序的长时间请求,以便其他用户不会延迟太多? [英] How do I handle long requests for a Rails App so other users are not delayed too much?
问题描述
我在Heroku的免费套餐上有一个Rails应用程序,它最近开始接触一些用户。我的应用中的一个事件涉及查询另一个API,最多可能需要10秒才能完成。我如何确保同时访问简单页面的其他用户(作为另一个用户的API事件)不需要等待10秒来加载页面?
我需要支付更多的Dynos吗?这是可以用delayed_job gem解决的吗?另一个主机(如AppFog或OpenShift)能够更快地处理同时请求?
更新:
这个问题建议手动处理线程,而不是使用delayed_job。
是的,您需要更多的dynos,speccialy工人dynos这些工作在后台可以检查对延迟工作的railscast,也可以帮助:
http ://railscasts.com/episodes/366-sidekiq
这里还有一个关于在您的免费heroku实例中添加独角兽和多线程的快速教程:
https://devcenter.heroku.com / articles / rails-unicorn
你将你的dyno分成两个或更多的实例,那么每个人可以处理不同的请求
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.
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
这篇关于我如何处理Rails应用程序的长时间请求,以便其他用户不会延迟太多?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!