Class: Kronk::Player::Benchmark
- Inherits:
-
Kronk::Player
- Object
- QueueRunner
- Kronk::Player
- Kronk::Player::Benchmark
- Defined in:
- lib/kronk/player/benchmark.rb
Overview
Returns benchmarks for a set of Player results.
-
Total time taken
-
Complete requests
-
Failed requests
-
Total bytes transferred
-
Requests per second
-
Time per request
-
Transfer rate
-
Connection times (min mean median max)
-
Percentage of requests within a certain time
-
Slowest endpoints
Defined Under Namespace
Classes: ResultSet
Instance Attribute Summary
Attributes inherited from Kronk::Player
#concurrency, #input, #mutex, #qps
Attributes inherited from QueueRunner
#count, #number, #queue, #reader_thread, #threads
Instance Method Summary collapse
- #body ⇒ Object
- #clear_screen ⇒ Object
- #complete ⇒ Object
- #error(err, kronk) ⇒ Object
- #head ⇒ Object
- #render ⇒ Object
- #result(kronk) ⇒ Object
- #start ⇒ Object
Methods inherited from Kronk::Player
#compare, #from_io, #initialize, new_type, #request, #run, #trigger_result
Methods inherited from QueueRunner
#concurrently, #finish, #finished?, #initialize, #kill, #on, #periodically, #start_input!, #stop_input!, #trigger, #until_finished, #yield_queue_item
Constructor Details
This class inherits a constructor from Kronk::Player
Instance Method Details
#body ⇒ Object
288 289 290 291 292 293 294 295 296 297 |
# File 'lib/kronk/player/benchmark.rb', line 288 def body @results.each{|res| res.total_time = Time.now - @start_time } if @results.length > 1 Diff.new(@results[0].to_s, @results[1].to_s, :context => false). formatted else @results.first.to_s end end |
#clear_screen ⇒ Object
254 255 256 |
# File 'lib/kronk/player/benchmark.rb', line 254 def clear_screen $stdout.print "\e[2K\e[1A" * @line_count end |
#complete ⇒ Object
269 270 271 272 273 274 |
# File 'lib/kronk/player/benchmark.rb', line 269 def complete puts "Finished!" unless @interactive render true end |
#error(err, kronk) ⇒ Object
259 260 261 262 263 264 265 266 |
# File 'lib/kronk/player/benchmark.rb', line 259 def error err, kronk @mutex.synchronize do @res_count += 1 @results.each do |res| res.err_count += 1 end end end |
#head ⇒ Object
300 301 302 303 304 305 306 307 308 309 |
# File 'lib/kronk/player/benchmark.rb', line 300 def head <<-STR Benchmark Time: #{(Time.now - @start_time).to_f} sec Number of Requests: #{@count} Concurrency: #{@qps ? "#{@qps} qps" : @concurrency} #{"Current Connections: #{Kronk::HTTP.conn_count}\n" if @interactive}\ Total Connections: #{Kronk::HTTP.total_conn} STR end |
#render ⇒ Object
277 278 279 280 281 282 283 284 285 |
# File 'lib/kronk/player/benchmark.rb', line 277 def render out = "#{head}#{body}\n" new_count = out.to_s.split("\n").length @last_print = Time.now clear_screen if @interactive @line_count = new_count $stdout.print out $stdout.flush end |
#result(kronk) ⇒ Object
236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 |
# File 'lib/kronk/player/benchmark.rb', line 236 def result kronk @mutex.synchronize do kronk.responses.each_with_index do |resp, i| @results[i] ||= ResultSet.new @results[i].add_result resp end @res_count += 1 if @interactive render if Time.now - @last_print > 0.5 else puts "#{@res_count} requests" if @res_count % @div == 0 end end end |
#start ⇒ Object
223 224 225 226 227 228 229 230 231 232 233 |
# File 'lib/kronk/player/benchmark.rb', line 223 def start @interactive = $stdout.isatty @res_count = 0 @results = [ResultSet.new] @div = @number / 10 if @number @div = 100 if !@div || @div < 10 @last_print = Time.now @line_count = 0 puts "Benchmarking..." unless @interactive end |