Browse Source

Use non-legacy fact name for os_workers

processorcount is a legacy fact name. Lets switch the newer fact name.

Change-Id: I310818ffd03ef92890bc5d9f10ad334b5281b126
Related-Bug: #1868454
tags/16.2.0
Alex Schultz 3 months ago
parent
commit
3b39a090b1
6 changed files with 36 additions and 31 deletions
  1. +17
    -12
      lib/facter/os_workers.rb
  2. +4
    -4
      spec/unit/facter/os_workers_heat_engine_spec.rb
  3. +4
    -4
      spec/unit/facter/os_workers_keystone_spec.rb
  4. +3
    -3
      spec/unit/facter/os_workers_large_spec.rb
  5. +4
    -4
      spec/unit/facter/os_workers_small_spec.rb
  6. +4
    -4
      spec/unit/facter/os_workers_spec.rb

+ 17
- 12
lib/facter/os_workers.rb View File

@@ -1,5 +1,5 @@
#
# We've found that using $::processorcount for workers/threads can lead to
# We've found that using $facts['processors']['count] for workers/threads can lead to
# unexpected memory or process counts for people deploying on baremetal or
# if they have large number of cpus. This fact allows us to tweak the formula
# used to determine number of workers in a single place but use it across all
@@ -11,17 +11,26 @@
# This fact can be overloaded by an external fact from /etc/factor/facts.d if
# a user would like to provide their own default value.
#
#
def get_proc_count
procs = Facter.value('processors')
if procs.key?('count') then
procs['count'].to_i
else
1
end
end

Facter.add(:os_workers_small) do
has_weight 100
setcode do
processors = Facter.value('processorcount')
[ [ (processors.to_i / 4), 2 ].max, 8 ].min
[ [ (get_proc_count / 4), 2 ].max, 8 ].min
end
end

#
# The value above for os_workers performs 3x worse in many cases compared to
# the prevuous default of $::processorcount.
# the previous default of $facts['processors']['count'].
#
# Based on performance data [1], the following calculation is within 1-2%.
#
@@ -33,8 +42,7 @@ end
Facter.add(:os_workers) do
has_weight 100
setcode do
processors = Facter.value('processorcount')
[ [ (processors.to_i / 2), 2 ].max, 12 ].min
[ [ (get_proc_count / 2), 2 ].max, 12 ].min
end
end

@@ -44,8 +52,7 @@ end
Facter.add(:os_workers_large) do
has_weight 100
setcode do
processors = Facter.value('processorcount')
[ (processors.to_i / 2), 1 ].max
[ (get_proc_count / 2), 1 ].max
end
end

@@ -57,8 +64,7 @@ end
Facter.add(:os_workers_heat_engine) do
has_weight 100
setcode do
processors = Facter.value('processorcount')
[ [ (processors.to_i / 2), 4 ].max, 24 ].min
[ [ (get_proc_count / 2), 4 ].max, 24 ].min
end
end

@@ -70,7 +76,6 @@ end
Facter.add(:os_workers_keystone) do
has_weight 100
setcode do
processors = Facter.value('processorcount')
[ [ processors.to_i, 4 ].max, 24 ].min
[ [ get_proc_count, 4 ].max, 24 ].min
end
end

+ 4
- 4
spec/unit/facter/os_workers_heat_engine_spec.rb View File

@@ -2,11 +2,11 @@ require 'spec_helper'

describe 'os_workers_heat_engine' do

before { Facter.flush }
before { Facter.clear }

context 'with processorcount=1' do
before do
Facter.fact(:processorcount).stubs(:value).returns(1)
Facter.fact(:processors).stubs(:value).returns({'count' => 1})
end

it 'returns a minimum of 2' do
@@ -16,7 +16,7 @@ describe 'os_workers_heat_engine' do

context 'with processorcount=8' do
before do
Facter.fact(:processorcount).stubs(:value).returns(8)
Facter.fact(:processors).stubs(:value).returns({'count' => 8})
end

it 'returns processorcount/2' do
@@ -26,7 +26,7 @@ describe 'os_workers_heat_engine' do

context 'with processorcount=64' do
before do
Facter.fact(:processorcount).stubs(:value).returns(64)
Facter.fact(:processors).stubs(:value).returns({'count' => 64})
end

it 'returns a maximum of 24' do


+ 4
- 4
spec/unit/facter/os_workers_keystone_spec.rb View File

@@ -2,11 +2,11 @@ require 'spec_helper'

describe 'os_workers_keystone' do

before { Facter.flush }
before { Facter.clear }

context 'with processorcount=1' do
before do
Facter.fact(:processorcount).stubs(:value).returns(1)
Facter.fact(:processors).stubs(:value).returns({'count' => 1})
end

it 'returns a minimum of 4' do
@@ -16,7 +16,7 @@ describe 'os_workers_keystone' do

context 'with processorcount=8' do
before do
Facter.fact(:processorcount).stubs(:value).returns(8)
Facter.fact(:processors).stubs(:value).returns({'count' => 8})
end

it 'returns processorcount' do
@@ -26,7 +26,7 @@ describe 'os_workers_keystone' do

context 'with processorcount=32' do
before do
Facter.fact(:processorcount).stubs(:value).returns(32)
Facter.fact(:processors).stubs(:value).returns({'count' => 32})
end

it 'returns a maximum of 24' do


+ 3
- 3
spec/unit/facter/os_workers_large_spec.rb View File

@@ -2,11 +2,11 @@ require 'spec_helper'

describe 'os_workers_large' do

before { Facter.flush }
before { Facter.clear }

context 'with processorcount=1' do
before do
Facter.fact(:processorcount).stubs(:value).returns(1)
Facter.fact(:processors).stubs(:value).returns({'count' => 1})
end

it 'returns a minimum of 1' do
@@ -16,7 +16,7 @@ describe 'os_workers_large' do

context 'with processorcount=8' do
before do
Facter.fact(:processorcount).stubs(:value).returns(8)
Facter.fact(:processors).stubs(:value).returns({'count' => 8})
end

it 'returns processorcount/2' do


+ 4
- 4
spec/unit/facter/os_workers_small_spec.rb View File

@@ -2,11 +2,11 @@ require 'spec_helper'

describe 'os_workers_small' do

before { Facter.flush }
before { Facter.clear }

context 'with processorcount=1' do
before do
Facter.fact(:processorcount).stubs(:value).returns(1)
Facter.fact(:processors).stubs(:value).returns({'count' => 1})
end

it 'returns a minimum of 2' do
@@ -16,7 +16,7 @@ describe 'os_workers_small' do

context 'with processorcount=16' do
before do
Facter.fact(:processorcount).stubs(:value).returns(16)
Facter.fact(:processors).stubs(:value).returns({'count' => 16})
end

it 'returns processorcount/4' do
@@ -26,7 +26,7 @@ describe 'os_workers_small' do

context 'with processorcount=32' do
before do
Facter.fact(:processorcount).stubs(:value).returns(32)
Facter.fact(:processors).stubs(:value).returns({'count' => 32})
end

it 'returns a maximum of 8' do


+ 4
- 4
spec/unit/facter/os_workers_spec.rb View File

@@ -2,11 +2,11 @@ require 'spec_helper'

describe 'os_workers' do

before { Facter.flush }
before { Facter.clear }

context 'with processorcount=1' do
before do
Facter.fact(:processorcount).stubs(:value).returns(1)
Facter.fact(:processors).stubs(:value).returns({'count' => 1})
end

it 'returns a minimum of 2' do
@@ -16,7 +16,7 @@ describe 'os_workers' do

context 'with processorcount=8' do
before do
Facter.fact(:processorcount).stubs(:value).returns(8)
Facter.fact(:processors).stubs(:value).returns({'count' => 8})
end

it 'returns processorcount/2' do
@@ -26,7 +26,7 @@ describe 'os_workers' do

context 'with processorcount=32' do
before do
Facter.fact(:processorcount).stubs(:value).returns(32)
Facter.fact(:processors).stubs(:value).returns({'count' => 32})
end

it 'returns a maximum of 12' do


Loading…
Cancel
Save