-
-
Save philsturgeon/ea4c3966731c8e2e92e70b11fe10d1bc to your computer and use it in GitHub Desktop.
HTTP 2 Client Call Benchmark
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
user system total real | |
faraday (http/1.1): 0.260000 0.030000 0.290000 ( 12.647877) | |
net-http2: 0.080000 0.010000 0.090000 ( 2.466356) |
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
require 'benchmark' | |
require 'json' | |
require 'faraday' | |
require 'net-http2' | |
n = 20 | |
host = 'https://secret.example.com/' | |
params = { | |
foo: 'something' | |
} | |
Benchmark.bm(15) do |x| | |
x.report("faraday (http/1.1):") do | |
client = Faraday.new(url: host, ssl: {verify: false}) do |conn| | |
conn.adapter :net_http | |
end | |
n.times do |i| | |
client.post do |req| | |
req.url '/check' | |
req.headers['Content-Type'] = 'application/json' | |
req.body = JSON.generate(params) | |
end | |
end | |
end | |
x.report("net-http2:") do | |
client = NetHttp2::Client.new(host) | |
n.times do | |
# prepare request | |
request = client.prepare_request(:post, '/check', body: JSON.generate(params), headers: { | |
'content-type' => 'application/json' | |
}) | |
client.call_async(request) | |
end | |
# Wait for all outgoing stream to be closed | |
client.join | |
# close the connection | |
client.close | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment