about summary refs log tree commit homepage
path: root/lib
diff options
context:
space:
mode:
authorEric Wong <e@yhbt.net>2020-08-08 11:24:05 +0000
committerEric Wong <e@yhbt.net>2020-08-09 18:41:42 +0000
commitc538c9593e4c4d8185c3131eab2d14c383fafe8f (patch)
tree7199fcb0f9bc53e1757e2740aacbdd8a953d72b0 /lib
parent5458d831698f79c58adf955dc11753d3b560374d (diff)
downloadpublic-inbox-c538c9593e4c4d8185c3131eab2d14c383fafe8f.tar.gz
getconf(1) itself is POSIX, while `_NPROCESSORS_ONLN' is not.
However, FreeBSD (tested 11.4 and 12.1) and glibc (tested CentOS
7.x and Debian 10.x) both support `getconf _NPROCESSORS_ONLN'.

GNU coreutils (and thus `nproc' or `gnproc') are not installed
by default on the *BSDs, so we'll try the option most likely
to exist on both glibc and *BSDs out-of-the-box.
Diffstat (limited to 'lib')
-rw-r--r--lib/PublicInbox/V2Writable.pm7
1 files changed, 3 insertions, 4 deletions
diff --git a/lib/PublicInbox/V2Writable.pm b/lib/PublicInbox/V2Writable.pm
index f7a318e5..dfcb4897 100644
--- a/lib/PublicInbox/V2Writable.pm
+++ b/lib/PublicInbox/V2Writable.pm
@@ -35,14 +35,13 @@ my $PACKING_FACTOR = 0.4;
 our $NPROC_MAX_DEFAULT = 4;
 
 sub detect_nproc () {
-        for my $nproc (qw(nproc gnproc)) { # GNU coreutils nproc
-                `$nproc 2>/dev/null` =~ /^(\d+)$/ and return $1;
-        }
-
         # getconf(1) is POSIX, but *NPROCESSORS* vars are not
         for (qw(_NPROCESSORS_ONLN NPROCESSORS_ONLN)) {
                 `getconf $_ 2>/dev/null` =~ /^(\d+)$/ and return $1;
         }
+        for my $nproc (qw(nproc gnproc)) { # GNU coreutils nproc
+                `$nproc 2>/dev/null` =~ /^(\d+)$/ and return $1;
+        }
 
         # should we bother with `sysctl hw.ncpu`?  Those only give
         # us total processor count, not online processor count.