Class: HanselCore::Hansel

Inherits:
Object
  • Object
show all
Includes:
Formatting, Httperf, JobQueue
Defined in:
lib/hansel/hansel.rb

Overview

Class wrapper over httperf.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from JobQueue

#jobs, #load_job_queue, #pop_job, #push_job

Methods included from Httperf

#build_httperf_cmd, #httperf

Methods included from Formatting

#csv_formatter, #formatted_output, #octave_formatter, #output_filename, #yaml_formatter

Constructor Details

#initialize(options = OpenStruct.new {}) ⇒ Hansel

Returns a new instance of Hansel.



12
13
14
15
16
17
# File 'lib/hansel/hansel.rb', line 12

def initialize options = OpenStruct.new {}
  @options = options
  @results = []
  @current_rate = nil
  @jobs = []
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



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

def options
  @options
end

#resultsObject (readonly)

Returns the value of attribute results.



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

def results
  @results
end

Instance Method Details

#config_pathObject



19
20
21
22
23
# File 'lib/hansel/hansel.rb', line 19

def config_path
  @config_path ||= File.join [ENV['HOME'], '.hansel']
  FileUtils.mkdir_p @config_path unless File.exists? @config_path
  @config_path
end

#outputObject

Output the results based on the requested output format



38
39
40
41
42
43
44
45
# File 'lib/hansel/hansel.rb', line 38

def output
  opts = options
  if opts.format
    FileUtils.mkdir_p opts.output_dir
    formatted_output
  end
  @results.clear
end

#output_dirObject



25
26
27
28
# File 'lib/hansel/hansel.rb', line 25

def output_dir
  @output_dir ||= File.join [ENV['HOME'], 'hansel_output']
  @output_dir
end

#registerObject



30
31
32
33
# File 'lib/hansel/hansel.rb', line 30

def register
  response = Typhoeus::Request.get options.master
  @token = JSON.parse(response.body)['token']
end

#runObject

Run httperf from low_rate to high_rate, stepping by rate_step



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/hansel/hansel.rb', line 54

def run
  while @jobs.length > 0 do
    # do a warm up run first with the highest connection rate
    @current_job = @jobs.pop
    @current_rate = @current_job.high_rate.to_i
    httperf true

    (@current_job.low_rate.to_i..@current_job.high_rate.to_i).
        step(@current_job.rate_step.to_i) do |rate|
      @current_rate = rate
      httperf
    end
    output
  end
end

#run_serverObject



70
71
72
73
# File 'lib/hansel/hansel.rb', line 70

def run_server
  HanselSlaveServer.hansel = self
  HanselSlaveServer.run! :host => 'localhost', :port => 4000
end

#status(text) ⇒ Object



47
48
49
# File 'lib/hansel/hansel.rb', line 47

def status text
  puts text if options.verbose
end