Skip to content

Instantly share code, notes, and snippets.

@JPvRiel
Last active April 11, 2023 00:49
Show Gist options
  • Save JPvRiel/e825c231f0e2209d1f8bb5e40addab02 to your computer and use it in GitHub Desktop.
Save JPvRiel/e825c231f0e2209d1f8bb5e40addab02 to your computer and use it in GitHub Desktop.
Ubuntu mirror selection and package downloads for South Africa using nmap and curl to manually test latency and throughput

A quick set of notes looking into Ubuntu mirror locations for South Africa from my home fiber (Vumatel). The examples should apply in general.

Debian Package Info and Downloads

There are two phases

  1. Getting lists of packages
  2. The actual package download

When testing performance of package list info downloads via upt-get update, clear previous package info downloaded. If this isn't done, cached package info could skew results.

sudo rm -rf /var/lib/apt/lists/*

'Software & Updates' tool

The Software & Updates (software-properties-gtk) tool has a 'Dowload from' button. Choose 'Other' and look for the 'Select best server' button.

tool screenshot

ubuntu.mirror.neology.co.za was selected as the best choice based on the 'Software & Updates' tool's methods.

Manual testing

Ubuntu mirror info

Official Archive Mirrors for Ubuntu provides info on mirrors, the link speed and how up to date they are.

E.g.

South Africa 2 Gbps 3 mirrors
WIRUlink http ftp rsync 1 Gbps Up to date
Neology http ftp rsync 1 Gbps Up to date
UCT LEG http ftp rsync 10 Mbps Up to date

Another option is to check (http://mirrors.ubuntu.com/ZA.txt)

http://ftp.leg.uct.ac.za/ubuntu/
http://mirror.wiru.co.za/ubuntu/
http://ubuntu.mirror.neology.co.za/ubuntu/
http://archive.ubuntu.com/ubuntu/

And there are some unofficial mirrors?

http://ubuntu.saix.net/ubuntu-archive/

As per (https://launchpad.net/ubuntu/+mirror/ftp.saix.net-archive), it looks behind.

Manual traceroute to nearest mirror

A traceroute will help check latency and nearest hop (but that doesn't necessairly imply best bandwidth)

To use namp to traceroute

$ export targets=$(curl -s http://mirrors.ubuntu.com/ZA.txt | grep -oP '(?<=^http://)[^/]+') && sudo -E nmap -Pn -sT -p80 --traceroute -oX za.ubuntu.nmap.xml $targets za.archive.ubuntu.com

Note, the above:

  • gets a list of mirrors and extracts the FQDNs into the targets variable which is exported so that it can be passed along via sudo nmap
  • nmap requires root for the traceroute feature
  • za.archive.ubuntu.com is appended to the list, given this seems to be the official update site when installing Ubuntu and setting the region as South Africa
  • *.archive.ubuntu.com have some or the other network security mechanism the prevents nmap host discovery and port probe on port 80, hence the need to -Pn to force the traceroute

The scan traceroute results can be visualized with zenmap. Zenmap provides nice visual queues

  • Outermost circle lines show the furtherest hosts
  • The thicker the blue line, the more latency
  • Centered perspective from the router that was common to most routes
zenmap za.ubuntu.nmap.xml

zenmap toplogy screenshot

Observations:

  • mirror.wiru.co.za was closest
    • 9 hops away (lowest)
    • ~2 ms latency (lowest)
  • ubuntu.mirror.neology.co.za was 2nd closest
  • za.archive.ubuntu.com was even further than archive.ubuntu.com!
    • 13 hops away (highest)
    • ~190 ms latency (highest)

Manual download test

Using the mirror file and appending the za.archive.ubuntu.com, I tested downloading the updates package list for my architecture (amd64):

$ for m in $(curl -s http://mirrors.ubuntu.com/ZA.txt) http://za.archive.ubuntu.com/ubuntu; do echo $m; curl "$m/dists/xenial-updates/Contents-amd64.gz" > /dev/null; done
http://mirror.wiru.co.za/ubuntu/
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 5991k  100 5991k    0     0  10.4M      0 --:--:-- --:--:-- --:--:-- 10.4M
http://ubuntu.mirror.neology.co.za/ubuntu/
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 5991k  100 5991k    0     0  1106k      0  0:00:05  0:00:05 --:--:--  984k
http://ftp.leg.uct.ac.za/ubuntu/
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 5991k  100 5991k    0     0   561k      0  0:00:10  0:00:10 --:--:--  595k
http://archive.ubuntu.com/ubuntu/
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 5991k  100 5991k    0     0  1556k      0  0:00:03  0:00:03 --:--:-- 1556k
http://za.archive.ubuntu.com/ubuntu
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 5991k  100 5991k    0     0   298k      0  0:00:20  0:00:20 --:--:--  286k

Observations

  • ~10MB/s average was the best, and approaching the maximum throughput of my current fiber line's throughput (~100Mbit/s)
  • za.archive.ubuntu.com, the default when you do a fresh install, was the worst!
  • Even though archive.ubuntu.com has the second highest number of hops and latency, and tracerouted through a ste in london, onto the US, it showed the 2nd best throughput, beating out all other local mirrors, except one.

Limitations:

  • The above only simulated some of the package list download process, not an actual package fetch.
  • And many more samples are needed (I'd be shot by a statistician)

Conclusion and inferences

The 'Software & Updates' and my own traceroute plus once-off curl download speed test didn't 100% agree, but both found what seems to be the top two local mirrors. Obviously:

  • Multiple samples over various time ranges are needed
  • As well as testing actual package downloads

Oddly, za.archive.ubuntu.com is the furtherest away and the slowest. Maybe it has the highest network load from SA given it's the default mirror if Ubuntu is installed with South Africa as the region.

Related

apt-select is an example of a tool that automates many of the steps above, except and actual download speed test. A feature request for that has already been logged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment