Feature #10267
closedNumber of processors
Description
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