Skip to content

Commit fe562f6

Browse files
committed
Cleanups
1 parent a5f09a5 commit fe562f6

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

lib/concurrent-ruby/concurrent/utility/processor_counter.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def compute_physical_processor_count
8282
end
8383

8484
def compute_cpu_quota
85-
if RbConfig::CONFIG["target_os"].match(/linux/i)
85+
if RbConfig::CONFIG["target_os"].include?("linux")
8686
if File.exist?("/sys/fs/cgroup/cpu.max")
8787
# cgroups v2: https://docs.kernel.org/admin-guide/cgroup-v2.html#cpu-interface-files
8888
cpu_max = File.read("/sys/fs/cgroup/cpu.max")
@@ -158,7 +158,7 @@ def self.available_processor_count
158158
processor_counter.available_processor_count
159159
end
160160

161-
# The maximun number of processors cores available for process scheduling.
161+
# The maximum number of processors cores available for process scheduling.
162162
# Returns `nil` if there is no enforced limit, or a `Float` if the
163163
# process is inside a cgroup with a dedicated CPU quota (typically Docker).
164164
#
@@ -168,7 +168,7 @@ def self.available_processor_count
168168
# For performance reasons the calculated value will be memoized on the first
169169
# call.
170170
#
171-
# @return [nil, Float] Maximum number of available processors seen by the OS or Java runtime
171+
# @return [nil, Float] Maximum number of available processors as set by a cgroup CPU quota, or nil if none set
172172
def self.cpu_quota
173173
processor_counter.cpu_quota
174174
end

spec/concurrent/utility/processor_count_spec.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ module Concurrent
2727
end
2828

2929
it 'returns nil if no quota is detected' do
30-
if RbConfig::CONFIG["target_os"].match(/linux/i)
30+
if RbConfig::CONFIG["target_os"].include?("linux")
3131
expect(File).to receive(:exist?).twice.and_return(nil) # Checks for cgroups V1 and V2
3232
end
3333
expect(counter.cpu_quota).to be_nil
@@ -72,21 +72,21 @@ module Concurrent
7272

7373
it 'returns #processor_count if #cpu_quota is nil' do
7474
expect(Concurrent::processor_counter).to receive(:cpu_quota).and_return(nil)
75-
available_processor_count = Concurrent::available_processor_count
75+
available_processor_count = Concurrent.available_processor_count
7676
expect(available_processor_count).to be == Concurrent::processor_count
7777
expect(available_processor_count).to be_a Float
7878
end
7979

8080
it 'returns #processor_count if #cpu_quota is higher' do
8181
expect(Concurrent::processor_counter).to receive(:cpu_quota).and_return(Concurrent::processor_count.to_f * 2)
82-
available_processor_count = Concurrent::available_processor_count
82+
available_processor_count = Concurrent.available_processor_count
8383
expect(available_processor_count).to be == Concurrent::processor_count
8484
expect(available_processor_count).to be_a Float
8585
end
8686

8787
it 'returns #cpu_quota if #cpu_quota is lower than #processor_count' do
8888
expect(Concurrent::processor_counter).to receive(:cpu_quota).and_return(Concurrent::processor_count.to_f / 2)
89-
available_processor_count = Concurrent::available_processor_count
89+
available_processor_count = Concurrent.available_processor_count
9090
expect(available_processor_count).to be == Concurrent::processor_count.to_f / 2
9191
expect(available_processor_count).to be_a Float
9292
end

0 commit comments

Comments
 (0)