From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Cc: Eric Wong <e@yhbt.net>
Subject: [PATCH 01/11] watch: limit batch size of NNTP and IMAP workers, too
Date: Mon, 31 Aug 2020 04:41:30 +0000 [thread overview]
Message-ID: <20200831044140.17027-2-e@80x24.org> (raw)
In-Reply-To: <20200831044140.17027-1-e@80x24.org>
From: Eric Wong <e@yhbt.net>
We don't want to monopolize locks because processes can easily
block each other if using `watchspam' on a Maildir while a big
NNTP or IMAP import is happening.
This can also happen if somebody configured a single inbox to
watch from several sources to merge several mailboxes into one
(e.g. both an IMAP and Maildir are watched).
---
lib/PublicInbox/WatchMaildir.pm | 18 +++++++++++++++---
1 file changed, 15 insertions(+), 3 deletions(-)
diff --git a/lib/PublicInbox/WatchMaildir.pm b/lib/PublicInbox/WatchMaildir.pm
index a227a6fd..5176ef69 100644
--- a/lib/PublicInbox/WatchMaildir.pm
+++ b/lib/PublicInbox/WatchMaildir.pm
@@ -108,6 +108,7 @@ sub new {
return unless $mdre || scalar(keys %imap) || scalar(keys %nntp);
bless {
+ max_batch => 10, # avoid hogging locks for too long
spamcheck => $spamcheck,
mdmap => \%mdmap,
mdre => $mdre,
@@ -472,8 +473,14 @@ sub imap_fetch_all ($$$) {
$l_uid = $uids->[-1] + 1; # for next search
my $last_uid;
+ my $n = $self->{max_batch};
while (scalar @$uids) {
+ if (--$n < 0) {
+ _done_for_now($self);
+ $itrk->update_last($r_uidval, $last_uid);
+ $n = $self->{max_batch};
+ }
my @batch = splice(@$uids, 0, $bs);
$batch = join(',', @batch);
local $0 = "UID:$batch $mbx $sec";
@@ -888,9 +895,15 @@ sub nntp_fetch_all ($$$) {
};
my $inboxes = $self->{nntp}->{$url};
my $last_art;
+ my $n = $self->{max_batch};
for ($beg..$end) {
last if $self->{quit};
$art = $_;
+ if (--$n < 0) {
+ _done_for_now($self);
+ $itrk->update_last(0, $last_art);
+ $n = $self->{max_batch};
+ }
my $raw = $nn->article($art);
unless (defined($raw)) {
my $msg = $nn->message;
@@ -976,12 +989,11 @@ sub fs_scan_step {
local $PublicInbox::DS::in_loop = 0; # waitpid() synchronously
# continue existing scan
- my $max = 10;
my $opendirs = $self->{opendirs};
my @dirnames = keys %$opendirs;
foreach my $dir (@dirnames) {
my $dh = delete $opendirs->{$dir};
- my $n = $max;
+ my $n = $self->{max_batch};
while (my $fn = readdir($dh)) {
_try_path($self, "$dir/$fn");
last if --$n < 0;
@@ -996,7 +1008,7 @@ sub fs_scan_step {
warn "failed to open $dir: $!\n";
next;
}
- my $n = $max;
+ my $n = $self->{max_batch};
while (my $fn = readdir($dh)) {
_try_path($self, "$dir/$fn");
last if --$n < 0;
next prev parent reply other threads:[~2020-08-31 4:41 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-08-31 4:41 [PATCH 00/11] watch: fix contention w/ Maildir & NNTP Eric Wong
2020-08-31 4:41 ` Eric Wong [this message]
2020-08-31 4:41 ` [PATCH 02/11] watchmaildir: use v5.10.1, drop warnings Eric Wong
2020-08-31 4:41 ` [PATCH 03/11] rename WatchMaildir => Watch Eric Wong
2020-08-31 4:41 ` [PATCH 04/11] watch: log signal activities to STDERR Eric Wong
2020-08-31 4:41 ` [PATCH 05/11] watch: avoid unnecessary spawning on spam removals Eric Wong
2020-08-31 4:41 ` [PATCH 06/11] watch: block signals before fork on non-signalfd/kevent systems Eric Wong
2020-08-31 4:41 ` [PATCH 07/11] watch: comments and tiny cleanups Eric Wong
2020-08-31 4:41 ` [PATCH 08/11] ds: avoid excessive queueing when reaping PIDs Eric Wong
2020-08-31 4:41 ` [PATCH 09/11] watch: use EOFpipe to reduce dwaitpid wakeups Eric Wong
2020-08-31 4:41 ` [PATCH 10/11] ds: avoid unnecessary timer for waitpid Eric Wong
2020-08-31 4:41 ` [PATCH 11/11] replace ParentPipe with EOFpipe 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=20200831044140.17027-2-e@80x24.org \
--to=e@80x24.org \
--cc=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.
Code repositories for project(s) associated with this public inbox
https://80x24.org/public-inbox.git
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).