0
我使用eventmachine来创建很多http查询。 Http服务器可以执行这些连接。 但是对100个查询定期调用5-7 errback。 为什么会这样?很多查询到eventmachine
require 'rubygems'
require 'eventmachine'
require 'em-http'
urls = []
100.times do
urls << 'http://127.0.0.1/'
end
if urls.size < 1
puts "Usage: #{$0} <url> <url> <...>"
exit
end
pending = urls.size
EM.run do
urls.each do |url|
http = EM::HttpRequest.new(url).get
http.callback do
puts "#{url}\n#{http.response_header.status} - #{http.response.length} bytes\n"
pending -= 1
EM.stop if pending < 1
end
http.errback do
puts "E::#{url}\n" + http.error.to_s
pending -= 1
EM.stop if pending < 1
end
end
end
}
什么样的错误?这可能与连接的另一端有关,例如,如果其他服务器只能处理50个并发连接,它可能会在超出连接时开始拒绝连接 – 2011-12-26 18:18:07
仅供参考,您可能需要查看[Typhoeus及其关联Hydra](https://github.com/dbalatero/typhoeus),如果你想异步执行多个HTTP请求。 – 2011-12-26 20:48:38