diff --git a/benchmarks/many_modules/benchmark.rb b/benchmarks/many_modules/benchmarker.rb similarity index 98% rename from benchmarks/many_modules/benchmark.rb rename to benchmarks/many_modules/benchmarker.rb index fd60c4a01..10a32b93a 100644 --- a/benchmarks/many_modules/benchmark.rb +++ b/benchmarks/many_modules/benchmarker.rb @@ -1,62 +1,62 @@ require 'erb' require 'ostruct' require 'fileutils' -class ManyModules +class Benchmarker include FileUtils def initialize(target, size) @target = target @size = size end def setup require 'puppet' config = File.join(@target, 'puppet.conf') Puppet.initialize_settings(['--config', config]) end def run env = Puppet.lookup(:environments).get('benchmarking') node = Puppet::Node.new("testing", :environment => env) Puppet::Resource::Catalog.indirection.find("testing", :use_node => node) end def generate environment = File.join(@target, 'environments', 'benchmarking') templates = File.join('benchmarks', 'many_modules') mkdir_p(File.join(environment, 'modules')) mkdir_p(File.join(environment, 'manifests')) render(File.join(templates, 'site.pp.erb'), File.join(environment, 'manifests', 'site.pp'), :size => @size) @size.times do |i| module_name = "module#{i}" manifests = File.join(environment, 'modules', module_name, 'manifests') mkdir_p(manifests) render(File.join(templates, 'module', 'init.pp.erb'), File.join(manifests, 'init.pp'), :name => module_name) render(File.join(templates, 'module', 'internal.pp.erb'), File.join(manifests, 'internal.pp'), :name => module_name) end render(File.join(templates, 'puppet.conf.erb'), File.join(@target, 'puppet.conf'), :location => @target) end def render(erb_file, output_file, bindings) site = ERB.new(File.read(erb_file)) File.open(output_file, 'w') do |fh| fh.write(site.result(OpenStruct.new(bindings).instance_eval { binding })) end end end diff --git a/benchmarks/many_modules/description b/benchmarks/many_modules/description new file mode 100644 index 000000000..a2b58ebe7 --- /dev/null +++ b/benchmarks/many_modules/description @@ -0,0 +1,3 @@ +Benchmark scenario: many manifests spread across many modules. +Benchmark target: catalog compilation. + diff --git a/tasks/benchmark.rake b/tasks/benchmark.rake index 00569c23f..afee2766e 100644 --- a/tasks/benchmark.rake +++ b/tasks/benchmark.rake @@ -1,64 +1,68 @@ require 'benchmark' require 'tmpdir' require 'erb' require 'ostruct' require 'open3' -desc "Execute all puppet benchmarks." -task :benchmark => ["benchmark:many_modules"] - namespace :benchmark do - desc "Benchmark scenario: many manifests spread across many modules. -Benchmark target: catalog compilation." - task :many_modules => "many_modules:run" + def generate_scenario_tasks(location, name) + desc File.read(File.join(location, 'description')) + task name => "#{name}:run" - namespace :many_modules do - task :setup do - ENV['SIZE'] ||= '100' - ENV['TARGET'] ||= Dir.mktmpdir("many_modules") - ENV['TARGET'] = File.expand_path(ENV['TARGET']) + namespace name do + task :setup do + ENV['ITERATIONS'] ||= '10' + ENV['SIZE'] ||= '100' + ENV['TARGET'] ||= Dir.mktmpdir(name) + ENV['TARGET'] = File.expand_path(ENV['TARGET']) - mkdir_p(ENV['TARGET']) + mkdir_p(ENV['TARGET']) - require File.expand_path(File.join('benchmarks', 'many_modules', 'benchmark.rb')) + require File.expand_path(File.join(location, 'benchmarker.rb')) - @benchmark = ManyModules.new(ENV['TARGET'], ENV['SIZE'].to_i) - end + @benchmark = Benchmarker.new(ENV['TARGET'], ENV['SIZE'].to_i) + end - desc "Generate the scenario" - task :generate => :setup do - @benchmark.generate - end + desc "Generate the #{name} scenario." + task :generate => :setup do + @benchmark.generate + end - task :run => :generate do - @benchmark.setup - Benchmark.benchmark(Benchmark::CAPTION, 10, Benchmark::FORMAT, "> total:", "> avg:") do |b| - times = [] - 10.times do |i| - times << b.report("Run #{i + 1}") do - @benchmark.run + desc "Run the #{name} scenario." + task :run => :generate do + @benchmark.setup + Benchmark.benchmark(Benchmark::CAPTION, 10, Benchmark::FORMAT, "> total:", "> avg:") do |b| + times = [] + ENV['ITERATIONS'].to_i.times do |i| + times << b.report("Run #{i + 1}") do + @benchmark.run + end end - end - sum = times.inject(Benchmark::Tms.new, &:+) + sum = times.inject(Benchmark::Tms.new, &:+) - [sum, sum / times.length] + [sum, sum / times.length] + end end - end - task :profile => :generate do - require 'ruby-prof' + desc "Profile a single run of the #{name} scenario." + task :profile => :generate do + require 'ruby-prof' - @benchmark.setup - result = RubyProf.profile do - @benchmark.run - end + @benchmark.setup + result = RubyProf.profile do + @benchmark.run + end - printer = RubyProf::CallTreePrinter.new(result) - File.open(File.join("callgrind.many_modules.#{Time.now.to_i}.trace"), "w") do |f| - printer.print(f) + printer = RubyProf::CallTreePrinter.new(result) + File.open(File.join("callgrind.#{name}.#{Time.now.to_i}.trace"), "w") do |f| + printer.print(f) + end end - end end + + Dir.glob('benchmarks/*') do |location| + generate_scenario_tasks(location, File.basename(location)) + end end