如何获得最佳性能rails请求并行sidekiq worker

时间:2014-03-11 03:50:59

标签: ruby-on-rails ruby multithreading parallel-processing sidekiq

我的rails应用程序有一个sidekiq工作者。 工作人员将对api外部执行2500个请求,响应为xml。 如何为这名工人获得最佳表现?

1 个答案:

答案 0 :(得分:7)

在worker中生成应用程序级别Threads。

例如,创建10个ruby线程来处理2500个外部api请求(意味着每个ruby线程将处理250个请求)。

  # 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