Class: Ralphttp::Wreckit

Inherits:
Fixit
  • Object
show all
Defined in:
lib/ralphttp/wreckit.rb

Overview

Public; Get benchmarking information for a HTTP server

Instance Attribute Summary collapse

Attributes inherited from Fixit

#bucket, #csv, #csvexport, #detailed, #error, #req, #status, #total_time

Instance Method Summary collapse

Methods inherited from Fixit

#analyze, #display_results, #print_header

Constructor Details

#initialize(options) ⇒ Wreckit

Public: Start the class and assign the domain anem to start

options - Hash containing URL and number of concurrent/total connections

Example:

options = { url: 'http://domain.tld',
            concurrent: 10,
            total: 100
            }
pwong = Ralphttp::Wreckit.new(options)

Returns Nil



24
25
26
27
28
29
30
31
# File 'lib/ralphttp/wreckit.rb', line 24

def initialize(options)
  super(options)
  @domain = options[:url]
  @ua = options[:useragent]
  @hammer = { :concurrent =>  options[:concurrent],
              :total => options[:requests] }
  @bucket = {}
end

Instance Attribute Details

#domainObject

Returns the value of attribute domain.



8
9
10
# File 'lib/ralphttp/wreckit.rb', line 8

def domain
  @domain
end

#hammerObject

Returns the value of attribute hammer.



9
10
11
# File 'lib/ralphttp/wreckit.rb', line 9

def hammer
  @hammer
end

#uaObject

Returns the value of attribute ua.



10
11
12
# File 'lib/ralphttp/wreckit.rb', line 10

def ua
  @ua
end

Instance Method Details

#blastObject

Public: Worker method, builds threads for querying the server

Returns nil



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/ralphttp/wreckit.rb', line 36

def blast
  arr = []
  start = Time.now
  num_loops = calculate_loops

  (1..num_loops.to_i).each do |f|
    Thread.abort_on_exception = false
    (1..@hammer[:concurrent].to_i).each do |s|
      arr[s] = Thread.new do
        start_http
      end
    end

    arr.shift
    arr.each do |t|
      t.join
    end
  end
  @total_time = sprintf('%.2f', (Time.now - start))
  @bucket.keys.sort
end