Commit 91b1d47f authored by Vitaly Lipatov's avatar Vitaly Lipatov

route-update: parallelize volatile domain detection (xargs -P 10)

detect_volatile_domains() and expand_volatile_subnets() now run dig queries in parallel (10 concurrent) via temp script + xargs -P. Reduces wall time from ~3min to ~20sec for lists with 200+ domains (telegram 135 + whatsapp 69). Co-Authored-By: 's avatarClaude Opus 4.6 <noreply@anthropic.com>
parent 5982bb88
......@@ -152,7 +152,8 @@ detect_volatile_domains()
local volatile_file="$STATE_DIR/$state/volatile_domains"
local ttl_threshold=120
local domains=$(mktemp)
trap "rm -f $domains" RETURN
local checker=$(mktemp)
trap "rm -f $domains $checker" RETURN
# Extract unique domain names from list files
for f in "$@" ; do
......@@ -161,15 +162,19 @@ detect_volatile_domains()
[ -s "$domains" ] || { rm -f "$volatile_file" ; return 0 ; }
> "$volatile_file"
while read -r domain ; do
local output=$(dig +noall +answer "$domain" "$rtype" 2>/dev/null | grep "IN[[:space:]]*${rtype}[[:space:]]")
local count=$(echo "$output" | grep -c .)
local ttl=$(echo "$output" | head -1 | awk '{print $2}')
if [ "$count" -le 1 ] && [ "${ttl:-9999}" -le "$ttl_threshold" ] ; then
echo "$domain ttl=$ttl records=$count" >> "$volatile_file"
fi
done < "$domains"
# Parallel dig via temp script (avoids quoting issues with xargs)
cat > "$checker" << 'CHECKER'
#!/bin/sh
rtype="$1"; threshold="$2"; domain="$3"
output=$(dig +noall +answer "$domain" "$rtype" 2>/dev/null | grep "IN[[:space:]]*${rtype}[[:space:]]")
count=$(echo "$output" | grep -c .)
ttl=$(echo "$output" | head -1 | awk '{print $2}')
if [ "$count" -le 1 ] && [ "${ttl:-9999}" -le "$threshold" ] ; then
printf "%s\tttl=%s records=%s\n" "$domain" "$ttl" "$count"
fi
CHECKER
chmod +x "$checker"
xargs -P 10 -I{} "$checker" "$rtype" "$ttl_threshold" {} < "$domains" > "$volatile_file"
if [ -s "$volatile_file" ] ; then
vlog "[$name]$label volatile domains (TTL≤${ttl_threshold}s, single $rtype): $(wc -l < "$volatile_file")"
......@@ -188,23 +193,31 @@ expand_volatile_subnets()
local vip_dir="$STATE_DIR/$state/volatile_ips"
mkdir -p "$vip_dir"
# Phase 1: parallel dig for all volatile domains
local fresh_dir=$(mktemp -d)
local digger=$(mktemp)
trap "rm -rf $fresh_dir $digger" RETURN
cat > "$digger" << 'DIGGER'
#!/bin/sh
domain="$1"; outdir="$2"; extra_dns="$3"
out="$outdir/$domain"
dig +short "$domain" AAAA 2>/dev/null | grep ':' > "$out"
[ -n "$extra_dns" ] && dig @$extra_dns +short "$domain" AAAA 2>/dev/null | grep ':' >> "$out" || true
DIGGER
chmod +x "$digger"
awk -F' ' '{print $1}' "$volatile_file" | \
xargs -P 10 -I{} "$digger" {} "$fresh_dir" "$EXTRA_DNS"
# Phase 2: sequential merge + subnet computation
local added=0
while IFS=' ' read -r domain _info ; do
[ -z "$domain" ] && continue
local ip_file="$vip_dir/$domain"
local fresh="$fresh_dir/$domain"
# Collect AAAA from local + extra resolvers
local fresh=$(mktemp)
trap "rm -f $fresh" RETURN
dig +short "$domain" AAAA 2>/dev/null | grep ':' >> "$fresh"
[ -n "$EXTRA_DNS" ] && dig @$EXTRA_DNS +short "$domain" AAAA 2>/dev/null | grep ':' >> "$fresh" || true
# Merge with saved IPs (accumulate across runs)
if [ -s "$ip_file" ] ; then
cat "$ip_file" >> "$fresh"
fi
sort -u "$fresh" > "$ip_file"
rm -f "$fresh"
# Merge fresh + saved IPs
{ [ -s "$fresh" ] && cat "$fresh" ; [ -s "$ip_file" ] && cat "$ip_file" ; } | sort -u > "$ip_file.tmp"
mv "$ip_file.tmp" "$ip_file"
local ip_count=$(wc -l < "$ip_file")
if [ "$ip_count" -lt 2 ] ; then
......@@ -222,7 +235,8 @@ expand_volatile_subnets()
fi
done < "$volatile_file"
[ "$added" -gt 0 ] && log "${tag}${label} Added $added covering subnet(s) for volatile IPv6 domains"
rm -rf "$fresh_dir" "$digger"
[ "$added" -gt 0 ] && log "${tag}${label} Added $added covering subnet(s) for volatile IPv6 domains" || true
}
# Allocate a free table number in range 200-250 (step 10)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment