Class: HttpProfiler::Runner

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

Instance Method Summary collapse

Constructor Details

#initialize(configFileName, config) ⇒ Runner

Returns a new instance of Runner.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/httpProfiler.rb', line 10

def initialize(configFileName, config)
  @configFileName = configFileName;
  @options = config;
  @cookies = Hash.new();
  if @options.has_key?('cookies') then
    @cookies = @options['cookies'];
    @options.delete('cookies');
  end
  @requestGroups = Hash.new();
  if @options.has_key?('requestGroups') then
    @requestGroups = @options['requestGroups'];
    @options.delete('requestGroups');
  end
end

Instance Method Details

#runObject



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/httpProfiler.rb', line 64

def run
  if @options['verbose'] then
    require 'pp';
    puts "\n\nConfiguration taken from: [#{@configFileName}]";
    puts "options:";
    pp @options;
    puts "requestGroups:";
    pp @requestGroups;
    puts "\n\n";
  end
  results = Hash.new();
  @requestGroups.each_pair do | requestGroupName, requestGroup |
    results[requestGroupName] = runRequestGroup(requestGroupName, 
                                                requestGroup.merge!(@options));
  end
  results;
end

#runRequestGroup(requestGroupName, requestGroup) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
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
# File 'lib/httpProfiler.rb', line 25

def runRequestGroup(requestGroupName, requestGroup)
  requestList = Array.new();
  @options['replications'].times do 
    requestGroup['urls'].each do | url |
      requestList.push(url);
    end    
  end

  randGen = nil;
  if requestGroup['randomize'] == 0 then
  elsif requestGroup['randomize'] < 0 then
    randGen = Random.new();
  else
    randGen = Random.new(requestGroup['randomize']);
  end
  requestList.shuffle!(random: randGen) unless randGen.nil?;

  connectTimes = Array.new();

  puts requestGroupName if @options['verbose'];
  requestList.each do | url |
    puts "\t#{url}" if @options['verbose'];
    c = Curl::Easy.new(url);
    c.follow_location = true;
    c.perform;
    connectTimes.push(c.connect_time);
    if 0 < @options['delay'] then
      puts "\t\tsleeping(#{@options['delay']})" if @options['verbose'];
      sleep(@options['delay']);
    end
  end

  [ connectTimes.min, 
    connectTimes.average,
    connectTimes.median,
    connectTimes.max,
    connectTimes.standard_deviation ]
end