Class: MPPerf

Inherits:
Object
  • Object
show all
Defined in:
lib/mp_perf.rb

Overview

Takes command line options and attempts to make a benchmark.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ MPPerf

Returns a new instance of MPPerf.



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

def initialize(opts = {})
  parse_options
  parse_config
  run_suite
  display_hints
end

Class Method Details

.options_bannerObject



121
122
123
124
125
126
127
128
129
# File 'lib/mp_perf.rb', line 121

def self.options_banner
  <<BANNER
Runs a stresstest defined in a config file and write the results to a csv file.

Usage:
    stresser -c my_config_file -o results.csv
where options are:
BANNER
end

Instance Method Details

#display_hintsObject



114
115
116
117
118
119
# File 'lib/mp_perf.rb', line 114

def display_hints
  puts "~"*80
  puts "Great, now create a graph with"
  puts "  stresser-grapher -o #{File.expand_path(File.dirname(@conf[:output_file]))} #{@conf[:output_file]}"
  puts ""
end

#parse_configObject

Raises:

  • (Errno::EACCES)


38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/mp_perf.rb', line 38

def parse_config
  config_file = @conf[:config_file]
  raise Errno::EACCES, "#{config_file} is not readable" unless File.readable?(config_file)

  conf = {}
  open(config_file).each { |line|
    line.chomp
    unless (/^\#/.match(line))
      if(/\s*=\s*/.match(line))
        param, value = line.split(/\s*=\s*/, 2)
        var_name = "#{param}".chomp.strip
        value = value.chomp.strip
        new_value = ''
        if (value)
          if value =~ /^['"](.*)['"]$/
            new_value = $1
          else
            new_value = value
          end
        else
          new_value = ''
        end
        conf[var_name] = new_value =~ /^\d+$/ ? new_value.to_i : new_value
      end
    end
  }

  @conf.merge! conf
end

#parse_optionsObject

Parse command line options



22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/mp_perf.rb', line 22

def parse_options
  @conf = Trollop::options do
    banner = MPPerf.options_banner
    opt :output_file, "The name of the csv file to write the results to. Warning: overwrites that file!",
                      :type => String
    opt :config_file, "The name of the .conf file defining your testsuite. See http://github.com/moviepilot/stresser",
                      :type => String
  end

  Trollop::die :output_file, "must be a writeable file" unless @conf[:config_file]
  Trollop::die :config_file, "must be a readable file"  unless @conf[:config_file]
end

#run_suiteObject



88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/mp_perf.rb', line 88

def run_suite
  results = {}
  report = nil
  (@conf['low_rate']..@conf['high_rate']).step(@conf['rate_step']) do |rate|

    # Run httperf
    results[rate] = single_benchmark(@conf.merge({'httperf_rate' => rate}))

    # Show that we're alive 
    puts "#{results[rate].delete('output')}\n"
    puts "~"*80

    # Init table unless it's there already
    report ||= Table(:column_names => ['rate'] + results[rate].keys.sort)

    # Save results of this run
    report << results[rate].merge({'rate' => rate})

    # Try to keep old pending requests from influencing the next round
    sleep(@conf['sleep_time'] || 0)
  end

  # Write csv
  File.new(@conf[:output_file], "w").puts report.to_csv unless report.nil?
end

#single_benchmark(conf) ⇒ Object

Runs a single benchmark (this method will be called many times

with different concurrency levels)


72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/mp_perf.rb', line 72

def single_benchmark(conf)
  cloned_conf = conf.clone
 
  # Shuffle the logfile around?
  if conf['httperf_wlog'] and conf['shuffle']=='true'
    file = conf['httperf_wlog'].split(',').last
    `cat #{file} | tr "\\0" "\\n" | sort --random-sort | tr "\\n" "\\0" > #{file}.shuffled`
    cloned_conf['httperf_wlog'] = conf['httperf_wlog']+'.shuffled'
  end
 
  # Run httperf 
  res = Httperf.run(cloned_conf)

  return res
end