about summary refs log tree commit homepage
path: root/lib
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2022-08-08 23:16:45 +0000
committerEric Wong <e@80x24.org>2022-08-09 16:41:47 +0000
commitc7ce8b45ccfa25953a877e148cec4a103b2dda9b (patch)
treecced7a3948d0d40dd82b2800b7da1837bdd4b3a4 /lib
parentd1024533712e32fde9c9812e604661ffc9e79019 (diff)
downloadpublic-inbox-c7ce8b45ccfa25953a877e148cec4a103b2dda9b.tar.gz
This improves fairness while having no measurable performance
impact for a single uncached IMAP client (mutt) opening a folder
for the first time.

I noticed this problem with the public-inbox.org IMAP server where
a few IMAP clients were unfairly monopolizing the -netd process.
Diffstat (limited to 'lib')
-rw-r--r--lib/PublicInbox/GitAsyncCat.pm9
1 files changed, 4 insertions, 5 deletions
diff --git a/lib/PublicInbox/GitAsyncCat.pm b/lib/PublicInbox/GitAsyncCat.pm
index cea3f539..6b7425f6 100644
--- a/lib/PublicInbox/GitAsyncCat.pm
+++ b/lib/PublicInbox/GitAsyncCat.pm
@@ -69,19 +69,18 @@ sub ibx_async_cat ($$$$) {
 }
 
 # this is safe to call inside $cb, but not guaranteed to enqueue
-# returns true if successful, undef if not.
+# returns true if successful, undef if not.  For fairness, we only
+# prefetch if there's no in-flight requests.
 sub ibx_async_prefetch {
         my ($ibx, $oid, $cb, $arg) = @_;
         my $git = $ibx->git;
         if (!defined($ibx->{topdir}) && $GCF2C) {
-                if (!$GCF2C->{wbuf}) {
+                if (!@{$GCF2C->{inflight} // []}) {
                         $oid .= " $git->{git_dir}\n";
                         return $GCF2C->gcf2_async(\$oid, $cb, $arg); # true
                 }
         } elsif ($git->{async_cat} && (my $inflight = $git->{inflight})) {
-                # we could use MAX_INFLIGHT here w/o the halving,
-                # but lets not allow one client to monopolize a git process
-                if (@$inflight < int(PublicInbox::Git::MAX_INFLIGHT/2)) {
+                if (!@$inflight) {
                         print { $git->{out} } $oid, "\n" or
                                                 $git->fail("write error: $!");
                         return push(@$inflight, $oid, $cb, $arg);