about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2019-01-19 04:57:08 +0000
committerEric Wong <e@80x24.org>2019-01-20 04:24:54 +0000
commit7fa037d0be9d1a8b891084a3c1215a1af5aa886b (patch)
tree47a3e03bac62b347c7fe8fe8fa5466abeef7bff5
parent20efb4bd22d93cef9e2bd72740a1fe73f6e19957 (diff)
downloadpublic-inbox-7fa037d0be9d1a8b891084a3c1215a1af5aa886b.tar.gz
We want more fine-grained scheduling for PSGI use, as
the patch application step can take hundreds of milliseconds
on my modest hardware
-rw-r--r--lib/PublicInbox/SolverGit.pm22
1 files changed, 16 insertions, 6 deletions
diff --git a/lib/PublicInbox/SolverGit.pm b/lib/PublicInbox/SolverGit.pm
index 29cfd218..71494e07 100644
--- a/lib/PublicInbox/SolverGit.pm
+++ b/lib/PublicInbox/SolverGit.pm
@@ -236,8 +236,8 @@ sub prepare_index ($$$$) {
                 "$mode_a $oid_full\t", git_quote($path_a), "\n";
 }
 
-sub do_apply ($$$$) {
-        my ($out, $wt_git, $wt_dir, $di) = @_;
+sub do_apply_begin ($$$) {
+        my ($out, $wt_dir, $di) = @_;
 
         my $tmp = delete $di->{tmp} or die "BUG: no tmp ", di_url($di);
         $tmp->flush or die "tmp->flush failed: $!";
@@ -248,11 +248,19 @@ sub do_apply ($$$$) {
         my $rdr = { 0 => fileno($tmp), 1 => $err_fd, 2 => $err_fd };
         my $cmd = [ qw(git -C), $wt_dir,
                     qw(apply --cached --whitespace=warn --verbose) ];
-        reap(spawn($cmd, undef, $rdr), 'apply');
+        spawn($cmd, undef, $rdr);
+}
 
-        local $/ = "\0";
-        my $rd = popen_rd([qw(git -C), $wt_dir, qw(ls-files -s -z)]);
+sub do_apply_continue ($$) {
+        my ($wt_dir, $apply_pid) = @_;
+        reap($apply_pid, 'apply');
+        popen_rd([qw(git -C), $wt_dir, qw(ls-files -s -z)]);
+}
 
+sub do_apply_end ($$$$) {
+        my ($out, $wt_git, $rd, $di) = @_;
+
+        local $/ = "\0";
         defined(my $line = <$rd>) or die "failed to read ls-files: $!";
         chomp $line or die "no trailing \\0 in [$line] from ls-files";
 
@@ -314,7 +322,9 @@ sub apply_patches ($$$$$) {
                         or die "print \$out failed: $!";
 
                 # apply the patch!
-                $found->{$di->{oid_b}} = do_apply($out, $wt_git, $wt_dir, $di);
+                my $apply_pid = do_apply_begin($out, $wt_dir, $di);
+                my $rd = do_apply_continue($wt_dir, $apply_pid);
+                $found->{$di->{oid_b}} = do_apply_end($out, $wt_git, $rd, $di);
         }
 }