class Benchmark::HTTP::Command::Latency

Public Instance Methods

call() click to toggle source
# File lib/benchmark/http/command/latency.rb, line 86
def call
        @hosts.each do |host|
                run(host).wait
        end
end
confidence_factor() click to toggle source
# File lib/benchmark/http/command/latency.rb, line 43
def confidence_factor
        1.0 - @options[:confidence]
end
measure_performance(concurrency, endpoint, request_path) click to toggle source
# File lib/benchmark/http/command/latency.rb, line 47
def measure_performance(concurrency, endpoint, request_path)
        puts "I am running #{concurrency} asynchronous tasks that will each make sequential requests..."
        
        statistics = Statistics.new(concurrency)
        task = Async::Task.current
        
        concurrency.times.map do
                task.async do
                        client = Async::HTTP::Client.new(endpoint, protocol: endpoint.protocol)
                        
                        statistics.sample(confidence_factor) do
                                response = client.get(request_path).tap(&:finish)
                        end
                        
                        client.close
                end
        end.each(&:wait)
        
        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]}"
        
        return statistics
end
run(url) click to toggle source
# File lib/benchmark/http/command/latency.rb, line 73
def run(url)
        endpoint = Async::HTTP::Endpoint.parse(url)
        request_path = endpoint.url.request_uri
        
        puts "I am going to benchmark #{url}..."
        
        Async::Reactor.run do |task|
                statistics = []
                
                base = measure_performance(@options[:concurrency], endpoint, request_path)
        end
end