Skip to content

Commit

Permalink
Refs #30057 - Configure Pulpcore Worker Count
Browse files Browse the repository at this point in the history
  • Loading branch information
wbclark committed Jun 25, 2020
1 parent bed36c5 commit 15f4b4d
Show file tree
Hide file tree
Showing 5 changed files with 126 additions and 4 deletions.
11 changes: 11 additions & 0 deletions lib/facter/pulpcore_workers.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Facter.add(:pulpcore_workers) do
setcode do
directory = '/etc/systemd/system/multi-user.target.wants'
extension = 'pulpcore-worker@*.service'
return unless File.exist?(directory)

Dir[File.join(directory, "*#{extension}")].map do |config|
File.basename(config, extension)
end
end
end
6 changes: 6 additions & 0 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@
# @param allowed_import_path
# Allowed paths that pulp can sync from using file:// protocol
#
# @param worker_count
# Number of pulpcore workers. Defaults to 8 or the number of CPU cores, whichever is smaller. Enabling more than 8 workers, even with additional CPU cores
# available, likely results in performance degradation due to I/O blocking and is not recommended in most cases. Modifying this parameter should
# be done incrementally with benchmarking at each step to determine an optimal value for your deployment.
#
# @example
# include pulpcore
class pulpcore (
Expand Down Expand Up @@ -115,6 +120,7 @@
Stdlib::Fqdn $servername = $facts['networking']['fqdn'],
Array[Stdlib::Absolutepath] $allowed_import_path = ['/var/lib/pulp/sync_imports'],
Optional[String] $remote_user_environ_name = undef,
Integer[1] $worker_count = min(8, $facts['processors']['count']),
) {

$settings_file = "${config_dir}/settings.py"
Expand Down
22 changes: 18 additions & 4 deletions manifests/service.pp
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,24 @@
content => template('pulpcore/pulpcore-worker@.service.erb'),
}

service { ['pulpcore-worker@1', 'pulpcore-worker@2']:
ensure => running,
enable => true,
require => [Systemd::Unit_file['pulpcore-worker@.service'], Class['systemd::systemctl::daemon_reload']],
Integer[1, $pulpcore::worker_count].each |$n| {
service { "pulpcore-worker@${n}.service":
ensure => running,
enable => true,
require => [Systemd::Unit_file['pulpcore-worker@.service'], Class['systemd::systemctl::daemon_reload']],
}
}

$existing_workers = fact('pulpcore_workers')
if $existing_workers {
$existing_workers.each |$instance| {
if $instance =~ Pattern["^pulpcore-worker@\d+\.service$"] and !defined(Service[$instance]) {
service { $instance:
ensure => stopped,
enable => false,
require => [Systemd::Unit_file['pulpcore-worker@.service', Class['systemd::systemctl::daemon_reload']],
}
}
}
}
}
73 changes: 73 additions & 0 deletions spec/acceptance/basic_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ class { 'redis::globals':
}
include pulpcore
class { 'pulpcore':
worker_count => 2,
}
PUPPET
}

Expand All @@ -45,6 +48,16 @@ class { 'redis::globals':
it { is_expected.to be_running }
end

describe service('pulpcore-worker@1') do
it { is_expected.to be_enabled }
it { is_expected.to be_running }
end

describe service('pulpcore-worker@3') do
it { is_expected.not_to be_enabled }
it { is_expected.not_to be_running }
end

describe port(80) do
it { is_expected.to be_listening }
end
Expand All @@ -60,3 +73,63 @@ class { 'redis::globals':
end

end

describe 'reducing worker count' do
let(:pp) {
<<-PUPPET
if $facts['os']['release']['major'] == '7' {
class { 'postgresql::globals':
version => '12',
client_package_name => 'rh-postgresql12-postgresql-syspaths',
server_package_name => 'rh-postgresql12-postgresql-server-syspaths',
contrib_package_name => 'rh-postgresql12-postgresql-contrib-syspaths',
service_name => 'postgresql',
datadir => '/var/lib/pgsql/data',
confdir => '/var/lib/pgsql/data',
bindir => '/usr/bin',
}
class { 'redis::globals':
scl => 'rh-redis5',
}
}
include pulpcore
class { 'pulpcore':
worker_count => 1,
}
PUPPET
}

it_behaves_like 'a idempotent resource'

describe service('httpd') do
it { is_expected.to be_enabled }
it { is_expected.to be_running }
end

describe service('pulpcore-api') do
it { is_expected.to be_enabled }
it { is_expected.to be_running }
end

describe service('pulpcore-content') do
it { is_expected.to be_enabled }
it { is_expected.to be_running }
end

describe service('pulpcore-resource-manager') do
it { is_expected.to be_enabled }
it { is_expected.to be_running }
end

describe service('pulpcore-worker@1') do
it { is_expected.to be_enabled }
it { is_expected.to be_running }
end

describe service('pulpcore-worker@2') do
it { is_expected.not_to be_enabled }
it { is_expected.not_to be_running }
end

end
18 changes: 18 additions & 0 deletions spec/classes/pulpcore_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,24 @@
end
end

context 'with custom worker count' do
let :params do
{
worker_count: 5
}
end

it do
is_expected.to compile.with_all_deps
is_expected.to contain_service('pulpcore-worker@5')
.with_ensure('running')
.with_enable('true')
is_expected.to contain_service('pulpcore-worker@6')
.with_ensure('stopped')
.with_enable('false')
end
end

context 'without apache httpd' do
let :params do
{
Expand Down

0 comments on commit 15f4b4d

Please sign in to comment.