perl script to autoselect best server for apt
http.us.debian.org has multiple ips. This (rather simple) perl script will
use netselect (apt-get install netselect) and nslookup to pick the "best"
(fastest, closest) server.
For me, this makes a difference: from some servers, I get 10k/sec, and
from samosa.debian.org (which this script picked for me), I get almost
200k/sec.
Or, is there a reason *not* to always use one server? I can imagine that
this may affect the loads on each server. It does keep overall network
traffic down, though, because netselect factors in hop count.
Comments?
Evan.
#!/usr/bin/perl -w
# Uses netselect to find "best" (fastest, closest) server.
#
# Evan Martin <eeyem@u.washington.edu>
# Nov-11-1999
$host = 'http.us.debian.org';
print "Looking up $host...\n";
$iplist = nslookup($host, 'Addresses');
print "Available hosts: " . $iplist . "\n";
print "netselect'ng best host...\n";
open(NETSEL, "netselect " . join(' ', split(/\s*,\s*/, $iplist)) . "|") || die "netselect error";
$ip = (split(' ', <NETSEL>))[1];
close(NETSEL);
$besthost = nslookup($ip, 'Name');
print "Best host: $besthost\n";
sub nslookup() {
my ($host, $word) = @_;
open(NSLOOKUP, "nslookup $host 2>&1 |") || die "nslookup error";
while (<NSLOOKUP>) {
last if /$word/;
if (/\*\*\*/) {
print "nslookup says: $_";
die "*** nslookup error";
}
}
close(NSLOOKUP);
s/$word:\s*//;
chomp;
return $_;
}
Reply to: