gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-03 17:16:00 27 4
gpt4 key购买 nike

我的 Rails 应用有一个 sidekiq worker。工作人员将向外部 api 发出 2500 个请求,响应是一个 xml。如何让这个 worker 获得最佳表现?

最佳答案

在 worker 内部,生成应用程序级线程。

例如,创建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

关于ruby-on-rails - 如何获得最佳性能 rails 请求并行 sidekiq worker,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22316102/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com