简体   繁体   中英

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). 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. Could you specify which server are you using? Can you make an Apache Benchmark and post the results? Maybe a little more information on your setup could help.

If you are using WEBrick, I would advise trying with 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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