Created
January 28, 2010 08:21
-
-
Save saivenkat/288548 to your computer and use it in GitHub Desktop.
Neverblock Net/Http problem
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "rubygems" | |
require "neverblock" | |
require "eventmachine" | |
require "net/http" | |
require "uri" | |
def load_timer(url, number_of_requests=50) | |
start = Time.now | |
EM.run do | |
@pool = NB::Pool::FiberPool.new(number_of_requests) | |
i = 0 | |
number_of_requests.times do |i| | |
@pool.spawn do | |
request_url = URI.parse(url) | |
p "Spawning ##{i} request" | |
res = Net::HTTP.start(request_url.host, request_url.port) {|client| client.get('/')} | |
i += 1 | |
EM.stop if i == number_of_requests - 1 | |
end | |
end | |
end | |
finish = Time.now | |
puts "Total time - #{finish - start} seconds" | |
end | |
if $0 == __FILE__ | |
load_timer "http://localhost:9999", 5 | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment