unofficial mirror of meta@public-inbox.org
 help / color / mirror / Atom feed
From: Eric Wong <e@yhbt.net>
To: meta@public-inbox.org
Subject: [PATCH 3/6] xapcmd: reduce CPU idling when shards exceeds job count
Date: Wed, 12 Aug 2020 09:17:16 +0000	[thread overview]
Message-ID: <20200812091719.13739-4-e@yhbt.net> (raw)
In-Reply-To: <20200812091719.13739-1-e@yhbt.net>

In case there's unbalanced shards AND we're limiting parallelism
while using many shards, spawn the next task in the queue ASAP
once a task is done, instead of waiting for all tasks to finish
before spawning the next batch.

Unbalanced shards probably isn't a big issue for most users;
however many smaller shards with few jobs can be useful for HDD
users to reduce the effect of random writes.
---
 lib/PublicInbox/Xapcmd.pm | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/lib/PublicInbox/Xapcmd.pm b/lib/PublicInbox/Xapcmd.pm
index 6fcc9e90c..b6279218c 100644
--- a/lib/PublicInbox/Xapcmd.pm
+++ b/lib/PublicInbox/Xapcmd.pm
@@ -9,7 +9,7 @@ use PublicInbox::SearchIdx;
 use File::Temp 0.19 (); # ->newdir
 use File::Path qw(remove_tree);
 use File::Basename qw(dirname);
-use POSIX ();
+use POSIX qw(WNOHANG);
 
 # support testing with dev versions of Xapian which installs
 # commands with a version number suffix (e.g. "xapian-compact-1.5")
@@ -151,14 +151,17 @@ sub process_queue {
 			$pids{cb_spawn($cb, $args, $opt)} = $args;
 		}
 
+		my $flags = 0;
 		while (scalar keys %pids) {
-			my $pid = waitpid(-1, 0);
+			my $pid = waitpid(-1, $flags) or last;
+			last if $pid < 0;
 			my $args = delete $pids{$pid};
 			if ($args) {
 				die join(' ', @$args)." failed: $?\n" if $?;
 			} else {
 				warn "unknown PID($pid) reaped: $?\n";
 			}
+			$flags = WNOHANG if scalar(@$queue);
 		}
 	}
 }

  parent reply	other threads:[~2020-08-12  9:17 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-08-12  9:17 [PATCH 0/6] xcpdb -index improvements Eric Wong
2020-08-12  9:17 ` [PATCH 1/6] xapcmd: simplify sub reference Eric Wong
2020-08-12  9:17 ` [PATCH 2/6] xcpdb: support --no-fsync from CLI Eric Wong
2020-08-12  9:17 ` Eric Wong [this message]
2020-08-12  9:17 ` [PATCH 4/6] admin: don't warn when --jobs exceeds shards Eric Wong
2020-08-12  9:17 ` [PATCH 5/6] xcpdb: wire up new index options and --help Eric Wong
2020-08-12  9:17 ` [PATCH 6/6] v2writable: remove IdxStack import Eric Wong

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://public-inbox.org/README

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200812091719.13739-4-e@yhbt.net \
    --to=e@yhbt.net \
    --cc=meta@public-inbox.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).