oni*_*ram 1 ruby parallel-processing multithreading ruby-on-rails sidekiq
我的rails应用程序有一个sidekiq工作者.工作人员将对api外部执行2500个请求,响应为xml.如何为这名工人获得最佳表现?
在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
| 归档时间: |
|
| 查看次数: |
666 次 |
| 最近记录: |