Codebase list ruby-parallel / f3fd4f7
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
3 changed file(s) with 8 addition(s) and 5 deletion(s). Raw diff Collapse all Expand all
155155 - [Benchmark/Test] Disable threading/forking with `in_threads: 0` or `in_processes: 0`, great to test performance or to debug parallel issues
156156 - [Isolation] Do not reuse previous worker processes: `isolation: true`
157157 - [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.
158159
159160 TODO
160161 ====
00 require 'etc'
11
22 module Parallel
3 # TODO: inline this method into parallel.rb and kill physical_processor_count in next major release
34 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
56 def processor_count
6 @processor_count ||= begin
7 Etc.nprocessors
8 end
7 @processor_count ||= Integer(ENV['PARALLEL_PROCESSOR_COUNT'] || Etc.nprocessors)
98 end
109
1110 # Number of physical processor cores on the current system.
12 #
1311 def physical_processor_count
1412 @physical_processor_count ||= begin
1513 ppc = case RbConfig::CONFIG["target_os"]
7373
7474 it "executes with detected cpus when nil was given" do
7575 `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
7680 end
7781
7882 it "set amount of parallel processes" do