module BigBench

Constants

VERSION

Public Class Methods

benchmark(options) click to toggle source

Add a benchmark like this:

benchmark "default website pages" => "http://localhost:3000" do
   get "/"
   get "/blog"
   get "/imprint"
end

benchmark "login and logout" => "http://localhost:3000" do
   post "/login", { :name => "test@user.com", :password => "secret" }
   post "http://localhost:3000/logout"
end
# File lib/bigbench/benchmark.rb, line 111
def self.benchmark(options)
  return unless block_given?
  Benchmark.add(options, &Proc.new)
end
benchmarks() click to toggle source

List all available benchmarks

# File lib/bigbench/benchmark.rb, line 117
def self.benchmarks
  Benchmark.all
end
check_config!() click to toggle source

Checks if all necessary config options are set and raises an InvalidOptions exception if not

# File lib/bigbench/configuration.rb, line 104
def self.check_config!
  raise Configuration::InvalidOptions.new unless config.valid?
  true
end
config() click to toggle source

Set and retreive the config values like this:

BigBench.config.duration # => 10.seconds
BigBench.config.duration = 20.minutes
# File lib/bigbench/configuration.rb, line 99
def self.config
  Configuration.config
end
configure=(config) click to toggle source

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

BigBench.configure = {
  :duration => 10.seconds,
  :output   => "test.ljson",
  :threads  => 20
}

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

# File lib/bigbench/configuration.rb, line 90
def self.configure=(config)
  Configuration.configure=(config)
end
duration() click to toggle source

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

# File lib/bigbench/benchmark.rb, line 122
def self.duration
  Benchmark.max_duration
end
load_test!(test) click to toggle source

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)
# File lib/bigbench/runner.rb, line 45
def self.load_test!(test)
  BigBench::Benchmark.reset!
  eval(test)
  check_config!
  BigBench::Output.loaded_tests
end
run!() click to toggle source

Runs all initialized benchmarks

# File lib/bigbench/runner.rb, line 31
def self.run!
  BigBench::Output.running_benchmarks
  Runner.run!
  BigBench::Output.finished_running_benchmarks
end
write_local_trackings_to_file!() click to toggle source

Writes the locals trackings from the benchmark to a file

# 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 + "\n"
        counter += 1
      end
    end
  end
  
  BigBench::Output.finished_writing_trackings(counter)
end
write_store_trackings_to_file!() click to toggle source

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

# 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!() click to toggle source

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

# 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)
      counter += 1
    end
  end
  
  BigBench::Output.finished_writing_trackings(counter)
end