user/dev discussion of public-inbox itself
 help / color / mirror / Atom feed
* [PATCH] favor `getconf _NPROCESSORS_ONLN` over GNU nproc
@ 2020-08-08 11:24 Eric Wong
  0 siblings, 0 replies; only message in thread
From: Eric Wong @ 2020-08-08 11:24 UTC (permalink / raw)
  To: meta

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.
---
 Makefile.PL                   | 6 ++++--
 lib/PublicInbox/V2Writable.pm | 7 +++----
 2 files changed, 7 insertions(+), 6 deletions(-)

diff --git a/Makefile.PL b/Makefile.PL
index 8d90ad46..831649f9 100644
--- a/Makefile.PL
+++ b/Makefile.PL
@@ -156,12 +156,14 @@ WriteMakefile(
 );
 
 sub MY::postamble {
-  <<EOF;
+	my $N = (`{ getconf _NPROCESSORS_ONLN || nproc; } 2>/dev/null` || 1);
+	$N += 1; # account for sleeps in some tests (and makes an IV)
+	<<EOF;
 PROVE = prove
 # support using eatmydata to speed up tests (apt-get install eatmydata):
 # https://www.flamingspork.com/projects/libeatmydata/
 EATMYDATA =
-N = \$\$(( \$\$(nproc 2>/dev/null || gnproc 2>/dev/null || echo 2) + 1 ))
+N = $N
 -include config.mak
 $VARS
 -include Documentation/include.mk
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.

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2020-08-08 11:24 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-08 11:24 [PATCH] favor `getconf _NPROCESSORS_ONLN` over GNU nproc Eric Wong

user/dev discussion of public-inbox itself

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://public-inbox.org/meta
	git clone --mirror http://czquwvybam4bgbro.onion/meta
	git clone --mirror http://hjrcffqmbrq6wope.onion/meta
	git clone --mirror http://ou63pmih66umazou.onion/meta

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V1 meta meta/ https://public-inbox.org/meta \
		meta@public-inbox.org
	public-inbox-index meta

Example config snippet for mirrors.
Newsgroups are available over NNTP:
	nntp://news.public-inbox.org/inbox.comp.mail.public-inbox.meta
	nntp://ou63pmih66umazou.onion/inbox.comp.mail.public-inbox.meta
	nntp://czquwvybam4bgbro.onion/inbox.comp.mail.public-inbox.meta
	nntp://hjrcffqmbrq6wope.onion/inbox.comp.mail.public-inbox.meta
	nntp://news.gmane.io/gmane.mail.public-inbox.general
 note: .onion URLs require Tor: https://www.torproject.org/

code repositories for the project(s) associated with this inbox:

	https://80x24.org/public-inbox.git

AGPL code for this site: git clone https://public-inbox.org/public-inbox.git