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 D8A881F44D for ; Wed, 17 Apr 2024 09:41:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=80x24.org; s=selector1; t=1713346869; bh=D4nVAjqatSd3TRJHRgK9/YgA78Y2qEV40C9a9oDVQwI=; h=Date:From:To:Subject:References:In-Reply-To:From; b=rK4fSfsSE87ubh+NkrfH2ReJjg85GDYT7rEwh9NK9WYHD+ne+t0PHjwyaKpCgJsI+ fLC5zD2MYtG23pRZ1az4bJjgZFekZ+sn2RQ0n8majpq7cA6JikHe8LSSf/OBGdzZWM 63A33dkETLgqWtGav6ByKk8p5OP26N4bFn9Px1g0= Date: Wed, 17 Apr 2024 09:34:01 +0000 From: Eric Wong To: meta@public-inbox.org Subject: [PATCH v2 3/4] lei/store: stop shard workers + cat-file on idle Message-ID: <20240417093401.M319057@dcvr> References: <20240416205629.3648894-1-e@80x24.org> <20240416205629.3648894-4-e@80x24.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20240416205629.3648894-4-e@80x24.org> List-Id: Schedule a timer to stop shard workers and the git-cat-file process after a `barrier' command. This allows us to save some memory again when the lei-daemon is idle but preserves the fork overhead reduction when issuing many commands in parallel or in quick succession. --- v2 fixes an incorrect call to add_uniq_timer. Sometimes I wish Perl could have more static type||arg checking, but it's probably still better than other scripting languages... Interdiff against v1: diff --git a/lib/PublicInbox/LeiStore.pm b/lib/PublicInbox/LeiStore.pm index a054f649..b2da2bc3 100644 --- a/lib/PublicInbox/LeiStore.pm +++ b/lib/PublicInbox/LeiStore.pm @@ -574,7 +574,7 @@ sub set_xvmd { sub check_done { my ($self) = @_; $self->git->_active ? - add_uniq_timer("$self-check_done", \&check_done, $self) : + add_uniq_timer("$self-check_done", 5, \&check_done, $self) : done($self); } lib/PublicInbox/LeiStore.pm | 46 ++++++++++++++++++------------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/lib/PublicInbox/LeiStore.pm b/lib/PublicInbox/LeiStore.pm index 162c915f..b2da2bc3 100644 --- a/lib/PublicInbox/LeiStore.pm +++ b/lib/PublicInbox/LeiStore.pm @@ -571,21 +571,11 @@ sub set_xvmd { sto_export_kw($self, $smsg->{num}, $vmd); } -sub barrier { +sub check_done { my ($self) = @_; - my ($errfh, $lei_sock) = @$self{0, 1}; # via sto_barrier_request - my @err; - if ($self->{im}) { - eval { $self->{im}->barrier }; - push(@err, "E: import barrier: $@\n") if $@; - } - delete $self->{lms}; - eval { $self->{priv_eidx}->barrier }; - push(@err, "E: priv_eidx barrier: $@\n") if $@; - print { $errfh // \*STDERR } @err; - send($lei_sock, 'child_error 256', 0) if @err && $lei_sock; - xchg_stderr($self); - die @err if @err; + $self->git->_active ? + add_uniq_timer("$self-check_done", 5, \&check_done, $self) : + done($self); } sub xchg_stderr { @@ -602,23 +592,33 @@ sub xchg_stderr { undef; } -sub done { - my ($self) = @_; - my ($errfh, $lei_sock) = @$self{0, 1}; +sub _commit ($$) { + my ($self, $cmd) = @_; # cmd is 'done' or 'barrier' + my ($errfh, $lei_sock) = @$self{0, 1}; # via sto_barrier_request my @err; - if (my $im = delete($self->{im})) { - eval { $im->done }; - push(@err, "E: import done: $@\n") if $@; + if ($self->{im}) { + eval { $self->{im}->$cmd }; + push(@err, "E: import $cmd: $@\n") if $@; } delete $self->{lms}; - eval { $self->{priv_eidx}->done }; # V2Writable::done - push(@err, "E: priv_eidx done: $@\n") if $@; - print { $errfh // *STDERR{GLOB} } @err; + eval { $self->{priv_eidx}->$cmd }; + push(@err, "E: priv_eidx $cmd: $@\n") if $@; + print { $errfh // \*STDERR } @err; send($lei_sock, 'child_error 256', 0) if @err && $lei_sock; xchg_stderr($self); die @err if @err; + # $lei_sock goes out-of-scope and script/lei can terminate +} + +sub barrier { + my ($self) = @_; + _commit $self, 'barrier'; + add_uniq_timer("$self-check_done", 5, \&check_done, $self); + undef; } +sub done { _commit $_[0], 'done' } + sub ipc_atfork_child { my ($self) = @_; my $lei = $self->{lei};