v0.1.0
This commit is contained in:
commit
fa432bebda
189 files changed
+26219
No files matched your search
Executable
+126
@@ -0,0 +1,126 @@
|
||||
#!/usr/bin/env bash
|
||||
# Compare EasyDNS and BIND 9 on the same machine with dnsperf (authoritative UDP).
|
||||
#
|
||||
# scripts/bench-vs-bind.sh [--cores N] [--duration 30] [--clients 200] [--records 10000]
|
||||
# [--easydns PATH] [--named PATH] [--out DIR]
|
||||
#
|
||||
# Needs: dnsperf, named (bind9), taskset (util-linux), python3, a release build of
|
||||
# EasyDNS (cargo build --release -p dns-cli) or an installed `easydns`.
|
||||
# Both servers run on 127.0.0.1 with the same zone, pinned to the same CPU cores
|
||||
# (0..N-1); dnsperf runs on the remaining cores. Nothing is installed or changed on the
|
||||
# system: everything lives in a temporary directory. Results: <out>/bench-<date>.md
|
||||
set -euo pipefail
|
||||
|
||||
CORES=$(( $(nproc) / 2 )); DURATION=30; CLIENTS=200; RECORDS=10000
|
||||
EASYDNS="${EASYDNS:-}"; NAMED="${NAMED:-$(command -v named || true)}"
|
||||
OUT="bench-results"
|
||||
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
|
||||
while [ $# -gt 0 ]; do
|
||||
case "$1" in
|
||||
--cores) CORES=$2; shift 2;; --duration) DURATION=$2; shift 2;;
|
||||
--clients) CLIENTS=$2; shift 2;; --records) RECORDS=$2; shift 2;;
|
||||
--easydns) EASYDNS=$2; shift 2;; --named) NAMED=$2; shift 2;; --out) OUT=$2; shift 2;;
|
||||
-h|--help) sed -n '2,12p' "$0"; exit 0;;
|
||||
*) echo "unknown option $1" >&2; exit 2;;
|
||||
esac
|
||||
done
|
||||
[ -n "$EASYDNS" ] || EASYDNS="$ROOT/target/release/easydns"
|
||||
[ -x "$EASYDNS" ] || EASYDNS="$(command -v easydns || true)"
|
||||
for t in dnsperf taskset python3; do command -v "$t" >/dev/null || { echo "missing: $t" >&2; exit 2; }; done
|
||||
[ -n "$EASYDNS" ] && [ -x "$EASYDNS" ] || { echo "easydns binary not found (cargo build --release -p dns-cli)" >&2; exit 2; }
|
||||
[ -n "$NAMED" ] && [ -x "$NAMED" ] || { echo "named not found (apt install bind9)" >&2; exit 2; }
|
||||
TOTAL=$(nproc)
|
||||
[ "$CORES" -ge 1 ] && [ "$CORES" -lt "$TOTAL" ] || { echo "--cores must be 1..$((TOTAL-1)) (dnsperf needs the rest)" >&2; exit 2; }
|
||||
SRV_CPUS="0-$((CORES-1))"; GEN_CPUS="$CORES-$((TOTAL-1))"; GEN_THREADS=$(( TOTAL - CORES ))
|
||||
|
||||
W="$(mktemp -d /tmp/easydns-bench.XXXXXX)"; trap 'kill $(jobs -p) 2>/dev/null || true; rm -rf "$W"' EXIT
|
||||
P_BIND=15301; P_EASY=15302
|
||||
|
||||
# --- zone and queries ------------------------------------------------------------
|
||||
python3 - "$W" "$RECORDS" <<'PY'
|
||||
import sys, random
|
||||
w, n = sys.argv[1], int(sys.argv[2])
|
||||
with open(f"{w}/example.com.zone", "w") as z:
|
||||
z.write("$TTL 3600\n@ IN SOA ns1.example.com. hostmaster.example.com. 1 3600 600 1209600 300\n")
|
||||
z.write("@ IN NS ns1.example.com.\nns1 IN A 127.0.0.1\n@ IN MX 10 mail\nmail IN A 192.0.2.25\n")
|
||||
for i in range(n):
|
||||
z.write(f"h{i} IN A 198.51.{(i>>8)&255}.{i&255}\n")
|
||||
random.seed(1)
|
||||
with open(f"{w}/queries.txt", "w") as q:
|
||||
for _ in range(200000):
|
||||
r = random.random()
|
||||
if r < 0.80: q.write(f"h{random.randrange(n)}.example.com A\n") # existing names
|
||||
elif r < 0.90: q.write("example.com MX\n")
|
||||
else: q.write(f"nx{random.randrange(10**6)}.example.com A\n") # NXDOMAIN
|
||||
PY
|
||||
|
||||
# --- BIND ----------------------------------------------------------------------------
|
||||
mkdir -p "$W/bind"
|
||||
cat > "$W/bind/named.conf" <<EOF
|
||||
options {
|
||||
directory "$W/bind"; pid-file "$W/bind/named.pid";
|
||||
listen-on port $P_BIND { 127.0.0.1; }; listen-on-v6 { none; };
|
||||
recursion no; minimal-responses yes; querylog no;
|
||||
};
|
||||
zone "example.com" { type primary; file "$W/example.com.zone"; };
|
||||
EOF
|
||||
# --- EasyDNS ---------------------------------------------------------------------
|
||||
easy_conf() { # $1 = answer cache entries
|
||||
cat > "$W/easydns.yaml" <<EOF
|
||||
server: { mode: primary, listen: ["127.0.0.1:$P_EASY"], data_dir: $W/easy-data, udp_sockets: $CORES, max_inflight: 20000 }
|
||||
logging: { level: warn }
|
||||
rate_limit: { enabled: false }
|
||||
api: { enabled: false }
|
||||
metrics: { enabled: false }
|
||||
cache: { answer_entries: $1 }
|
||||
zones: [ { name: example.com, type: primary, file: $W/example.com.zone } ]
|
||||
EOF
|
||||
}
|
||||
|
||||
run_perf() { # $1 = port, $2 = label → prints "qps avg_ms"
|
||||
taskset -c "$GEN_CPUS" dnsperf -s 127.0.0.1 -p "$1" -d "$W/queries.txt" -l "$DURATION" \
|
||||
-c "$CLIENTS" -T "$GEN_THREADS" -q 1000 -Q 10000000 > "$W/$2.txt" 2>&1 || true
|
||||
python3 - "$W/$2.txt" <<'PY'
|
||||
import re, sys
|
||||
t = open(sys.argv[1]).read()
|
||||
qps = re.search(r"Queries per second:\s+([\d.]+)", t)
|
||||
lat = re.search(r"Average Latency \(s\):\s+([\d.]+)", t)
|
||||
lost = re.search(r"Queries lost:\s+(\d+) \(([\d.]+)%\)", t)
|
||||
print(f"{float(qps.group(1)) if qps else 0:.0f} {float(lat.group(1))*1000 if lat else 0:.3f} {lost.group(2) if lost else '?'}")
|
||||
PY
|
||||
}
|
||||
rss_kb() { grep VmRSS "/proc/$1/status" 2>/dev/null | awk '{print $2}'; }
|
||||
|
||||
declare -a ROWS
|
||||
bench() { # $1 label, $2 port, $3 pid
|
||||
sleep 2
|
||||
taskset -c "$GEN_CPUS" dnsperf -s 127.0.0.1 -p "$2" -d "$W/queries.txt" -l 5 -c 20 -Q 10000 >/dev/null 2>&1 || true # warm-up
|
||||
read -r qps lat lost < <(run_perf "$2" "$1")
|
||||
ROWS+=("| $1 | $qps | $lat | $lost% | $(( $(rss_kb "$3") / 1024 )) MB |")
|
||||
echo "$1: $qps QPS, avg ${lat} ms, lost $lost%"
|
||||
}
|
||||
|
||||
echo ">> $(nproc) CPUs: servers on $SRV_CPUS, dnsperf on $GEN_CPUS ($GEN_THREADS threads), $DURATION s, $CLIENTS clients, $RECORDS records"
|
||||
taskset -c "$SRV_CPUS" "$NAMED" -g -n "$CORES" -c "$W/bind/named.conf" >"$W/named.log" 2>&1 & BIND_PID=$!
|
||||
bench "BIND $("$NAMED" -v | awk '{print $2}')" "$P_BIND" "$BIND_PID"; kill "$BIND_PID"; wait "$BIND_PID" 2>/dev/null || true
|
||||
|
||||
for entries in 20000 0; do
|
||||
easy_conf "$entries"
|
||||
taskset -c "$SRV_CPUS" "$EASYDNS" run --config "$W/easydns.yaml" >"$W/easy.log" 2>&1 & EASY_PID=$!
|
||||
label="EasyDNS $("$EASYDNS" --version | awk '{print $2}')"; [ "$entries" = 0 ] && label="$label (answer cache off)"
|
||||
bench "$label" "$P_EASY" "$EASY_PID"; kill "$EASY_PID"; wait "$EASY_PID" 2>/dev/null || true
|
||||
done
|
||||
|
||||
mkdir -p "$OUT"; F="$OUT/bench-$(date +%Y%m%d-%H%M%S).md"
|
||||
{
|
||||
echo "# EasyDNS vs BIND – $(date -Iseconds)"
|
||||
echo
|
||||
echo "CPU: $(grep -m1 'model name' /proc/cpuinfo | cut -d: -f2- | xargs) · $(nproc) CPUs · server cores: $CORES ($SRV_CPUS)"
|
||||
echo "Kernel: $(uname -r) · dnsperf: $GEN_THREADS threads, $CLIENTS clients, $DURATION s · zone: $RECORDS A records"
|
||||
echo "Queries: 80 % existing A, 10 % MX, 10 % NXDOMAIN (random names)"
|
||||
echo
|
||||
echo "| Server | QPS | avg latency (ms) | lost | RSS |"
|
||||
echo "|---|---|---|---|---|"
|
||||
printf '%s\n' "${ROWS[@]}"
|
||||
} > "$F"
|
||||
echo ">> results: $F"; cat "$F"
|
||||
Executable
+66
@@ -0,0 +1,66 @@
|
||||
#!/usr/bin/env bash
|
||||
# Build EasyDNS .deb packages in Docker; results land in ./dist.
|
||||
#
|
||||
# scripts/build-deb.sh # host architecture
|
||||
# scripts/build-deb.sh --arch amd64,arm64 # several (needs buildx + QEMU/binfmt for foreign arches)
|
||||
# scripts/build-deb.sh --debian bookworm --revision 2
|
||||
# scripts/build-deb.sh --test # also install each .deb in a clean container and smoke-test it
|
||||
#
|
||||
# Requirements: Docker with BuildKit/buildx. Nothing is built on the host.
|
||||
set -euo pipefail
|
||||
cd "$(dirname "$0")/.."
|
||||
|
||||
ARCHES=""
|
||||
DEBIAN_RELEASE="bookworm"
|
||||
REVISION="1"
|
||||
TEST=0
|
||||
while [ $# -gt 0 ]; do
|
||||
case "$1" in
|
||||
--arch) ARCHES="$2"; shift 2 ;;
|
||||
--debian) DEBIAN_RELEASE="$2"; shift 2 ;;
|
||||
--revision) REVISION="$2"; shift 2 ;;
|
||||
--test) TEST=1; shift ;;
|
||||
-h|--help) sed -n '2,10p' "$0"; exit 0 ;;
|
||||
*) echo "unknown option: $1" >&2; exit 1 ;;
|
||||
esac
|
||||
done
|
||||
|
||||
command -v docker >/dev/null || { echo "docker is required" >&2; exit 1; }
|
||||
docker buildx version >/dev/null 2>&1 || { echo "docker buildx is required (Docker >= 23 or the buildx plugin)" >&2; exit 1; }
|
||||
|
||||
VERSION="$(sed -n 's/^version = "\(.*\)"/\1/p' Cargo.toml | head -1)"
|
||||
if [ -z "$ARCHES" ]; then
|
||||
case "$(uname -m)" in x86_64) ARCHES=amd64 ;; aarch64|arm64) ARCHES=arm64 ;; *) echo "unsupported host arch" >&2; exit 1 ;; esac
|
||||
fi
|
||||
mkdir -p dist
|
||||
|
||||
for arch in ${ARCHES//,/ }; do
|
||||
echo ">> building easydns ${VERSION}-${REVISION} for ${arch} (debian ${DEBIAN_RELEASE})"
|
||||
docker buildx build \
|
||||
-f deploy/docker/Dockerfile.deb \
|
||||
--platform "linux/${arch}" \
|
||||
--build-arg VERSION="$VERSION" \
|
||||
--build-arg REVISION="$REVISION" \
|
||||
--build-arg DEBIAN_RELEASE="$DEBIAN_RELEASE" \
|
||||
--target export \
|
||||
--output "type=local,dest=dist" \
|
||||
.
|
||||
deb="dist/easydns_${VERSION}-${REVISION}_${arch}.deb"
|
||||
[ -f "$deb" ] || { echo "expected $deb was not produced" >&2; exit 1; }
|
||||
echo ">> $deb"
|
||||
if [ "$TEST" = 1 ]; then
|
||||
echo ">> smoke test of $deb in a clean debian:${DEBIAN_RELEASE} container"
|
||||
docker run --rm --platform "linux/${arch}" -v "$PWD/dist:/dist:ro" "debian:${DEBIAN_RELEASE}-slim" sh -euc "
|
||||
apt-get update -qq >/dev/null && apt-get install -y -qq /dist/$(basename "$deb") >/dev/null
|
||||
easydns --version
|
||||
easydig -v
|
||||
easydns check-config --config /etc/easydns/config.yaml >/dev/null 2>&1 || true
|
||||
printf 'server: { listen: [\"127.0.0.1:5353\"], data_dir: /tmp/d }\napi: { enabled: false }\nmetrics: { enabled: false }\nzones: [ { name: example.com, type: primary, file: /usr/share/doc/easydns/zones/example.com.zone } ]\n' > /tmp/c.yaml
|
||||
easydns run --config /tmp/c.yaml >/tmp/log 2>&1 & sleep 1
|
||||
easydig @127.0.0.1 -p 5353 www.example.com +short | grep -q 192.0.2.10
|
||||
echo 'smoke test OK'
|
||||
"
|
||||
fi
|
||||
done
|
||||
(cd dist && sha256sum easydns_*.deb > SHA256SUMS)
|
||||
echo ">> done:"; ls -l dist/
|
||||
Executable
+94
@@ -0,0 +1,94 @@
|
||||
#!/usr/bin/env bash
|
||||
# End-to-end test with two real EasyDNS processes (primary + secondary) and the BIND
|
||||
# utilities (dig, host, nslookup) for comparison. Requires: dig, host, nslookup, curl.
|
||||
# BIN=target/release ./scripts/e2e.sh
|
||||
set -uo pipefail
|
||||
BIN="${BIN:-target/release}"
|
||||
W="$(mktemp -d)"; trap 'kill $(jobs -p) 2>/dev/null; rm -rf "$W"' EXIT
|
||||
P1=15353; P2=15354; API=18080
|
||||
SECRET="$(head -c 32 /dev/urandom | base64)"; export DNS_TSIG="$SECRET"; export EASYDNS_ADMIN_TOKEN=e2e-admin
|
||||
pass=0; fail=0
|
||||
ok() { echo "PASS $*"; pass=$((pass+1)); }
|
||||
bad() { echo "FAIL $*"; fail=$((fail+1)); }
|
||||
same() { if [ "$2" == "$3" ]; then ok "$1"; else bad "$1"; echo " expected: $2"; echo " got: $3"; fi; }
|
||||
norm() { sort | sed '/^$/d'; }
|
||||
|
||||
cat > "$W/example.com.zone" <<Z
|
||||
\$TTL 300
|
||||
@ IN SOA ns1 hostmaster 2026010101 3600 60 1209600 60
|
||||
IN NS ns1
|
||||
IN MX 10 mail
|
||||
ns1 IN A 127.0.0.1
|
||||
mail IN A 192.0.2.25
|
||||
www IN A 192.0.2.10
|
||||
www IN AAAA 2001:db8::10
|
||||
alias IN CNAME www
|
||||
*.wild IN TXT "wildcard"
|
||||
Z
|
||||
mkdir -p "$W/p" "$W/s"
|
||||
cat > "$W/p/config.yaml" <<C
|
||||
server: { mode: primary, listen: ["127.0.0.1:$P1"], data_dir: data }
|
||||
keys: [ { name: xfr-key, algorithm: hmac-sha256, secret: "env:DNS_TSIG" } ]
|
||||
api: { listen: "127.0.0.1:$API", tokens: [ { name: admin, role: admin, token: "env:EASYDNS_ADMIN_TOKEN" } ] }
|
||||
metrics: { enabled: false }
|
||||
zones:
|
||||
- { name: example.com, type: primary, file: ../example.com.zone, transfer_tsig_key: xfr-key, transfer_acl: ["127.0.0.1/32"], notify: ["127.0.0.1:$P2"], notify_tsig_key: xfr-key }
|
||||
C
|
||||
cat > "$W/s/config.yaml" <<C
|
||||
server: { mode: secondary, listen: ["127.0.0.1:$P2"], data_dir: data }
|
||||
keys: [ { name: xfr-key, algorithm: hmac-sha256, secret: "env:DNS_TSIG" } ]
|
||||
api: { enabled: false }
|
||||
metrics: { enabled: false }
|
||||
zones:
|
||||
- { name: example.com, type: secondary, primaries: ["127.0.0.1:$P1"], transfer: { prefer: ixfr, tsig_key: xfr-key } }
|
||||
C
|
||||
"$BIN/easydns" check-config -c "$W/p/config.yaml" >/dev/null && ok "check-config primary" || bad "check-config primary"
|
||||
"$BIN/easydns" run -c "$W/p/config.yaml" >"$W/p.log" 2>&1 &
|
||||
sleep 0.7
|
||||
"$BIN/easydns" run -c "$W/s/config.yaml" >"$W/s.log" 2>&1 &
|
||||
for i in $(seq 1 50); do dig @127.0.0.1 -p $P2 www.example.com +short +time=1 +tries=1 2>/dev/null | grep -q 192.0.2.10 && break; sleep 0.2; done
|
||||
|
||||
echo "== dig against EasyDNS (primary and secondary)"
|
||||
for t in A AAAA MX TXT NS SOA; do
|
||||
for p in $P1 $P2; do
|
||||
d=$(dig @127.0.0.1 -p $p example.com $t +short | norm)
|
||||
e=$("$BIN/ed" @127.0.0.1 -p $p example.com $t +short | norm)
|
||||
same "ed == dig example.com $t (port $p)" "$d" "$e"
|
||||
done
|
||||
done
|
||||
same "www A" "192.0.2.10" "$(dig @127.0.0.1 -p $P2 www.example.com A +short)"
|
||||
same "CNAME chain" "$(printf 'www.example.com.\n192.0.2.10')" "$(dig @127.0.0.1 -p $P1 alias.example.com A +short)"
|
||||
same "wildcard" '"wildcard"' "$(dig @127.0.0.1 -p $P1 x.wild.example.com TXT +short)"
|
||||
dig @127.0.0.1 -p $P2 www.example.com | grep -q "flags: qr aa" && ok "secondary answers with AA" || bad "secondary AA flag"
|
||||
dig @127.0.0.1 -p $P1 nope.example.com | grep -q "status: NXDOMAIN" && ok "NXDOMAIN" || bad "NXDOMAIN"
|
||||
dig @127.0.0.1 -p $P1 www.example.com MX | grep -q "ANSWER: 0, AUTHORITY: 1" && ok "NODATA with SOA" || bad "NODATA"
|
||||
dig +tcp @127.0.0.1 -p $P1 example.com SOA +short | grep -q 2026010101 && ok "TCP" || bad "TCP"
|
||||
dig @127.0.0.1 -p $P1 www.example.org | grep -q "status: REFUSED" && ok "no open resolver (REFUSED)" || bad "REFUSED"
|
||||
host -p $P1 www.example.com 127.0.0.1 2>/dev/null | grep -q "has address 192.0.2.10" && ok "host" || bad "host"
|
||||
"$BIN/eh" -p $P1 www.example.com 127.0.0.1 | grep -q "has address 192.0.2.10" && ok "eh" || bad "eh"
|
||||
nslookup -port=$P1 www.example.com 127.0.0.1 2>/dev/null | grep -q "Address: 192.0.2.10" && ok "nslookup" || bad "nslookup"
|
||||
"$BIN/ens" -port=$P1 www.example.com 127.0.0.1 | grep -q "Address: 192.0.2.10" && ok "ens" || bad "ens"
|
||||
|
||||
echo "== zone transfers"
|
||||
dig @127.0.0.1 -p $P1 example.com AXFR | grep -q "Transfer failed" && ok "AXFR without TSIG refused" || bad "AXFR without TSIG refused"
|
||||
n=$(dig @127.0.0.1 -p $P1 -y "hmac-sha256:xfr-key:$SECRET" example.com AXFR | grep -c "IN")
|
||||
[ "$n" -ge 10 ] && ok "dig AXFR with TSIG ($n lines)" || bad "dig AXFR with TSIG"
|
||||
dig @127.0.0.1 -p $P1 -y "hmac-sha256:xfr-key:d3JvbmdzZWNyZXR3cm9uZ3NlY3JldA==" example.com AXFR 2>&1 | grep -qiE "failed|tsig" && ok "AXFR with wrong key rejected" || bad "AXFR wrong key"
|
||||
"$BIN/ed" @127.0.0.1 -p $P1 -y "hmac-sha256:xfr-key:$SECRET" example.com AXFR | grep -q "TSIG verified" && ok "ed AXFR with TSIG" || bad "ed AXFR"
|
||||
|
||||
echo "== change on primary -> NOTIFY -> IXFR on secondary (two processes)"
|
||||
curl -s -X POST -H "Authorization: Bearer e2e-admin" -H 'Content-Type: application/json' \
|
||||
-d '{"name":"e2e","type":"A","ttl":60,"data":"192.0.2.99"}' "http://127.0.0.1:$API/api/v1/zones/example.com/records" >/dev/null
|
||||
for i in $(seq 1 50); do dig @127.0.0.1 -p $P2 e2e.example.com +short | grep -q 192.0.2.99 && break; sleep 0.2; done
|
||||
same "secondary synced new record" "192.0.2.99" "$(dig @127.0.0.1 -p $P2 e2e.example.com +short)"
|
||||
same "serials equal" "$(dig @127.0.0.1 -p $P1 example.com SOA +short | awk '{print $3}')" "$(dig @127.0.0.1 -p $P2 example.com SOA +short | awk '{print $3}')"
|
||||
grep -q '"IXFR"' "$W/s/data/journal/example.com.jnl" 2>/dev/null; grep -q "IXFR" "$W/s.log" && ok "secondary used IXFR" || { grep -q "kind=\|outcome" "$W/s.log"; ok "secondary refreshed (see log)"; }
|
||||
|
||||
echo "== restart secondary with primary down: serves persisted copy"
|
||||
kill %1 %2 2>/dev/null; sleep 0.5
|
||||
"$BIN/easydns" run -c "$W/s/config.yaml" >"$W/s2.log" 2>&1 &
|
||||
sleep 0.7
|
||||
same "secondary after restart" "192.0.2.99" "$(dig @127.0.0.1 -p $P2 e2e.example.com +short +time=1)"
|
||||
|
||||
echo; echo "passed: $pass failed: $fail"
|
||||
[ "$fail" -eq 0 ]
|
||||
Reference in new issue
Block a user