diff options
author | Eric Wong <e@80x24.org> | 2021-01-03 20:58:29 +0000 |
---|---|---|
committer | Eric Wong <e@80x24.org> | 2021-01-04 04:02:54 +0000 |
commit | 7c73a09c6df674e389fb20fb57f63c6bb9695d31 (patch) | |
tree | ea0fa44e55b063b58aa98bccac9bca6662d7e80e /script | |
parent | ddb34f3e901c2e93e9b02dbac31961225b33379f (diff) | |
download | public-inbox-7c73a09c6df674e389fb20fb57f63c6bb9695d31.tar.gz |
While our recv_3fds() implementation is more efficient syscall-wise, loading Inline takes nearly 50ms on my machine even after Inline::C memoizes the build. The current ~20ms in the fast path is barely acceptable to me, and 50ms would be unusable. Eventually, script/lei may invoke tcc(1) or cc(1) directly in the fast path, but it needs @INC for the slow path, at least. We'll encode the number of FDs into the socket name allow parallel installations, for now.
Diffstat (limited to 'script')
-rwxr-xr-x | script/lei | 18 |
1 files changed, 12 insertions, 6 deletions
@@ -4,11 +4,17 @@ use strict; use v5.10.1; use Socket qw(AF_UNIX SOCK_STREAM pack_sockaddr_un); -my $send_3fds; +my ($send_3fds, $nfd); if (my ($sock, $pwd) = eval { - require PublicInbox::Spawn; - $send_3fds = PublicInbox::Spawn->can('send_3fds') or die - "Inline::C not installed/configured or IO::FDPass missing\n"; + $send_3fds = eval { + require IO::FDPass; + $nfd = 1; # 1 FD per-sendmsg + sub { IO::FDPass::send($_[0], $_[$_]) for (1..3) } + } // do { + require PublicInbox::Spawn; # takes ~50ms even if built *sigh* + $nfd = 3; # 3 FDs per-sendmsg(2) + PublicInbox::Spawn->can('send_3fds'); + } // die "IO::FDPass missing or Inline::C not installed/configured\n"; my $path = do { my $runtime_dir = ($ENV{XDG_RUNTIME_DIR} // '') . '/lei'; if ($runtime_dir eq '/lei') { @@ -19,7 +25,7 @@ if (my ($sock, $pwd) = eval { require File::Path; File::Path::mkpath($runtime_dir, 0, 0700); } - "$runtime_dir/sock"; + "$runtime_dir/$nfd.sock"; }; my $addr = pack_sockaddr_un($path); socket(my $sock, AF_UNIX, SOCK_STREAM, 0) or die "socket: $!"; @@ -27,7 +33,7 @@ if (my ($sock, $pwd) = eval { local $ENV{PERL5LIB} = join(':', @INC); open(my $daemon, '-|', $^X, qw[-MPublicInbox::LEI -E PublicInbox::LEI::lazy_start(@ARGV)], - $path, $! + 0) or die "popen: $!"; + $path, $! + 0, $nfd) or die "popen: $!"; while (<$daemon>) { warn $_ } # EOF when STDERR is redirected close($daemon) or warn <<""; lei-daemon could not start, exited with \$?=$? |