简体   繁体   English

使用Rails控制器接受大量请求的正确方法是什么?

[英]What is right way to accept a lot of requests with Rails controller?

My app controller accepts requests from third party API (webhooks), but when it becomes 400 RPM my site goes down (too many clients). 我的应用控制器接受来自第三方API(webhooks)的请求,但当它变为400 RPM时,我的网站出现故障(客户太多)。 What can I do with it? 我该怎么办?

class CallbacksController < ApplicationController
def acceptor
    if params['type'] == 'confirmation' # this type is rare. only when client switches on callback
      group_setting = GroupSetting.find_by_callback_token(params[:callback_token])
      if group_setting
        group_setting.update_attribute(:use_callback, true)
        GroupSetting.new.callback_start(group_setting.group, group_setting.user)
        render text: group_setting.response_string
      else
        render text:'ok'
      end
    else
      CallbackWorker.perform_async(params[:callback_token], params['type'],
                                       params['group_id'], params['object'],
                                       params['secret'])
      render text:'ok'
    end
  end
end

It seems to me that you have a web server thread bottleneck. 在我看来,你有一个Web服务器线程瓶颈。 Could you specify which server are you using? 你能指定你使用的服务器吗? Can you make an Apache Benchmark and post the results? 你能制作一个Apache Benchmark并发布结果吗? Maybe a little more information on your setup could help. 也许有关您的设置的更多信息可能有所帮助。

If you are using WEBrick, I would advise trying with PUMA . 如果您使用的是WEBrick,我建议您尝试使用PUMA

I would also suggest that you check out Passenger that integrates easily with NGINX or Unicorn , that can help you with load balancing your requests. 我还建议您查看与NGINX或Unicorn轻松集成的Passenger ,它可以帮助您平衡您的请求。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM