-
-
Save fagci/558f2a952cdf894f6c2d7ed9d439cfe7 to your computer and use it in GitHub Desktop.
Using TCP_NODELAY with ruby Net HTTP (set socket options)
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
class MyHTTP < Net::HTTP | |
def on_connect() | |
@socket.io.setsockopt(Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1) | |
end | |
end | |
n = 5 | |
host = 'example.com' | |
port = 80 | |
MyHTTP.new(host, port).start do |http| | |
n.times do | |
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