Skip to content

Commit

Permalink
recalculate reserved_code_cache based upon calculated jrubies
Browse files Browse the repository at this point in the history
  • Loading branch information
tkishel committed Feb 14, 2019
1 parent 84b1fe0 commit cc09792
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 10 deletions.
28 changes: 21 additions & 7 deletions lib/puppet_x/puppetlabs/tune/calculate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ def calculate_master_settings(node)
minimum_cpu_jrubies = 2
minimum_ram_puppetserver = 1024
ram_per_puppetserver_jruby = fit_to_memory(node['resources']['ram'], 512, 768, 1024)
ram_puppetserver_code_cache = fit_to_memory(node['resources']['ram'], 512, 1024, 2048)
minimum_ram_code_cache = 512
maximum_ram_code_cache = 2048
ram_per_jruby_code_cache = 128
ram_puppetserver_code_cache = fit_to_memory(node['resources']['ram'], minimum_ram_code_cache, 1024, maximum_ram_code_cache) # Estimate, prior to fit_to_jrubies.
percent_ram_database = 25
minimum_ram_database = fit_to_memory(node['resources']['ram'], 2048, 3072, 4096)
maximum_ram_database = 16384
Expand Down Expand Up @@ -66,10 +69,6 @@ def calculate_master_settings(node)
end
end

# Reallocate resources from puppetserver depending upon jruby version.

ram_puppetserver_code_cache = 0 unless node['type']['with_jruby9k_enabled']

# Reallocate resources depending upon services active on this host.

percent_cpu_jrubies = 100 unless node['classes']['puppetdb']
Expand Down Expand Up @@ -107,6 +106,10 @@ def calculate_master_settings(node)
ram_activemq = 256
end

# Reallocate resources from puppetserver depending upon jruby version.

ram_puppetserver_code_cache = 0 unless node['type']['with_jruby9k_enabled']

settings = initialize_settings(node)

if node['classes']['database']
Expand Down Expand Up @@ -143,6 +146,8 @@ def calculate_master_settings(node)
settings['totals']['RAM']['used'] += ram_puppetdb
end

# Consider subtracting ram_puppetserver_code_cache estimate from available_ram_for_puppetserver.

available_ram_for_puppetserver = node['resources']['ram'] - minimum_ram_os - settings['totals']['RAM']['used']
if available_ram_for_puppetserver < minimum_ram_puppetserver
Puppet.debug("Error: available_ram_for_puppetserver: #{available_ram_for_puppetserver} < minimum_ram_puppetserver: #{minimum_ram_puppetserver}")
Expand All @@ -157,8 +162,17 @@ def calculate_master_settings(node)
ram_jrubies = (jruby_max_active_instances * ram_per_puppetserver_jruby)
ram_puppetserver = [ram_jrubies, minimum_ram_puppetserver].max
settings['params']['puppet_enterprise::profile::master::java_args'] = { 'Xms' => "#{ram_puppetserver}m", 'Xmx' => "#{ram_puppetserver}m" }
settings['params']['puppet_enterprise::master::puppetserver::reserved_code_cache'] = "#{ram_puppetserver_code_cache}m" if ram_puppetserver_code_cache > 0
settings['totals']['RAM']['used'] += ram_puppetserver + ram_puppetserver_code_cache
settings['totals']['RAM']['used'] += ram_puppetserver

if node['type']['with_jruby9k_enabled']
# Recalulate ram_puppetserver_code_cache estimate.
unless ram_puppetserver_code_cache == 256
code_cache_by_ram_per_jruby = jruby_max_active_instances * ram_per_jruby_code_cache
ram_puppetserver_code_cache = value_within_min_max(code_cache_by_ram_per_jruby, minimum_ram_code_cache, maximum_ram_code_cache)
end
settings['params']['puppet_enterprise::master::puppetserver::reserved_code_cache'] = "#{ram_puppetserver_code_cache}m"
settings['totals']['RAM']['used'] += ram_puppetserver_code_cache
end

if node['classes']['console']
settings['params']['puppet_enterprise::profile::console::java_args'] = { 'Xms' => "#{ram_console}m", 'Xmx' => "#{ram_console}m" }
Expand Down
26 changes: 23 additions & 3 deletions spec/unit/puppet_x/puppetlabs/tune/calculate_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@
node['type']['with_jruby9k_enabled'] = true
node['classes'].delete('amq::broker')
settings['params']['puppet_enterprise::master::puppetserver::reserved_code_cache'] = '256m'
settings['totals']['RAM']['used'] += 256
settings['totals']['RAM']['used'] -= settings['params']['puppet_enterprise::profile::amq::broker::heap_mb']
settings['params'].delete('puppet_enterprise::profile::amq::broker::heap_mb')
end

Expand Down Expand Up @@ -108,6 +110,8 @@
node['type']['with_jruby9k_enabled'] = true
node['classes'].delete('amq::broker')
settings['params']['puppet_enterprise::master::puppetserver::reserved_code_cache'] = '512m'
settings['totals']['RAM']['used'] += 512
settings['totals']['RAM']['used'] -= settings['params']['puppet_enterprise::profile::amq::broker::heap_mb']
settings['params'].delete('puppet_enterprise::profile::amq::broker::heap_mb')
end

Expand Down Expand Up @@ -159,7 +163,9 @@
if pe_2019_or_newer
node['type']['with_jruby9k_enabled'] = true
node['classes'].delete('amq::broker')
settings['params']['puppet_enterprise::master::puppetserver::reserved_code_cache'] = '1024m'
settings['params']['puppet_enterprise::master::puppetserver::reserved_code_cache'] = '640m'
settings['totals']['RAM']['used'] += 640
settings['totals']['RAM']['used'] -= settings['params']['puppet_enterprise::profile::amq::broker::heap_mb']
settings['params'].delete('puppet_enterprise::profile::amq::broker::heap_mb')
end

Expand Down Expand Up @@ -211,7 +217,9 @@
if pe_2019_or_newer
node['type']['with_jruby9k_enabled'] = true
node['classes'].delete('amq::broker')
settings['params']['puppet_enterprise::master::puppetserver::reserved_code_cache'] = '2048m'
settings['params']['puppet_enterprise::master::puppetserver::reserved_code_cache'] = '1408m'
settings['totals']['RAM']['used'] += 1408
settings['totals']['RAM']['used'] -= settings['params']['puppet_enterprise::profile::amq::broker::heap_mb']
settings['params'].delete('puppet_enterprise::profile::amq::broker::heap_mb')
end

Expand Down Expand Up @@ -260,6 +268,15 @@
}
settings = { 'params' => params, 'totals' => totals }

if pe_2019_or_newer
node['type']['with_jruby9k_enabled'] = true
node['classes'].delete('amq::broker')
settings['params']['puppet_enterprise::master::puppetserver::reserved_code_cache'] = '512m'
settings['totals']['RAM']['used'] += 512
settings['totals']['RAM']['used'] -= settings['params']['puppet_enterprise::profile::amq::broker::heap_mb']
settings['params'].delete('puppet_enterprise::profile::amq::broker::heap_mb')
end

expect(calculator::calculate_master_settings(node)).to eq(settings)
end

Expand Down Expand Up @@ -305,9 +322,12 @@
settings = { 'params' => params, 'totals' => totals }

if pe_2019_or_newer
node['type']['with_jruby9k_enabled'] = true
node['classes'].delete('amq::broker')
settings['params']['puppet_enterprise::master::puppetserver::reserved_code_cache'] = '512m'
settings['totals']['RAM']['used'] += 512
settings['totals']['RAM']['used'] -= settings['params']['puppet_enterprise::profile::amq::broker::heap_mb']
settings['params'].delete('puppet_enterprise::profile::amq::broker::heap_mb')
settings['totals']['RAM']['used'] -= 512
end

expect(calculator::calculate_master_settings(node)).to eq(settings)
Expand Down

0 comments on commit cc09792

Please sign in to comment.