Skip to content

Commit 50186ac

Browse files
Sijaysbaddaden
andauthored
Fix Fiber::ExecutionContext.default_workers_count (#16227)
Co-authored-by: Julien Portalier <[email protected]>
1 parent d29a4d8 commit 50186ac

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

src/fiber/execution_context.cr

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -92,18 +92,16 @@ module Fiber::ExecutionContext
9292
# parallel execution context for example.
9393
#
9494
# Respects the `CRYSTAL_WORKERS` environment variable if present and valid,
95-
# and otherwise defaults to the minimum number of logical CPUs available to
96-
# the process or available on the computer.
95+
# and otherwise defaults to the number of logical CPUs available to the
96+
# process or on the computer.
9797
def self.default_workers_count : Int32
98-
if count = ENV["CRYSTAL_WORKERS"]?.try(&.to_i?)
99-
return count.clamp(1..)
100-
end
101-
102-
total = System.cpu_count.to_i.clamp(1..)
103-
effective = Crystal::System.effective_cpu_count.to_i.clamp(1..)
98+
count = ENV["CRYSTAL_WORKERS"]?.try(&.to_i?) || -1
99+
count = Crystal::System.effective_cpu_count.to_i if count == -1
100+
count = System.cpu_count.to_i if count == -1
104101
# TODO: query for CPU limits (e.g. linux/cgroup, freebsd/rctl, ...)
105102

106-
Math.min(total, effective)
103+
# always report at least 1 worker
104+
count.clamp(1..)
107105
end
108106

109107
# :nodoc:

0 commit comments

Comments
 (0)