Skip to content

Commit

Permalink
749495 - installation script process count
Browse files Browse the repository at this point in the history
  • Loading branch information
lzap committed Nov 2, 2011
1 parent b7f6243 commit d40a607
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
31 changes: 31 additions & 0 deletions puppet/lib/puppet/parser/functions/katello_process_count.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
module Puppet::Parser::Functions
newfunction(:katello_process_count) do |args|
begin
cpu_count = scope.lookupvar('::processorcount')
consumes = 230_000_000 # for each thin process
reserve = 500_000_000 # for the OS
mem,unit = scope.lookupvar('::memorysize').split

# convert total memory into bytes
total_mem = mem.to_f
case unit
when nil: total_mem *= (1<<0)
when 'kB': total_mem *= (1<<10)
when 'MB': total_mem *= (1<<20)
when 'GB': total_mem *= (1<<30)
when 'TB': total_mem *= (1<<40)
end

# calculate number of processes
no_processes = (((total_mem - reserve) / (cpu_count * consumes))).floor

# safeguard not to return bigger number then cpu count + 1
no_processes = cpu_count + 1 if no_processes > cpu_count * 2

no_processes
rescue Exception => e
# when anything goes wrong return a decent constant
2
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ NameVirtualHost *:443
ProxyTimeout 5400

<Proxy balancer://thinservers>
<%- (processorcount.to_i + 1).times do |i| -%>
<%- katello_process_count().times do |i| -%>
<%= "BalancerMember http://127.0.0.1:#{scope.lookupvar('katello::params::thin_start_port').to_i + i}/#{scope.lookupvar('katello::params::deployment')}" %>
<%- end -%>
</Proxy>
Expand Down
2 changes: 1 addition & 1 deletion puppet/modules/katello/templates/etc/katello/thin.yml.erb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ require: []

environment: production
max_persistent_conns: 512
servers: <%= processorcount.to_i + 1 %>
servers: <%= katello_process_count() %>
daemonize: yes
chdir: <%= scope.lookupvar("katello::params::katello_dir") %>

0 comments on commit d40a607

Please sign in to comment.