Skip to content

Instantly share code, notes, and snippets.

@steveyen
Created September 7, 2011 17:00
Show Gist options
  • Save steveyen/1201110 to your computer and use it in GitHub Desktop.
Save steveyen/1201110 to your computer and use it in GitHub Desktop.
Using TCP_NODELAY with ruby Net HTTP
class MyHTTP < Net::HTTP
def on_connect()
@socket.io.setsockopt(Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1)
end
end
MyHTTP.new(host, port).start do |http|
for x in 0..n
req = Net::HTTP::Get.new("http://#{host}:#{port}/rest/of/url")
req.add_field('Connection', 'keep-alive')
http.request(req) do |res|
res.read_body
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment