Class: Kronk::Player::Benchmark

Inherits:
Kronk::Player show all
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

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

#bodyObject



274
275
276
277
278
279
280
281
282
283
# File 'lib/kronk/player/benchmark.rb', line 274

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_screenObject



241
242
243
# File 'lib/kronk/player/benchmark.rb', line 241

def clear_screen
  $stdout.print "\e[2K\e[1A" * @line_count
end

#completeObject



256
257
258
259
260
261
# File 'lib/kronk/player/benchmark.rb', line 256

def complete
  puts "Finished!" unless @interactive

  render
  true
end

#error(err, kronk) ⇒ Object



246
247
248
249
250
251
252
253
# File 'lib/kronk/player/benchmark.rb', line 246

def error err, kronk
  @mutex.synchronize do
    @res_count += 1
    @results.each do |res|
      res.err_count += 1
    end
  end
end

#headObject



286
287
288
289
290
291
292
293
294
295
# File 'lib/kronk/player/benchmark.rb', line 286

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

#renderObject



264
265
266
267
268
269
270
271
# File 'lib/kronk/player/benchmark.rb', line 264

def render
  clear_screen if @interactive
  out = "#{head}#{body}\n"
  @line_count = out.to_s.split("\n").length
  @last_print = Time.now
  $stdout.print out
  $stdout.flush
end

#result(kronk) ⇒ Object



223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
# File 'lib/kronk/player/benchmark.rb', line 223

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

#startObject



210
211
212
213
214
215
216
217
218
219
220
# File 'lib/kronk/player/benchmark.rb', line 210

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