diff options
author | Eric Wong <e@80x24.org> | 2021-01-03 02:06:16 +0000 |
---|---|---|
committer | Eric Wong <e@80x24.org> | 2021-01-03 18:30:32 +0000 |
commit | 02ff5cc7ecfe3e36cdd1898c4747c28d83de0e1a (patch) | |
tree | 2ca6a9f8f2f7c09f1157362d06d896cf49aeeb3a /lib/PublicInbox/SearchIdxShard.pm | |
parent | 71461c67fee940b05309baa8c67bac10c8c51ac6 (diff) | |
download | public-inbox-02ff5cc7ecfe3e36cdd1898c4747c28d83de0e1a.tar.gz |
This fixes a performance regression in multi-process v2 indexing due to the switch to PublicInbox::IPC. While Unix sockets are fewer FDs to manage, pipes allow unprivileged processes to use larger buffers (up to 1M) on out-of-the-box Linux instances. A larger buffer via F_SETPIPE_SZ afforded by pipes was proven valuable during v2 development in 2018 and continues to be valuable when we get significant amounts of one-way traffic from the producer parent to worker children. Compression may be an option for systems without F_SETPIPE_SZ; but it increases CPU usage with no memory bandwidth savings on hosts where larger buffers are available.
Diffstat (limited to 'lib/PublicInbox/SearchIdxShard.pm')
-rw-r--r-- | lib/PublicInbox/SearchIdxShard.pm | 23 |
1 files changed, 10 insertions, 13 deletions
diff --git a/lib/PublicInbox/SearchIdxShard.pm b/lib/PublicInbox/SearchIdxShard.pm index 83cbbb25..0051df93 100644 --- a/lib/PublicInbox/SearchIdxShard.pm +++ b/lib/PublicInbox/SearchIdxShard.pm @@ -21,6 +21,14 @@ sub new { if ($v2w->{parallel}) { local $self->{-v2w_afc} = $v2w; $self->ipc_worker_spawn("shard[$shard]"); + # F_SETPIPE_SZ = 1031 on Linux; increasing the pipe size for + # inputs speeds V2Writable batch imports across 8 cores by + # nearly 20%. Since any of our responses are small, make + # the response pipe as small as possible + if ($^O eq 'linux') { + fcntl($self->{-ipc_req}, 1031, 1048576); + fcntl($self->{-ipc_res}, 1031, 4096); + } } $self; } @@ -36,7 +44,7 @@ sub _worker_done { sub ipc_atfork_child { # called automatically before ipc_worker_loop my ($self) = @_; my $v2w = delete $self->{-v2w_afc} or die 'BUG: {-v2w_afc} missing'; - $v2w->atfork_child; # calls shard_atfork_child on our siblings + $v2w->atfork_child; # calls ipc_sibling_atfork_child on our siblings $v2w->{current_info} = "[$self->{shard}]"; # for $SIG{__WARN__} $self->begin_txn_lazy; # caller must capture this: @@ -49,17 +57,6 @@ sub index_eml { $self->ipc_do('add_message', $eml, $smsg); } -# needed when there's multiple IPC workers and the parent forking -# causes newer siblings to inherit older siblings sockets -sub shard_atfork_child { - my ($self) = @_; - my $pid = delete($self->{-ipc_worker_pid}) or - die "BUG: $$ no -ipc_worker_pid"; - my $s1 = delete($self->{-ipc_sock}) or die "BUG: $$ no -ipc_sock"; - $pid == $$ and die "BUG: $$ shard_atfork_child called on itself"; - close($s1) or die "close -ipc_sock: $!"; -} - # wait for return to determine when ipc_do('commit_txn_lazy') is done sub echo { shift; @@ -80,7 +77,7 @@ sub shard_close { sub shard_over_check { my ($self, $over) = @_; - if ($self->{-ipc_sock} && $over->{dbh}) { + if ($self->{-ipc_req} && $over->{dbh}) { # can't send DB handles over IPC $over = ref($over)->new($over->{dbh}->sqlite_db_filename); } |