Issue #10267 has been updated by Akira Tanaka.


It seems kosaki-san is busy.

I committed etc-nprocessors-kosaki2.patch at r47939.

----------------------------------------
Feature #10267: Number of processors
https://bugs.ruby-lang.org/issues/10267#change-49458

* Author: Akira Tanaka
* Status: Closed
* Priority: Normal
* Assignee: 
* Category: 
* Target version: 
----------------------------------------
How about a method to obtain number of processors?

Several committers discussed this feature at RubyKaigi 2014.

The number is important to use all available processing power.
Too few processes doesn't use all processors.
Too much processes wastes processing power.

For example, test/lib/test/unit has -j N option for
parallel tests and N is the number of processes to run simultaneously.
But we must specify N explicitly.
I think it should have reasonable default.

I propose a primitive method to obtain number of processors for such purpose:
Etc.nprocessors_online.

It is implemented using sysconf(_SC_NPROCESSORS_ONLN).
It is not standardized but available on many platforms: 
GNU/Linux, NetBSD, FreeBSD, OpenBSD, DragonFly BSD,
OpenIndiana, Mac OS X and AIX.

usa-san said he will implement on Windows (after this feature is implemented).

kosaki-san said he will improve the method for container on GNU/Linux.
(If a process is run in a container, usable number of processors may be restricted.
So sysconf(_SC_NPROCESSORS_ONLN) may be not approprate.)

matz accepted this feature including the method name,
Etc.nprocessors_online.

However kosaki-san said he will try to find better name
(by survey container technology).
So I'm waiting.


---Files--------------------------------
etc-nprocessors.patch (1.91 KB)
etc-nprocessors2.patch (2.31 KB)
etc-nprocessors3.patch (2.29 KB)
etc-nprocessors-kosaki.patch (3.06 KB)
etc-nprocessors-kosaki2.patch (3.68 KB)


-- 
https://bugs.ruby-lang.org/