2

我在 sidekiq 工作人员中使用 em-synchrony 和 em-http-request (Ruby 2.1) 同时抓取多个链接。一切正常,除非我尝试同时使用刮板运行多个工人。这是我正在使用的代码:

def process(web_pages)
  EM.synchrony do
    EM::Synchrony::Iterator.new(web_pages, concurrency=50).map do |web_page, iter|
      EventMachine::HttpRequest.new(web_page.url, request_options).get(redirects:10)
    end
    EventMachine.stop
  end
end

当这个工作进程在同时运行多个实例的情况下运行时,它最终会抛出以下错误:

WARN: FiberError: fiber called across threads
WARN: ruby-2.1.0/gems/em-synchrony-1.0.4/lib/em-synchrony/iterator.rb:28:in `resume'
/ruby-2.1.0/gems/em-synchrony-1.0.4/lib/em-synchrony/iterator.rb:28:in `block in map'
/ruby-2.1.0/gems/eventmachine-1.0.8/lib/em/iterator.rb:172:in `call'
/ruby-2.1.0/gems/eventmachine-1.0.8/lib/em/iterator.rb:172:in `block in map'
/ruby-2.1.0/gems/eventmachine-1.0.8/lib/em/iterator.rb:206:in `call'
/ruby-2.1.0/gems/eventmachine-1.0.8/lib/em/iterator.rb:206:in `block in inject'
/ruby-2.1.0/gems/em-synchrony-1.0.4/lib/em-synchrony/iterator.rb:17:in `call'
/ruby-2.1.0/gems/em-synchrony-1.0.4/lib/em-synchrony/iterator.rb:17:in `block in each'
/ruby-2.1.0/gems/eventmachine-1.0.8/lib/em/iterator.rb:95:in `call'
/ruby-2.1.0/gems/eventmachine-1.0.8/lib/em/iterator.rb:95:in `block in each'
/ruby-2.1.0/gems/eventmachine-1.0.8/lib/em/iterator.rb:117:in `call'
/ruby-2.1.0/gems/eventmachine-1.0.8/lib/em/iterator.rb:117:in `block (2 levels) in each'
/ruby-2.1.0/gems/eventmachine-1.0.8/lib/em/iterator.rb:195:in `call'
/ruby-2.1.0/gems/eventmachine-1.0.8/lib/em/iterator.rb:195:in `block (2 levels) in inject'
/ruby-2.1.0/gems/eventmachine-1.0.8/lib/em/iterator.rb:161:in `call'
/ruby-2.1.0/gems/eventmachine-1.0.8/lib/em/iterator.rb:161:in `block (2 levels) in map'
4

0 回答 0