Skip to content

Instantly share code, notes, and snippets.

@timsonner
Created March 7, 2026 20:21
Show Gist options
  • Select an option

  • Save timsonner/6f36344a91c5d02efd4f60f9ca4c3d4e to your computer and use it in GitHub Desktop.

Select an option

Save timsonner/6f36344a91c5d02efd4f60f9ca4c3d4e to your computer and use it in GitHub Desktop.
Find fastest download server / mirror.
#!/usr/bin/env bash
# Find the fastest mirror from a list of servers
# Tests HTTP(S) response time using curl's time_connect + time_starttransfer
TIMEOUT=5
PARALLEL=8 # max concurrent jobs
SERVERS=(
adectra.com
akane.network
arizona.edu
arlm.tyzoid.com
bloomu.edu
brightlight.today
cdn-perfprod.com
cicku.me
clarkson.edu
colonelhosting.com
constant.com
cs.odu.edu
customcomputercare.com
ette.biz
fcix.net
geo.mirror.pkgbuild.com
givebytes.net
goober.cloud
hasphetica.win
hu.fo
hugeblank.dev
ialab.dsu.edu
iu13.org
k0.ae
kernel.org
lahansons.com
leaseweb.net
logal.dev
lug.mtu.edu
m.lqy.me
marcusspencer.us
miningtcup.me
mirrors.shr.cx
misaka.one
mit.edu
mra.sh
niranjan.co
ocf.berkeley.edu
octyl.net
osuosl.org
pilotfiber.com
rackspace.com
rcac.purdue.edu
rit.edu
smeal.xyz
soulharsh007.dev
teraswitch.com
theash.xyz
umd.edu
vectair.net
xtom.com
yonderly.org
zackmyers.io
zxcvfdsa.com
)
TMPDIR_RESULTS=$(mktemp -d)
trap 'rm -rf "$TMPDIR_RESULTS"' EXIT
measure() {
local host="$1"
local result
result=$(curl -sSo /dev/null \
--max-time "$TIMEOUT" \
--connect-timeout "$TIMEOUT" \
-w "%{time_connect} %{time_starttransfer}" \
-L --max-redirs 3 \
"https://${host}/" 2>/dev/null)
if [[ -z "$result" ]]; then
printf "%-40s UNREACHABLE\n" "$host" > "$TMPDIR_RESULTS/$host"
return
fi
local t_connect t_ttfb total
t_connect=$(echo "$result" | awk '{print $1}')
t_ttfb=$(echo "$result" | awk '{print $2}')
# Use TTFB (time to first byte) as the ranking metric; 0.000 means failed
if [[ "$t_ttfb" == "0.000000" || "$t_ttfb" == "0" ]]; then
printf "%-40s UNREACHABLE\n" "$host" > "$TMPDIR_RESULTS/$host"
else
total=$(awk "BEGIN {printf \"%.4f\", $t_ttfb}")
printf "%-40s %s s (connect: %s s)\n" "$host" "$total" "$t_connect" \
> "$TMPDIR_RESULTS/$host"
fi
}
export -f measure
export TIMEOUT TMPDIR_RESULTS
echo "Testing ${#SERVERS[@]} mirrors (timeout: ${TIMEOUT}s, parallel: ${PARALLEL})..."
echo "---"
# Run measurements in parallel using a job pool
active=0
for host in "${SERVERS[@]}"; do
measure "$host" &
(( active++ ))
if (( active >= PARALLEL )); then
wait -n 2>/dev/null || wait # wait for any one job (-n requires bash 4.3+)
(( active-- ))
fi
done
wait
echo ""
echo "=== Results (sorted by TTFB) ==="
echo ""
# Separate reachable from unreachable, sort reachable by TTFB
REACHABLE=()
UNREACHABLE=()
for host in "${SERVERS[@]}"; do
line=$(cat "$TMPDIR_RESULTS/$host" 2>/dev/null)
if [[ "$line" == *"UNREACHABLE"* ]]; then
UNREACHABLE+=("$line")
else
REACHABLE+=("$line")
fi
done
# Sort reachable results by the TTFB column (field 2)
printf '%s\n' "${REACHABLE[@]}" | sort -k2 -n
if (( ${#UNREACHABLE[@]} > 0 )); then
echo ""
echo "--- Unreachable ---"
printf '%s\n' "${UNREACHABLE[@]}"
fi
echo ""
echo "=== FASTEST MIRROR ==="
BEST=$(printf '%s\n' "${REACHABLE[@]}" | sort -k2 -n | head -1)
echo "$BEST"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment