Skip to content

Instantly share code, notes, and snippets.

@minhajuddin
Last active October 28, 2020 19:53
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 minhajuddin/3e7bccc0be3916f941593622c7b90026 to your computer and use it in GitHub Desktop.
Save minhajuddin/3e7bccc0be3916f941593622c7b90026 to your computer and use it in GitHub Desktop.
HTTP Connection pooling benchmark

Performance comparison

For a 100 requests.

$ ruby ~/s/bench_connection_pool.rb
       user     system      total        real
without  1.329350   0.059367   1.388717 (  7.018174)
with     0.222370   0.000000   0.222370 (  1.659621)

Requests with connection pooling take 76% less time than requests without connection pooling, they also consume less resources.

require 'excon'
require 'benchmark'
n = 100
url = 'https://putty.minhajuddin.com/'
c1 = -> { Excon.new(url, path: '/', persistent: true) }
Benchmark.bm do |b|
b.report('without') { n.times { Excon.get url } }
b.report('with ') { c1 = c1.call; n.times { c1.get } }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment