dns-bench/main.sh
2024-12-20 10:15:17 +04:00

60 lines
1.4 KiB
Bash
Executable file

#!/bin/bash
IFS=$'\n'
set -eu -o pipefail
cleanup () {
echo
echo '==> Stopping Unbound'
[ -v unbound_pid ] && kill -INT "$unbound_pid"
echo
}
trap cleanup EXIT
echo
echo '==> Checking deps'
echo 'Note: dig is installed from package usually named "bind-utils"'
echo ' drill -- package "ldns"'
echo " and hickory's resolve can be built with ./build_hr.sh"
echo ' (this script will find it in subdir, no need to install)'
which unbound
which hyperfine
which dig
which drill
hr="hickory-dns/target/release/resolve"
[ -e "$hr" ] || hr=$(which resolve)
echo
echo '==> Starting Unbound'
unbound -c ./unbound.conf -dp 2>unbound.log &
unbound_pid=$!
sleep 2
echo
echo '==> Benchmarks for A domain.tld.'
hyperfine -N \
"dig -p 2253 domain.tld @127.0.0.1" \
"drill -p 2253 domain.tld @127.0.0.1" \
"$hr -n 127.0.0.1:2253 domain.tld"
echo
echo '==> Benchmarks for AAAA domain.tld.'
hyperfine -N \
"dig -p 2253 aaaa domain.tld @127.0.0.1" \
"drill -p 2253 aaaa domain.tld @127.0.0.1" \
"$hr -n 127.0.0.1:2253 -t AAAA domain.tld"
echo
echo '==> Benchmarks for MX domain.tld.'
hyperfine -N \
"dig -p 2253 mx domain.tld @127.0.0.1" \
"drill -p 2253 mx domain.tld @127.0.0.1" \
"$hr -n 127.0.0.1:2253 -t MX domain.tld"
echo
echo '==> Benchmarks for CNAME mail.domain.tld.'
hyperfine -N \
"dig -p 2253 mail.domain.tld @127.0.0.1" \
"drill -p 2253 mail.domain.tld @127.0.0.1" \
"$hr -n 127.0.0.1:2253 mail.domain.tld"