Created
April 18, 2024 20:07
-
-
Save litch/eb41e0170943bbf2b0fa5735a6a9f150 to your computer and use it in GitHub Desktop.
Digtest for diagnosing DNS timings
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# depends on gawk | |
# if running in a netshoot container, you need to install it: | |
# apk add --no-cache gawk | |
# Filename to store the results | |
output_file="dig_results.txt" | |
times_file="query_times.txt" | |
# Clear files if they already exist | |
> "$output_file" | |
> "$times_file" | |
# Number of iterations | |
iterations=1000 | |
echo "Performing $iterations DNS lookups..." | |
# Execute dig command multiple times and save the query times | |
for i in $(seq 1 $iterations); do | |
dig bitcoind-mutinynet.bitcoind.svc.cluster.local | grep "Query time" >> "$output_file" | |
done | |
# Extract the query times from the results | |
awk -F ": " '/Query time/ {print $2}' "$output_file" | awk '{print $1}' > "$times_file" | |
# Calculate percentile distributions using gawk instead of awk | |
echo "Calculating percentile distributions..." | |
gawk 'BEGIN { | |
total = 0; | |
count = 0; | |
data[0] = 0; | |
} | |
{ | |
data[count++] = $1; | |
total += $1; | |
} | |
END { | |
asort(data); | |
p50 = int(0.5 * count); | |
p90 = int(0.9 * count); | |
p95 = int(0.95 * count); | |
p99 = int(0.99 * count); | |
print "50th Percentile (Median): " data[p50] " ms"; | |
print "90th Percentile: " data[p90] " ms"; | |
print "95th Percentile: " data[p95] " ms"; | |
print "99th Percentile: " data[p99] " ms"; | |
print "Average: " total/count " ms"; | |
}' "$times_file" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment