Created
July 11, 2019 15:16
-
-
Save shal/40719403723fec135d5a37b9958e5f53 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env ruby | |
require File.join(ENV.fetch('RAILS_ROOT'), 'config', 'environment') | |
Rails.logger.level = Logger::FATAL | |
module Faraday | |
NUMBER_OF_REQUESTS = 10000 | |
class Ethereum | |
def initialize(server, adapter) | |
@adapter = adapter | |
@json_rpc_call_id = 0 | |
@connection = Faraday.new(server) do |builder| | |
builder.adapter adapter | |
end.tap do |connection| | |
unless server.user.blank? | |
connection.basic_auth(server.user, server.password) | |
end | |
end | |
end | |
def run | |
start = Time.now | |
NUMBER_OF_REQUESTS.times do | |
request | |
end | |
finish = Time.now | |
@report = { | |
adapter: @adapter, | |
execution_time: finish - start, | |
ops: NUMBER_OF_REQUESTS / (finish - start) | |
} | |
end | |
def report | |
@report | |
end | |
private | |
def rpc_call_id | |
@json_rpc_call_id += 1 | |
end | |
def request | |
response = @connection.post \ | |
'/', | |
{jsonrpc: '2.0', id: rpc_call_id, method: :eth_blockNumber, params: []}.to_json, | |
{'Accept' => 'application/json', | |
'Content-Type' => 'application/json'} | |
response.assert_success! | |
response = JSON.parse(response.body) | |
response.fetch('result') | |
end | |
end | |
end | |
%i[net_http net_http_persistent typhoeus].each do |adapter| | |
bench = Faraday::Ethereum.new( | |
URI.parse(::Blockchain.find_by(key: 'prt-kovan').server), | |
adapter | |
) | |
bench.run | |
puts bench.report | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment