Last active
December 15, 2015 08:28
-
-
Save wtfuzz/5230558 to your computer and use it in GitHub Desktop.
Test keepalive
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 'em-http-request' | |
count = 10000 | |
error_count = 0 | |
EventMachine.run do | |
conn = EventMachine::HttpRequest.new("http://127.0.0.1:8000", :connect_timeout => 5, :inactivity_timeout => 0) | |
cb = lambda { |req| | |
count -= 1 | |
puts "%d %d" % [count, req.response_header.status] | |
EventMachine.stop if count == 0 | |
} | |
p = lambda { | |
req = conn.get :path => '/ping', :keepalive => true | |
req.errback { | |
error_count += 1 | |
puts "ERROR" | |
puts req.inspect | |
EventMachine.stop | |
} | |
req.callback { | |
cb.call(req) | |
EventMachine.next_tick(p) | |
} | |
req | |
} | |
p.call | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment