开发者

Improve Controller Performance Ruby on Rails

I have the following code in a controller

user = RegUser.create_reg_user(:some_parameters)
UserStuff.pass_user(some_parameters)
@hex = 开发者_如何学运维user.hex

The @hex is passed to the view and returned. The UserStuff call is taking a decent amount of time and is not actually important to the @hex which is needed for the view. Is there a way to go ahead and return the @hex and load the view and let the UserStuff process afterwards?


Offload these kinds of long running "jobs" to a background queue. Probably the easiest for you to get setup and running is Delayed Job.

We use Beanstalkd (a queue) and many worker processes to handle all long-running tasks (or any tasks that takes longer than 1-2 seconds).

The beauty of having a background system to process these kinds of jobs is that you can scale quickly, you can spin-up any number of worker processes which all pull jobs from a master queue (or DB in the case of Delayed Job).


Delayed Job is good, and easy to use. I recommend it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜