首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >对eventmachine的大量查询

对eventmachine的大量查询
EN

Stack Overflow用户
提问于 2011-12-27 01:25:05
回答 1查看 347关注 0票数 0

我使用eventmachine创建了很多http查询。Http服务器可以执行这些连接。但是周期性地在100个查询上调用5-7个错误返回。为什么会这样呢?

代码语言:javascript
复制
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
}
EN

回答 1

Stack Overflow用户

发布于 2011-12-28 13:51:33

您的localhost可以处理多少查询?你以127.0.0.1的速度发送100个并发请求,它能处理100个并发请求吗?否则,请求将排队,并且可能在EM::HttpRequest中超时。

EM::HttpRequest默认连接超时为5秒,默认不活动超时为10秒。

尝试在本地主机上运行ab,看看它每秒可以处理多少个请求。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/8637805

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档