Merge pull request #265 from grosser/bpaquet-master
Allow to override the number of processor with PARALLEL_PROCESSOR_COUNT env var
Michael Grosser authored 4 years ago
GitHub committed 4 years ago
155 | 155 |
- [Benchmark/Test] Disable threading/forking with `in_threads: 0` or `in_processes: 0`, great to test performance or to debug parallel issues
|
156 | 156 |
- [Isolation] Do not reuse previous worker processes: `isolation: true`
|
157 | 157 |
- [Stop all processses with an alternate interrupt signal] `'INT'` (from `ctrl+c`) is caught by default. Catch `'TERM'` (from `kill`) with `interrupt_signal: 'TERM'`
|
|
158 |
- [Process count via ENV] `PARALLEL_PROCESSOR_COUNT=16` will use `16` instead of the number of processors detected. This is used to reconfigure a tool using `parallel` without inserting custom logic.
|
158 | 159 |
|
159 | 160 |
TODO
|
160 | 161 |
====
|
0 | 0 |
require 'etc'
|
1 | 1 |
|
2 | 2 |
module Parallel
|
|
3 |
# TODO: inline this method into parallel.rb and kill physical_processor_count in next major release
|
3 | 4 |
module ProcessorCount
|
4 | |
# Number of processors seen by the OS and used for process scheduling. It's just wrapper for Etc.nprocessors
|
|
5 |
# Number of processors seen by the OS, used for process scheduling
|
5 | 6 |
def processor_count
|
6 | |
@processor_count ||= begin
|
7 | |
Etc.nprocessors
|
8 | |
end
|
|
7 |
@processor_count ||= Integer(ENV['PARALLEL_PROCESSOR_COUNT'] || Etc.nprocessors)
|
9 | 8 |
end
|
10 | 9 |
|
11 | 10 |
# Number of physical processor cores on the current system.
|
12 | |
#
|
13 | 11 |
def physical_processor_count
|
14 | 12 |
@physical_processor_count ||= begin
|
15 | 13 |
ppc = case RbConfig::CONFIG["target_os"]
|
73 | 73 |
|
74 | 74 |
it "executes with detected cpus when nil was given" do
|
75 | 75 |
`ruby spec/cases/parallel_with_nil_uses_detected_cpus.rb`.should == "HELLO\n" * cpus
|
|
76 |
end
|
|
77 |
|
|
78 |
it "executes with cpus from ENV" do
|
|
79 |
`PARALLEL_PROCESSOR_COUNT=10 ruby spec/cases/parallel_with_detected_cpus.rb`.should == "HELLO\n" * 10
|
76 | 80 |
end
|
77 | 81 |
|
78 | 82 |
it "set amount of parallel processes" do
|