Class: CelluloidBenchmark::BenchmarkRun
- Inherits:
-
Object
- Object
- CelluloidBenchmark::BenchmarkRun
- Includes:
- Celluloid
- Defined in:
- lib/celluloid_benchmark/benchmark_run.rb
Overview
A test run of a scenario. Holds response times, codes, and requests. Reports results as an array of Benchmarks
Instance Attribute Summary collapse
-
#ended_at ⇒ Object
Returns the value of attribute ended_at.
-
#logger ⇒ Object
Returns the value of attribute logger.
-
#started_at ⇒ Object
Returns the value of attribute started_at.
-
#thresholds ⇒ Object
readonly
Returns the value of attribute thresholds.
-
#visitors ⇒ Object
Returns the value of attribute visitors.
Instance Method Summary collapse
- #benchmarks ⇒ Object
- #elapsed_time ⇒ Object
-
#initialize ⇒ BenchmarkRun
constructor
A new instance of BenchmarkRun.
- #inspect ⇒ Object
- #log(http_status_code, start_time, end_time, server_response_time, label, threshold) ⇒ Object
- #mark_end ⇒ Object
- #mark_start ⇒ Object
- #network_time ⇒ Object
- #network_times ⇒ Object
- #ok? ⇒ Boolean
- #requests ⇒ Object
- #response_codes ⇒ Object
- #response_times ⇒ Object
Constructor Details
#initialize ⇒ BenchmarkRun
17 18 19 20 21 22 23 24 25 |
# File 'lib/celluloid_benchmark/benchmark_run.rb', line 17 def initialize if !Dir.exists?("log") FileUtils.mkdir "log" end # Could replace with Celluloid.logger @logger = ::Logger.new("log/benchmark.log") @thresholds = Hash.new end |
Instance Attribute Details
#ended_at ⇒ Object
Returns the value of attribute ended_at.
11 12 13 |
# File 'lib/celluloid_benchmark/benchmark_run.rb', line 11 def ended_at @ended_at end |
#logger ⇒ Object
Returns the value of attribute logger.
12 13 14 |
# File 'lib/celluloid_benchmark/benchmark_run.rb', line 12 def logger @logger end |
#started_at ⇒ Object
Returns the value of attribute started_at.
13 14 15 |
# File 'lib/celluloid_benchmark/benchmark_run.rb', line 13 def started_at @started_at end |
#thresholds ⇒ Object (readonly)
Returns the value of attribute thresholds.
15 16 17 |
# File 'lib/celluloid_benchmark/benchmark_run.rb', line 15 def thresholds @thresholds end |
#visitors ⇒ Object
Returns the value of attribute visitors.
14 15 16 |
# File 'lib/celluloid_benchmark/benchmark_run.rb', line 14 def visitors @visitors end |
Instance Method Details
#benchmarks ⇒ Object
71 72 73 74 75 |
# 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 ⇒ Object
85 86 87 88 89 90 91 |
# 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 ⇒ Object
97 98 99 100 101 |
# 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) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# 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 ⇒ Object
81 82 83 |
# File 'lib/celluloid_benchmark/benchmark_run.rb', line 81 def mark_end @ended_at = Time.now end |
#mark_start ⇒ Object
77 78 79 |
# File 'lib/celluloid_benchmark/benchmark_run.rb', line 77 def mark_start @started_at = Time.now end |
#network_time ⇒ Object
63 64 65 66 67 68 69 |
# 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 ⇒ Object
59 60 61 |
# File 'lib/celluloid_benchmark/benchmark_run.rb', line 59 def network_times @network_times ||= Hash.new { |hash, value| hash[value] = [] } end |
#ok? ⇒ Boolean
93 94 95 |
# File 'lib/celluloid_benchmark/benchmark_run.rb', line 93 def ok? benchmarks.all?(&:ok?) end |
#requests ⇒ Object
55 56 57 |
# File 'lib/celluloid_benchmark/benchmark_run.rb', line 55 def requests response_times.values.compact.map(&:size).reduce(0, &:+) end |
#response_codes ⇒ Object
51 52 53 |
# File 'lib/celluloid_benchmark/benchmark_run.rb', line 51 def response_codes @response_codes ||= Hash.new { |hash, value| hash[value] = [] } end |
#response_times ⇒ Object
47 48 49 |
# File 'lib/celluloid_benchmark/benchmark_run.rb', line 47 def response_times @response_times ||= Hash.new { |hash, value| hash[value] = [] } end |