How get best performance rails requests parallel sidekiq worker

ε祈祈猫儿з 提交于 2019-12-09 01:48:50

问题


My rails app have one sidekiq worker. The worker will do 2500 requests to a api external, the response is a xml. How get best performance for this worker?


回答1:


Inside the worker, spawn application level Threads.

For example, Create 10 ruby threads to process the 2500 external api requests(means each ruby thread will process 250 requests).

  # threads will contain the threads
  threads = [] 
external_requests.each_slice(250) do |group| threads << Thread.new(group) do |tsrc| tsrc.each do |ex_request| # Do your external call here end end end threads.each(&:join) # wait for all threads to finish


来源:https://stackoverflow.com/questions/22316102/how-get-best-performance-rails-requests-parallel-sidekiq-worker

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!