Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refs #30057 - Configure Pulpcore Worker Count #100

Merged
merged 1 commit into from
Jul 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions lib/facter/pulpcore_workers.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Facter.add(:pulpcore_workers) do
setcode do
directory = '/etc/systemd/system/multi-user.target.wants'
worker_glob = 'pulpcore-worker@*.service'
worker_template = '/etc/systemd/system/pulpcore-worker@.service'
if File.exist?(worker_template)
Dir[File.join(directory, worker_glob)].map do |worker|
File.basename(worker)
end
else
nil
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[0] $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 |$worker| {
if $worker =~ /^pulpcore-worker@\d+\.service$/ and !defined(Service[$worker]) {
service { $worker:
ensure => stopped,
enable => false,
require => [Systemd::Unit_file['pulpcore-worker@.service'], Class['systemd::systemctl::daemon_reload']],
}
}
}
}
}
73 changes: 72 additions & 1 deletion spec/acceptance/basic_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ class { 'redis::globals':
}
}

include pulpcore
class { 'pulpcore':
worker_count => 2,
}
PUPPET
}

Expand All @@ -45,6 +47,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 +72,62 @@ 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',
}
}

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
60 changes: 60 additions & 0 deletions spec/classes/pulpcore_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,66 @@
end
end

context 'with worker_count set to 5' do
let(:params) { { worker_count: 5 } }

context 'with 6 workers from fact' do
let(:facts) { super().merge(pulpcore_workers: (1..6).map { |n| "pulpcore-worker@#{n}.service" } ) }

it 'is expected to reduce the workers to 5' do
is_expected.to compile.with_all_deps
(1..5).each do |n|
is_expected.to contain_service("pulpcore-worker@#{n}.service")
.with_ensure('running')
.with_enable('true')
end
is_expected.to contain_service('pulpcore-worker@6.service')
.with_ensure('stopped')
.with_enable('false')
end
end

context 'with 4 workers from fact' do
let(:facts) { super().merge(pulpcore_workers: (1..4).map { |n| "pulpcore-worker@#{n}.service" } ) }

it 'is expected to increase the workers to 5' do
is_expected.to compile.with_all_deps
(1..5).each do |n|
is_expected.to contain_service("pulpcore-worker@#{n}.service")
.with_ensure('running')
.with_enable('true')
end
is_expected.not_to contain_service('pulpcore-worker@6.service')
end
end

context 'with 0 workers from fact' do
let(:facts) { super().merge(pulpcore_workers: {} ) }

it 'is expected to enable 5 workers' do
is_expected.to compile.with_all_deps
(1..5).each do |n|
is_expected.to contain_service("pulpcore-worker@#{n}.service")
.with_ensure('running')
.with_enable('true')
end
is_expected.not_to contain_service('pulpcore-worker@6.service')
end
end

context 'fact absent' do
it 'is expected to enable 5 workers' do
is_expected.to compile.with_all_deps
(1..5).each do |n|
is_expected.to contain_service("pulpcore-worker@#{n}.service")
.with_ensure('running')
.with_enable('true')
end
is_expected.not_to contain_service('pulpcore-worker@6.service')
end
end
end

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