* Load balancing. `build-remote.pl' will only execute up to a

per-machine maximum number of parallel jobs on a remote machine.
This commit is contained in:
Eelco Dolstra 2004-05-13 19:35:46 +00:00
parent 3426d19547
commit 25db622454
4 changed files with 34 additions and 11 deletions

View file

@ -7,9 +7,16 @@ my $localSystem = shift @ARGV;
my $neededSystem = shift @ARGV; my $neededSystem = shift @ARGV;
my $storeExpr = shift @ARGV; my $storeExpr = shift @ARGV;
sub sendReply {
my $reply = shift;
open OUT, ">&3" or die;
print OUT "$reply\n";
close OUT;
}
# Decline if the local system can do the build. # Decline if the local system can do the build.
if ($amWilling && ($localSystem eq $neededSystem)) { if ($amWilling && ($localSystem eq $neededSystem)) {
print "decline\n"; sendReply "decline";
exit 0; exit 0;
} }
@ -45,11 +52,8 @@ while (<LOAD>) {
} }
close LOAD; close LOAD;
sub sendReply { foreach my $cur (keys %machines) {
my $reply = shift; $curJobs{$cur} = 0 unless defined $curJobs{$cur};
open OUT, ">&3" or die;
print OUT "$reply\n";
close OUT;
} }
# Find a suitable system. # Find a suitable system.
@ -58,8 +62,7 @@ my $machine;
foreach my $cur (keys %machines) { foreach my $cur (keys %machines) {
if ($neededSystem eq $systemTypes{$cur}) { if ($neededSystem eq $systemTypes{$cur}) {
$rightType = 1; $rightType = 1;
if (!defined $curJobs{$cur} or if ($curJobs{$cur} < $maxJobs{$cur})
($curJobs{$cur} < $maxJobs{$cur}))
{ {
$machine = $cur; $machine = $cur;
last; last;
@ -86,6 +89,19 @@ close IN;
print "BUILDING REMOTE: $storeExpr on $machine\n"; print "BUILDING REMOTE: $storeExpr on $machine\n";
$curJobs{$machine} = $curJobs{$machine} + 1;
sub writeLoad {
open LOAD, "> /home/eelco/nix/distributed/current-load" or die;
foreach my $cur (keys %machines) {
print LOAD "$cur $curJobs{$cur}\n";
}
close LOAD;
}
writeLoad
my $ssh = "ssh -i $sshKeys{$machine} -x"; my $ssh = "ssh -i $sshKeys{$machine} -x";
my $inputs = `cat inputs`; my $inputs = `cat inputs`;
@ -117,3 +133,7 @@ foreach my $output (split '\n', $outputs) {
system "rsync -a -e '$ssh' $machine:$output /nix/store"; system "rsync -a -e '$ssh' $machine:$output /nix/store";
die "cannot rsync outputs from $machine" if ($? != 0); die "cannot rsync outputs from $machine" if ($? != 0);
} }
$curJobs{$machine} = $curJobs{$machine} - 1;
writeLoad

View file

@ -1,2 +1,2 @@
scratchy.labs.cs.uu.nl i686-linux /home/eelco/.ssh/id_scratchy_auto 2 scratchy.labs.cs.uu.nl i686-linux /home/eelco/.ssh/id_scratchy_auto 1
mckroket.labs.cs.uu.nl powerpc-mac /home/eelco/.ssh/id_scratchy_mckroket 1 mckroket.labs.cs.uu.nl powerpc-mac /home/eelco/.ssh/id_scratchy_mckroket 1

View file

@ -2,8 +2,11 @@
set -e set -e
rm -f current-load
touch current-load
storeExpr=$(nix-instantiate ~/nixpkgs/pkgs/system/test.nix) storeExpr=$(nix-instantiate ~/nixpkgs/pkgs/system/test.nix)
export NIX_BUILD_HOOK="build-remote.pl" export NIX_BUILD_HOOK="build-remote.pl"
../src/nix-store/nix-store -qnvvvv -j0 $storeExpr ../src/nix-store/nix-store -qnvvvv -j1 $storeExpr

View file

@ -332,7 +332,7 @@ void Normaliser::run()
while (!goals.empty()) { while (!goals.empty()) {
printMsg(lvlVomit, "main loop"); debug("main loop - starting jobs");
/* Start building as many buildable goals as possible. */ /* Start building as many buildable goals as possible. */
bool madeProgress = false; bool madeProgress = false;