about summary refs log tree commit homepage
path: root/lib/PublicInbox/V2Writable.pm
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2021-02-02 11:47:02 +0000
committerEric Wong <e@80x24.org>2021-02-03 07:32:45 +0000
commitcff308df82cda8370e98c0c9c6a3704209362a60 (patch)
tree4632b2a438f2fca6369f079064d771f7497fa5f3 /lib/PublicInbox/V2Writable.pm
parent9ff9755999351a582c857c38e2996b3ab7eb7481 (diff)
downloadpublic-inbox-cff308df82cda8370e98c0c9c6a3704209362a60.tar.gz
This comma-delimited parameter allows controlling the number or
lei_xsearch and lei2mail worker processes.  With the change
to make IPC wq_* work use the event loop, it's now safe to
run fewer worker processes for searching with no risk of
deadlocks.

MAX_PER_HOST isn't configurable yet for remote hosts,
and maybe it shouldn't be due to potential for abuse.
Diffstat (limited to 'lib/PublicInbox/V2Writable.pm')
-rw-r--r--lib/PublicInbox/V2Writable.pm22
1 files changed, 2 insertions, 20 deletions
diff --git a/lib/PublicInbox/V2Writable.pm b/lib/PublicInbox/V2Writable.pm
index 35b7fe30..cbd4f003 100644
--- a/lib/PublicInbox/V2Writable.pm
+++ b/lib/PublicInbox/V2Writable.pm
@@ -8,6 +8,7 @@ use strict;
 use v5.10.1;
 use parent qw(PublicInbox::Lock);
 use PublicInbox::SearchIdxShard;
+use PublicInbox::IPC;
 use PublicInbox::Eml;
 use PublicInbox::Git;
 use PublicInbox::Import;
@@ -35,32 +36,13 @@ our $PACKING_FACTOR = 0.4;
 # to increase Xapian shards
 our $NPROC_MAX_DEFAULT = 4;
 
-sub detect_nproc () {
-        # _SC_NPROCESSORS_ONLN = 84 on both Linux glibc and musl
-        return POSIX::sysconf(84) if $^O eq 'linux';
-        return POSIX::sysconf(58) if $^O eq 'freebsd';
-        # TODO: more OSes
-
-        # 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.
-        undef
-}
-
 sub nproc_shards ($) {
         my ($creat_opt) = @_;
         my $n = $creat_opt->{nproc} if ref($creat_opt) eq 'HASH';
         $n //= $ENV{NPROC};
         if (!$n) {
                 # assume 2 cores if not detectable or zero
-                state $NPROC_DETECTED = detect_nproc() || 2;
+                state $NPROC_DETECTED = PublicInbox::IPC::detect_nproc() || 2;
                 $n = $NPROC_DETECTED;
                 $n = $NPROC_MAX_DEFAULT if $n > $NPROC_MAX_DEFAULT;
         }