From: akr@... Date: 2014-10-02T03:23:37+00:00 Subject: [ruby-core:65359] [ruby-trunk - Feature #10267] [Closed] Number of processors Issue #10267 has been updated by Akira Tanaka. Status changed from Open to Closed % Done changed from 0 to 100 Applied in changeset r47761. ---------- * ext/etc/etc.c (etc_nprocessors): New method. Accepted by matz at RubyKaigi 2014. [ruby-core:65142] [Feature #10267] ---------------------------------------- Feature #10267: Number of processors https://bugs.ruby-lang.org/issues/10267#change-49165 * 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/