Class: Benchmark::HTTP::Command::Latency

Inherits:
Samovar::Command
  • Object
show all
Defined in:
lib/benchmark/http/command/latency.rb

Instance Method Summary collapse

Instance Method Details

#callObject



73
74
75
76
77
# File 'lib/benchmark/http/command/latency.rb', line 73

def call
	@hosts.each do |host|
		run(host)
	end
end

#confidence_factorObject



28
29
30
# File 'lib/benchmark/http/command/latency.rb', line 28

def confidence_factor
	1.0 - @options[:confidence]
end

#measure_performance(concurrency, endpoint, request_path) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/benchmark/http/command/latency.rb', line 32

def measure_performance(concurrency, endpoint, request_path)
	Console.logger.info(self) {"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)
	
	Console.logger.info(self, statistics: statistics) do |buffer|
		buffer.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."
		buffer.puts "\t          Variance: #{Seconds[statistics.variance]}"
		buffer.puts "\tStandard Deviation: #{Seconds[statistics.standard_deviation]}"
		buffer.puts "\t    Standard Error: #{Seconds[statistics.standard_error]}"
	end
	
	return statistics
end

#run(url) ⇒ Object



60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/benchmark/http/command/latency.rb', line 60

def run(url)
	endpoint = Async::HTTP::Endpoint.parse(url)
	request_path = endpoint.url.request_uri
	
	Console.logger.info(self) {"I am going to benchmark #{url}..."}
	
	Sync do |task|
		statistics = []
		
		base = measure_performance(@options[:concurrency], endpoint, request_path)
	end
end