Created
March 30, 2018 13:25
-
-
Save sadovnik/1d597e1da023ff759dcbeb5e53688585 to your computer and use it in GitHub Desktop.
Keep-alive vs new TCP connection each time
This file contains hidden or 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 "excon" | |
require "benchmark" | |
n = 10000 | |
Benchmark.bm(30) do |benchmark| | |
benchmark.report("reuse connection") do | |
client = Excon.new("http://localhost:8080", persistent: true) | |
n.times do | |
client.get(path: "/") | |
end | |
end | |
benchmark.report("open new connection each time") do | |
n.times do | |
Excon.get("http://localhost:8080/") | |
end | |
end | |
end |
This file contains hidden or 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
user system total real | |
reuse connection 9.080000 5.310000 14.390000 ( 34.927759) | |
open new connection each time 13.800000 14.900000 28.700000 ( 71.979245) |
This file contains hidden or 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 'rack' | |
app = Proc.new do |env| | |
current_time = Time.new | |
response_body = "Current time is #{current_time}" | |
[ | |
'200', | |
{ 'Content-Type' => 'text/html' }, | |
[response_body] | |
] | |
end | |
Rack::Handler::WEBrick.run app |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment