lib/benchmark/http/command/latency.rb in benchmark-http-0.15.1 vs lib/benchmark/http/command/latency.rb in benchmark-http-0.16.0
- old
+ new
@@ -1,25 +1,10 @@
-# Copyright, 2018, by Samuel G. D. Williams. <http://www.codeotaku.com>
-#
-# Permission is hereby granted, free of charge, to any person obtaining a copy
-# of this software and associated documentation files (the "Software"), to deal
-# in the Software without restriction, including without limitation the rights
-# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-# copies of the Software, and to permit persons to whom the Software is
-# furnished to do so, subject to the following conditions:
-#
-# The above copyright notice and this permission notice shall be included in
-# all copies or substantial portions of the Software.
-#
-# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-# THE SOFTWARE.
+# frozen_string_literal: true
+# Released under the MIT License.
+# Copyright, 2019-2022, by Samuel Williams.
+
require_relative '../seconds'
require_relative '../statistics'
require 'async'
require 'async/http/client'
@@ -43,11 +28,11 @@
def confidence_factor
1.0 - @options[:confidence]
end
def measure_performance(concurrency, endpoint, request_path)
- puts "I am running #{concurrency} asynchronous tasks that will each make sequential requests..."
+ 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
@@ -60,33 +45,35 @@
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]}"
+ 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
def run(url)
endpoint = Async::HTTP::Endpoint.parse(url)
request_path = endpoint.url.request_uri
- puts "I am going to benchmark #{url}..."
+ Console.logger.info(self) {"I am going to benchmark #{url}..."}
- Async::Reactor.run do |task|
+ Sync do |task|
statistics = []
base = measure_performance(@options[:concurrency], endpoint, request_path)
end
end
def call
@hosts.each do |host|
- run(host).wait
+ run(host)
end
end
end
end
end