Skip to content

Commit a019798

Browse files
committed
(PUP-5482) Add a benchmark to missing type caching
This commit adds a simple benchmark to measure the effect of caching type load misses. It works by creating a single populated module with a defined type that is defined in init.pp. It also creates a number of other empty modules to expand the required search_path.
1 parent c4c5c0d commit a019798

File tree

5 files changed

+77
-0
lines changed

5 files changed

+77
-0
lines changed
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
require 'erb'
2+
require 'ostruct'
3+
require 'fileutils'
4+
require 'json'
5+
6+
class Benchmarker
7+
include FileUtils
8+
9+
def initialize(target, size)
10+
@target = target
11+
@size = size
12+
end
13+
14+
def setup
15+
require 'puppet'
16+
config = File.join(@target, 'puppet.conf')
17+
Puppet.initialize_settings(['--config', config])
18+
Puppet[:always_retry_plugins] = false
19+
end
20+
21+
def run(args=nil)
22+
env = Puppet.lookup(:environments).get('benchmarking')
23+
node = Puppet::Node.new("testing", :environment => env)
24+
Puppet::Resource::Catalog.indirection.find("testing", :use_node => node)
25+
end
26+
27+
def generate
28+
environment = File.join(@target, 'environments', 'benchmarking')
29+
templates = File.join('benchmarks', 'missing_type_caching')
30+
test_module_dir = File.join(environment, 'modules', 'testmodule',
31+
'manifests')
32+
33+
mkdir_p(File.join(environment, 'modules'))
34+
@size.times.each do |i|
35+
mkdir_p(File.join(environment, 'modules', "mymodule_#{i}", 'lib',
36+
'puppet', 'type'))
37+
mkdir_p(File.join(environment, 'modules', "mymodule_#{i}", 'manifests'))
38+
end
39+
mkdir_p(File.join(environment, 'manifests'))
40+
41+
mkdir_p(test_module_dir)
42+
43+
44+
render(File.join(templates, 'site.pp.erb'),
45+
File.join(environment, 'manifests', 'site.pp'),
46+
:size => @size)
47+
48+
render(File.join(templates, 'module', 'testmodule.pp.erb'),
49+
File.join(test_module_dir, 'init.pp'),
50+
:name => "foo")
51+
52+
render(File.join(templates, 'puppet.conf.erb'),
53+
File.join(@target, 'puppet.conf'),
54+
:location => @target)
55+
end
56+
57+
def render(erb_file, output_file, bindings)
58+
site = ERB.new(File.read(erb_file))
59+
File.open(output_file, 'w') do |fh|
60+
fh.write(site.result(OpenStruct.new(bindings).instance_eval { binding }))
61+
end
62+
end
63+
end
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Benchmark scenario: heavy use of defined types found in init.pp
2+
Benchmark target: catalog compilation
3+
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
define testmodule {
2+
notify { "in <%= name %>: $title": }
3+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
confdir = <%= location %>
2+
vardir = <%= location %>
3+
environmentpath = <%= File.join(location, 'environments') %>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
if true {
2+
<% size.times do |i| %>
3+
testmodule { "foo<%= i %>": }
4+
<% end %>
5+
}

0 commit comments

Comments
 (0)