Revision df716c98d203ab64cdf05f9c17fdae565b7daa1c authored by Eelco Dolstra on 23 June 2012, 04:28:35 UTC, committed by Eelco Dolstra on 23 June 2012, 04:28:35 UTC
On Linux it's possible to run a process in its own network namespace, meaning that it gets its own set of network interfaces, disjunct from the rest of the system. We use this to completely remove network access to chroot builds, except that they get a private loopback interface. This means that: - Builders cannot connect to the outside network or to other processes on the same machine, except processes within the same build. - Vice versa, other processes cannot connect to processes in a chroot build, and open ports/connections do not show up in "netstat". - If two concurrent builders try to listen on the same port (e.g. as part of a test), they no longer conflict with each other. This was inspired by the "PrivateNetwork" flag in systemd.
1 parent 2f3f413
show-duplication.pl
#! /usr/bin/perl -w
if (scalar @ARGV != 1) {
print "syntax: show-duplication.pl PATH\n";
exit 1;
}
my $root = $ARGV[0];
my $nameRE = "(?:(?:[A-Za-z0-9\+\_]|(?:-[^0-9]))+)";
my $versionRE = "(?:[A-Za-z0-9\.\-]+)";
my %pkgInstances;
my $pid = open(PATHS, "-|") || exec "nix-store", "-qR", $root;
while (<PATHS>) {
chomp;
/^.*\/[0-9a-z]*-(.*)$/;
my $nameVersion = $1;
$nameVersion =~ /^($nameRE)(-($versionRE))?$/;
$name = $1;
$version = $3;
$version = "(unnumbered)" unless defined $version;
# print "$nameVersion $name $version\n";
push @{$pkgInstances{$name}}, {version => $version, path => $_};
}
close PATHS or exit 1;
sub pathSize {
my $path = shift;
my @st = lstat $path or die;
my $size = $st[7];
if (-d $path) {
opendir DIR, $path or die;
foreach my $name (readdir DIR) {
next if $name eq "." || $name eq "..";
$size += pathSize("$path/$name");
}
}
return $size;
}
my $totalPaths = 0;
my $totalSize = 0, $totalWaste = 0;
foreach my $name (sort {scalar @{$pkgInstances{$b}} <=> scalar @{$pkgInstances{$a}}} (keys %pkgInstances)) {
print "$name ", scalar @{$pkgInstances{$name}}, "\n";
my $allSize = 0;
foreach my $x (sort {$a->{version} cmp $b->{version}} @{$pkgInstances{$name}}) {
$totalPaths++;
my $size = pathSize $x->{path};
$allSize += $size;
print " $x->{version} $size\n";
}
my $avgSize = int($allSize / scalar @{$pkgInstances{$name}});
my $waste = $allSize - $avgSize;
$totalSize += $allSize;
$totalWaste += $waste;
print " average $avgSize, waste $waste\n";
}
my $avgDupl = $totalPaths / scalar (keys %pkgInstances);
my $wasteFactor = ($totalWaste / $totalSize) * 100;
print "average package duplication $avgDupl, total size $totalSize, total waste $totalWaste, $wasteFactor% wasted\n";

Computing file changes ...