Skip to content

Instantly share code, notes, and snippets.

@wtfuzz
Last active December 15, 2015 08:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wtfuzz/5230558 to your computer and use it in GitHub Desktop.
Save wtfuzz/5230558 to your computer and use it in GitHub Desktop.
Test keepalive
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