43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
# File 'lib/benchmark/http/command/hammer.rb', line 43
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, 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
|