class CelluloidBenchmark::BenchmarkRun
A test run of a scenario. Holds response times, codes, and requests. Reports results as an array of Benchmarks
Attributes
ended_at[RW]
logger[RW]
started_at[RW]
thresholds[R]
visitors[RW]
Public Class Methods
new()
click to toggle source
# File lib/celluloid_benchmark/benchmark_run.rb, line 17 def initialize if !Dir.exist?("log") FileUtils.mkdir "log" end # Could replace with Celluloid.logger @logger = ::Logger.new("log/benchmark.log") @thresholds = Hash.new end
Public Instance Methods
benchmarks()
click to toggle source
# File lib/celluloid_benchmark/benchmark_run.rb, line 71 def benchmarks response_times.map do |label, response_times| CelluloidBenchmark::Benchmark.new label, thresholds[label], response_times, response_codes[label] end end
elapsed_time()
click to toggle source
# File lib/celluloid_benchmark/benchmark_run.rb, line 85 def elapsed_time if started_at && ended_at (ended_at - started_at).to_f else 0 end end
inspect()
click to toggle source
# File lib/celluloid_benchmark/benchmark_run.rb, line 97 def inspect response_times.map do |label, response_times| "#{label} #{response_times.reduce(:+) / response_times.size} #{response_times.min} #{response_times.max} #{response_times.size}" end end
log(http_status_code, start_time, end_time, server_response_time, label, threshold)
click to toggle source
# File lib/celluloid_benchmark/benchmark_run.rb, line 27 def log(http_status_code, start_time, end_time, server_response_time, label, threshold) response_codes[label] << http_status_code.to_i network_and_server_time = network_and_server_time(start_time, end_time) if server_response_time response_times[label] << server_response_time network_times[label] << network_and_server_time - server_response_time else response_times[label] << network_and_server_time network_times[label] << network_and_server_time end if threshold thresholds[label] = threshold end logger.info "#{http_status_code} #{network_and_server_time} #{label}" end
mark_end()
click to toggle source
# File lib/celluloid_benchmark/benchmark_run.rb, line 81 def mark_end @ended_at = Time.now end
mark_start()
click to toggle source
# File lib/celluloid_benchmark/benchmark_run.rb, line 77 def mark_start @started_at = Time.now end
network_time()
click to toggle source
# File lib/celluloid_benchmark/benchmark_run.rb, line 63 def network_time requests = network_times.values.flatten if requests.size > 0 requests.reduce(:+) / requests.size end end
network_times()
click to toggle source
# File lib/celluloid_benchmark/benchmark_run.rb, line 59 def network_times @network_times ||= Hash.new { |hash, value| hash[value] = [] } end
ok?()
click to toggle source
# File lib/celluloid_benchmark/benchmark_run.rb, line 93 def ok? benchmarks.all?(&:ok?) end
requests()
click to toggle source
# File lib/celluloid_benchmark/benchmark_run.rb, line 55 def requests response_times.values.compact.map(&:size).reduce(0, &:+) end
response_codes()
click to toggle source
# File lib/celluloid_benchmark/benchmark_run.rb, line 51 def response_codes @response_codes ||= Hash.new { |hash, value| hash[value] = [] } end
response_times()
click to toggle source
# File lib/celluloid_benchmark/benchmark_run.rb, line 47 def response_times @response_times ||= Hash.new { |hash, value| hash[value] = [] } end
Private Instance Methods
network_and_server_time(start_time, end_time)
click to toggle source
# File lib/celluloid_benchmark/benchmark_run.rb, line 106 def network_and_server_time(start_time, end_time) if start_time && end_time end_time - start_time else 0 end end