about summary refs log tree commit diff
diff options
context:
space:
mode:
authorEelco Dolstra <e.dolstra@tudelft.nl>2011-12-21T18·59+0000
committerEelco Dolstra <e.dolstra@tudelft.nl>2011-12-21T18·59+0000
commit69d6f0936a59da5cc35040407f4b667437d61add (patch)
tree359468ac775b4f2851a806f7e00d1838bd5c5650
parent38776198880d06dc6af0fbdfa7cb2c053000112a (diff)
* Use a lock to ensure that only one build-remote instance can copy a
  closure to a given machine at the same time.  This prevents the case
  where multiple instances try to copy the same missing store path to
  the target machine, which is very wasteful.

-rwxr-xr-xscripts/build-remote.pl.in11
1 files changed, 10 insertions, 1 deletions
diff --git a/scripts/build-remote.pl.in b/scripts/build-remote.pl.in
index c805d6740ef3..6a6515756163 100755
--- a/scripts/build-remote.pl.in
+++ b/scripts/build-remote.pl.in
@@ -225,8 +225,17 @@ sub removeRoots {
 }
 
 
-# Copy the derivation and its dependencies to the build machine.
+# Copy the derivation and its dependencies to the build machine.  This
+# is guarded by an exclusive lock per machine to prevent multiple
+# build-remote instances from copying to a machine simultaneously.
+# That's undesirable because we may end up with N instances uploading
+# the same missing path simultaneously, causing the effective network
+# bandwidth and target disk speed to be divided by N.
+my $uploadLock = "$currentLoad/$hostName.upload-lock";
+open MAINLOCK, ">>$uploadLock" or die;
+flock(MAINLOCK, LOCK_EX) or die;
 Nix::CopyClosure::copyTo($hostName, [ @sshOpts ], [ $drvPath, @inputs ], "", "", 0, 0, $maybeSign ne "");
+close MAINLOCK;
 
 
 # Perform the build.