diff options
author | Eric Wong <e@80x24.org> | 2022-07-19 22:42:52 +0000 |
---|---|---|
committer | Eric Wong <e@80x24.org> | 2022-07-20 03:54:27 +0000 |
commit | 49684178901a3d5db198032da1bb831b2b3e0b65 (patch) | |
tree | 7c19828248f589d06cb34fbfb69cee129c4e1366 /lib/PublicInbox/IPC.pm | |
parent | 840785917bc74c8e7df226463144185294047d75 (diff) | |
download | public-inbox-49684178901a3d5db198032da1bb831b2b3e0b65.tar.gz |
Enqueuing "note-event" requests from the DS event loop must not wait on workers being able to drain the queue quickly enough. Thus we make the SOCK_SEQPACKET writes nonblocking and rely on the lei-daemon event loop to enqueue writes. This is a unique problem for "note-event" since it reuses workers in between commands, while most lei commands currently fork off new workers.
Diffstat (limited to 'lib/PublicInbox/IPC.pm')
-rw-r--r-- | lib/PublicInbox/IPC.pm | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/lib/PublicInbox/IPC.pm b/lib/PublicInbox/IPC.pm index 67e86a43..74862673 100644 --- a/lib/PublicInbox/IPC.pm +++ b/lib/PublicInbox/IPC.pm @@ -1,4 +1,4 @@ -# Copyright (C) 2020-2021 all contributors <meta@public-inbox.org> +# Copyright (C) all contributors <meta@public-inbox.org> # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt> # base class for remote IPC calls and workqueues, requires Storable or Sereal @@ -43,7 +43,7 @@ if ($enc && $dec) { # should be custom ops } my $recv_cmd = PublicInbox::Spawn->can('recv_cmd4'); -my $send_cmd = PublicInbox::Spawn->can('send_cmd4') // do { +our $send_cmd = PublicInbox::Spawn->can('send_cmd4') // do { require PublicInbox::CmdIPC4; $recv_cmd //= PublicInbox::CmdIPC4->can('recv_cmd4'); PublicInbox::CmdIPC4->can('send_cmd4'); @@ -348,6 +348,24 @@ sub wq_do { } } +sub prepare_nonblock { + ($_[0]->{-wq_s1} // die 'BUG: no {-wq_s1}')->blocking(0); + $_[0]->{-reap_async} or die 'BUG: {-reap_async} needed for nonblock'; + require PublicInbox::WQBlocked; +} + +sub wq_nonblock_do { # always async + my ($self, $sub, @args) = @_; + my $buf = ipc_freeze([$sub, @args]); + if ($self->{wqb}) { # saturated once, assume saturated forever + $self->{wqb}->flush_send($buf); + } else { + $send_cmd->($self->{-wq_s1}, [], $buf, MSG_EOR) // + ($!{EAGAIN} ? PublicInbox::WQBlocked->new($self, $buf) + : croak("sendmsg: $!")); + } +} + sub _wq_worker_start ($$$$) { my ($self, $oldset, $fields, $one) = @_; my ($bcast1, $bcast2); @@ -405,6 +423,10 @@ sub wq_workers_start { sub wq_close { my ($self) = @_; + if (my $wqb = delete $self->{wqb}) { + $self->{-reap_async} or die 'BUG: {-reap_async} unset'; + $wqb->enq_close; + } delete @$self{qw(-wq_s1 -wq_s2)} or return; return if $self->{-reap_async}; my @pids = keys %{$self->{-wq_workers}}; |