From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.2 required=3.0 tests=ALL_TRUSTED,AWL,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id CCFC51F560 for ; Sat, 30 Sep 2023 15:20:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=80x24.org; s=selector1; t=1696087240; bh=pw6PjGJOm0NfQmRjyS6dhRf74/vn6m+7PTPIN1X5YlU=; h=From:To:Subject:Date:In-Reply-To:References:From; b=GJQYGZNEM1WVrs4wfs6q3dm5Wj/OZzhJl25lABStVHXJe1VQKtX/t8mSz9UFCDuqH D+MO4r7S1XI3SWmoVb1UXF6Txfvm+VJ24+JccLflBH2jQZo++mbCiZSmJrb4zL9Dp3 61kWgzfT2rx04prQEbeQS6LLh8Z7INCFY/jG5zo0= From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 1/3] git: decouple cat_async_retry from POSIX pipe semantics Date: Sat, 30 Sep 2023 15:20:38 +0000 Message-ID: <20230930152040.1743107-2-e@80x24.org> In-Reply-To: <20230930152040.1743107-1-e@80x24.org> References: <20230930152040.1743107-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: While pipes guarantee writes of <= 512 bytes to be atomic, Unix stream sockets (or TCP sockets) have no such guarantees. Removing the pipe assumption will make it possible for us to switch to bidirectional Unix stream sockets and save FDs with `git cat-file' processes as we have with Gcf2Client. The performance benefit of larger pipe buffers over stream sockets isn't irrelevant when interacting with git as it is with SearchIdx shards. --- lib/PublicInbox/Git.pm | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/lib/PublicInbox/Git.pm b/lib/PublicInbox/Git.pm index eb88aa48..8ac40d2b 100644 --- a/lib/PublicInbox/Git.pm +++ b/lib/PublicInbox/Git.pm @@ -223,25 +223,21 @@ sub my_readline ($$) { } sub cat_async_retry ($$) { - my ($self, $inflight) = @_; + my ($self, $old_inflight) = @_; # {inflight} may be non-existent, but if it isn't we delete it # here to prevent cleanup() from waiting: delete $self->{inflight}; cleanup($self); + batch_prepare($self, my $new_inflight = []); - batch_prepare($self, $inflight); - my $buf = ''; - for (my $i = 0; $i < @$inflight; $i += 3) { - $buf .= "$inflight->[$i]\n"; + while (my ($oid, $cb, $arg) = splice(@$old_inflight, 0, 3)) { + write_all($self, $self->{out}, $oid."\n", + \&cat_async_step, $new_inflight); + $oid = \$oid if !@$new_inflight; # to indicate oid retried + push @$new_inflight, $oid, $cb, $arg; } - $self->{out}->blocking(1); # brand new pipe, should never block - print { $self->{out} } $buf or $self->fail("write error: $!"); - $self->{out}->blocking(0); - my $req = shift @$inflight; - unshift(@$inflight, \$req); # \$ref to indicate retried - - cat_async_step($self, $inflight); # take one step + cat_async_step($self, $new_inflight); # take one step } # returns true if prefetch is successful