class Benchmark::HTTP::Command::Hammer
Public Instance Methods
call()
click to toggle source
# File lib/benchmark/http/command/hammer.rb, line 98 def call while true @urls.each do |url| run(url).wait end if @interval sleep(@interval) else break end end end
measure_performance(concurrency, count, endpoint, request_path)
click to toggle source
# File lib/benchmark/http/command/hammer.rb, line 45 def measure_performance(concurrency, count, endpoint, request_path) puts "I am running #{concurrency} asynchronous tasks that will each make #{count} sequential requests..." statistics = Statistics.new(concurrency) task = Async::Task.current running = true progress_task = task.async do |child| while true child.sleep(1) statistics.print end end concurrency.times.map do task.async do client = Async::HTTP::Client.new(endpoint, protocol: endpoint.protocol) count.times do |i| statistics.measure do response = client.get(request_path).tap(&:finish) end end client.close end end.each(&:wait) progress_task&.stop puts "I made #{statistics.count} requests in #{Seconds[statistics.sequential_duration]}. The per-request latency was #{Seconds[statistics.latency]}. That's #{statistics.per_second} asynchronous requests/second." puts "\t Variance: #{Seconds[statistics.variance]}" puts "\tStandard Deviation: #{Seconds[statistics.standard_deviation]}" puts "\t Standard Error: #{Seconds[statistics.standard_error]}" statistics.print return statistics end
run(url)
click to toggle source
# File lib/benchmark/http/command/hammer.rb, line 85 def run(url) endpoint = Async::HTTP::Endpoint.parse(url) request_path = endpoint.url.request_uri puts "I am going to benchmark #{url}..." Async do |task| statistics = [] base = measure_performance(@options[:concurrency], @options[:count], endpoint, request_path) end end