Module: BigBench

Defined in:
lib/bigbench/bot.rb,
lib/bigbench/store.rb,
lib/bigbench/output.rb,
lib/bigbench/runner.rb,
lib/bigbench/tracker.rb,
lib/bigbench/version.rb,
lib/bigbench/executor.rb,
lib/bigbench/fragment.rb,
lib/bigbench/benchmark.rb,
lib/bigbench/configuration.rb,
lib/bigbench/post_processor.rb,
lib/bigbench/benchmark/looper.rb,
lib/bigbench/post_processor/graphs.rb,
lib/bigbench/post_processor/statistics.rb,
lib/bigbench/post_processor/environment.rb

Defined Under Namespace

Modules: Benchmark, Bot, Configuration, Executor, Fragment, Output, PostProcessor, Runner, Store, Tracker

Constant Summary collapse

VERSION =
"0.0.6"

Class Method Summary collapse

Class Method Details

.benchmark(options) ⇒ Object

Add a benchmark like this:

benchmark "default website pages" => "http://localhost:3000" do
   get "/"
   get "/blog"
   get "/imprint"
   get "/admin", :basic_auth => ['admin', 'secret']
end

benchmark "login and logout" => "http://localhost:3000" do
   post "/login",  :params => { :name => "[email protected]", :password => "secret" }
   post "/logout", :params => { :name => "[email protected]" }
end


101
102
103
# File 'lib/bigbench/benchmark.rb', line 101

def self.benchmark(options)
  Benchmark.add(options, &Proc.new) if block_given?
end

.benchmarksObject

List all available benchmarks



106
107
108
# File 'lib/bigbench/benchmark.rb', line 106

def self.benchmarks
  Benchmark.all
end

.configObject

Set and retreive the config values like this:

BigBench.config.duration # => 10.seconds
BigBench.config.duration = 20.minutes


73
74
75
# File 'lib/bigbench/configuration.rb', line 73

def self.config
  Configuration.config
end

.configure {|Configuration.config| ... } ⇒ Object

Configure the benchmark by supplying a hash of options like this:

BigBench.configure do |config|
  config.duration    = 10.seconds,
  config.output      = "test.ljson",
  config.users       = 20,
  config.basic_auth  = ['username', 'secret']
end

Those values can then be set and retreived with BigBench.config.duration, …

Yields:



62
63
64
65
66
# File 'lib/bigbench/configuration.rb', line 62

def self.configure
  raise "No block to configure given" unless block_given?
  yield(Configuration.config)
  Configuration.config
end

.durationObject

Returns the duration of all benchmarks - ergo the duration of the longest one



111
112
113
# File 'lib/bigbench/benchmark.rb', line 111

def self.duration
  Benchmark.max_duration
end

.load_test!(test) ⇒ Object

Loads a test from a string file that is either parsed from a local file or retreived from the key-value store.

benchmark_string = 'benchmark "index page" => "http://localhost:3000" do
    get "/"
end'

BigBench.load_test!(benchmark_string)


46
47
48
49
50
# File 'lib/bigbench/runner.rb', line 46

def self.load_test!(test)
  BigBench::Benchmark.reset!
  eval(test)
  BigBench::Output.loaded_tests
end

.post_process(processor = nil, options = {}) ⇒ Object

To setup a post processor simply do this:

post_process do
  # Some code that is executed after the tests, like a database update, twitter post, email etc.
end

Or use one of the predefined post processor or write one yourself:

post_process :statistics
post_process BigBench::PostProcessor::Statistics
post_process "statistics"

All the upper lines include the same post processor. Symbols and strings are camelized and constantized as the module name.

Available Methods in Processors

Every post processor block or module supports the following methods and has full ActionView::Helper support.

each_tracking

A method that iterates through every collected tracking. It automatically returns a hash with a single tracking of the following form:

{
  :elapsed    => 2.502132,
  :start      => 1333986292.1755981,
  :stop       => 1333986293.618884,
  :duration   => 1443,
  :benchmark  => "index page",
  :url        => "http://www.google.de/",
  :path       => "/",
  :method     => "get",
  :status     => 200
}

It can be used like this:

post_process do

  total_trackings, total_errors = 0, 0                
  each_tracking do |tracking|
    total_trackings += 1
    total_errors    += 1 unless tracking[:status] == 200
  end

  Twitter.post "Just run BigBench with #{total_trackings} trackings and #{total_errors} errors."

end


188
189
190
191
# File 'lib/bigbench/post_processor.rb', line 188

def self.post_process processor = nil, options = {}
  raise PostProcessor::InvalidProcessor.new if processor.nil? && !block_given?
  block_given? ? PostProcessor.add(processor, options, &Proc.new) : PostProcessor.add(processor, options)
end

.post_processorsObject

List all initialized post processors



194
195
196
# File 'lib/bigbench/post_processor.rb', line 194

def self.post_processors
  PostProcessor.all
end

.run!Object

Runs all initialized benchmarks



32
33
34
35
36
# File 'lib/bigbench/runner.rb', line 32

def self.run!
  BigBench::Output.running_benchmarks
  Runner.run!
  BigBench::Output.finished_running_benchmarks
end

.run_post_processors!Object

Runs all initialized post processors after the trackings have been written



199
200
201
# File 'lib/bigbench/post_processor.rb', line 199

def self.run_post_processors!
  PostProcessor.run!
end

.write_local_trackings_to_file!Object

Writes the locals trackings from the benchmark to a file



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/bigbench/tracker.rb', line 45

def self.write_local_trackings_to_file!
  trackings, counter = 0, 0
  BigBench.benchmarks.each{ |benchmark| trackings += benchmark.tracker.trackings.size }
  BigBench::Output.writing_trackings(trackings)
  
  File.open(BigBench.config.output, "w+") do |file|
    BigBench.benchmarks.each do |benchmark|
      benchmark.tracker.trackings.each do |tracking|
        BigBench::Output.wrote_trackings(counter) if counter % 100 == 0
        file.write tracking.to_json + "\n"
        counter += 1
      end
    end
  end
  
  BigBench::Output.finished_writing_trackings(counter)
end

.write_store_trackings_to_file!Object

Gathers the trackings from the redis and writes them to a local file



64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/bigbench/tracker.rb', line 64

def self.write_store_trackings_to_file!
  trackings, counter = BigBench::Store.count_trackings, 0
  BigBench::Output.writing_trackings(trackings)
  
  File.open(BigBench.config.output, "w+") do |file|
    while tracking = BigBench::Store.pop_tracking do
      BigBench::Output.wrote_trackings(counter) if counter % 100 == 0
      file.write tracking + "\n"
      counter += 1
    end
  end
  
  BigBench::Output.finished_writing_trackings(counter)
end

.write_trackings_to_store!Object

Writes the trackings of a bot to the redis after he finishes the run



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/bigbench/tracker.rb', line 28

def self.write_trackings_to_store!
  trackings, counter = 0, 0
  BigBench.benchmarks.each{ |benchmark| trackings += benchmark.tracker.trackings.size }
  BigBench::Output.writing_trackings(trackings)
  
  BigBench.benchmarks.each do |benchmark|
    benchmark.tracker.trackings.each do |tracking|
      BigBench::Output.wrote_trackings(counter) if counter % 100 == 0
      BigBench::Store.add_tracking(tracking.to_json)
      counter += 1
    end
  end
  
  BigBench::Output.finished_writing_trackings(counter)
end