我使用eventmachine创建了很多http查询。Http服务器可以执行这些连接。但是周期性地在100个查询上调用5-7个错误返回。为什么会这样呢?
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
}发布于 2011-12-28 13:51:33
您的localhost可以处理多少查询?你以127.0.0.1的速度发送100个并发请求,它能处理100个并发请求吗?否则,请求将排队,并且可能在EM::HttpRequest中超时。
EM::HttpRequest默认连接超时为5秒,默认不活动超时为10秒。
尝试在本地主机上运行ab,看看它每秒可以处理多少个请求。
https://stackoverflow.com/questions/8637805
复制相似问题