如何获得最佳性能Rails要求并行Sidekiq Worker [英] How get best performance rails requests parallel sidekiq worker
本文介绍了如何获得最佳性能Rails要求并行Sidekiq Worker的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的Rails应用程序有一个sidekiq工人. 工作者将向api外部发出2500个请求,响应为xml. 如何为这名工人获得最佳表现?
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?
推荐答案
在工作进程内部,生成应用程序级线程.
例如,创建10个ruby线程来处理2500个外部api请求(意味着每个ruby线程将处理250个请求).
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
这篇关于如何获得最佳性能Rails要求并行Sidekiq Worker的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文