Skip to content

Commit

Permalink
(maint) Adds environment functions to function loading performance test
Browse files Browse the repository at this point in the history
  • Loading branch information
thallgren committed Feb 20, 2015
1 parent 6c43c83 commit 3e70572
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 9 deletions.
19 changes: 10 additions & 9 deletions benchmarks/function_loading/benchmarker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ def setup
end

def run(args=nil)
env = Puppet.lookup(:environments).get("benchmarking#{benchmark_count}")
node = Puppet::Node.new("testing", :environment => env)
Puppet::Resource::Catalog.indirection.find("testing", :use_node => node)
envs = Puppet.lookup(:environments)
envs.clear('benchmarking')
node = Puppet::Node.new('testing', :environment => envs.get('benchmarking'))
Puppet::Resource::Catalog.indirection.find('testing', :use_node => node)
end

def benchmark_count
Expand All @@ -31,16 +32,13 @@ def benchmark_count
end

def generate
# We need a new environment for each iteration
ENV['ITERATIONS'].to_i.times { |c| generate_env(c) }
end

def generate_env(c)
environment = File.join(@target, 'environments', "benchmarking#{c}")
environment = File.join(@target, 'environments', 'benchmarking')
modules = File.join(environment, 'modules')
env_functions = File.join(environment, 'lib', 'puppet', 'functions', 'environment')
templates = File.join('benchmarks', 'function_loading')

mkdir_p(modules)
mkdir_p(env_functions)
mkdir_p(File.join(environment, 'manifests'))

module_count = @size / 10
Expand All @@ -49,6 +47,9 @@ def generate_env(c)
File.join(environment, 'manifests', 'site.pp'),
:size => module_count)

env_function_template = File.join(templates, 'env_function.erb')
function_count.times { |n| render(env_function_template, File.join(env_functions, "f#{n}.rb"), :n => n) }

module_count.times do |i|
module_name = "module#{i}"
module_base = File.join(modules, module_name)
Expand Down
5 changes: 5 additions & 0 deletions benchmarks/function_loading/env_function.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Puppet::Functions.create_function(:'environment::f<%= n %>') do
def f<%= n %>
<% if n > 0 %>call_function(:'environment::f<%= n-1 %>')<% else %>'environment::f<%= n %>'<% end %>
end
end
1 change: 1 addition & 0 deletions benchmarks/function_loading/puppet.conf.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
confdir = <%= location %>
vardir = <%= location %>
environmentpath = <%= File.join(location, 'environments') %>
environment_timeout = 40s
parser = future
2 changes: 2 additions & 0 deletions benchmarks/function_loading/site.pp.erb
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
environment::f999()
<% size.times do |i| %>include module<%= i %>
<% end %>

0 comments on commit 3e70572

Please sign in to comment.