How get best performance rails requests parallel sidekiq worker

前端 未结 1 1678
有刺的猬
有刺的猬 2021-01-03 13:01

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条回答
  •  一生所求
    2021-01-03 13:42

    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

    0 讨论(0)
提交回复
热议问题