about summary refs log tree commit homepage
path: root/lib/PublicInbox
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2024-04-16 20:56:28 +0000
committerEric Wong <e@80x24.org>2024-04-17 09:27:43 +0000
commit4ff8e8d21ab55fdb8d94f8b6fd58aaafd03d8dca (patch)
tree77fc9e42a919b8f2972999d7bb80f211f1203631 /lib/PublicInbox
parentcad60b2aa5fee563f2a6b41fa0cc7267e13e4bde (diff)
downloadpublic-inbox-4ff8e8d21ab55fdb8d94f8b6fd58aaafd03d8dca.tar.gz
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.
Diffstat (limited to 'lib/PublicInbox')
-rw-r--r--lib/PublicInbox/LeiStore.pm46
1 files 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};