From 69d6f0936a59da5cc35040407f4b667437d61add Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Wed, 21 Dec 2011 18:59:25 +0000 Subject: [PATCH] * 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. --- scripts/build-remote.pl.in | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/scripts/build-remote.pl.in b/scripts/build-remote.pl.in index c805d6740e..6a65157561 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.