feat(benchmark): Add UDP mode tests to network benchmark

- Add UDP tests for 1, 2, 4 connections
- UDP tests run on LAN and low-loss scenarios
- Skip UDP tests on high packet loss scenarios (not yet supported)
- Include UDP results in comparison table and best calculation

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
This commit is contained in:
taptap
2026-06-24 21:50:42 +02:00
parent 948542394e
commit 2ce66c0e20
+69 -3
View File
@@ -356,8 +356,55 @@ IFS='|' read -r ms mbs ok <<< "$result"
RSYNCC_RES=("$ms|$mbs|$ok")
[ "$ok" -eq 1 ] && ok "${mbs} MB/s (${ms}ms)" || warn "${mbs} MB/s (${ms}ms) FAILED"
# Cleanup network
cleanup_network
# UDP tests - only for scenarios without packet loss (UDP doesn't handle loss yet)
if [ "$PACKET_LOSS" = "0%" ] || [ "$PACKET_LOSS" = "0.1%" ]; then
# Re-setup network for UDP tests (UDP doesn't work with tc netem packet loss)
cleanup_network
setup_network
declare -a UDP_RES
UDP_LABELS=("fastSyncAI UDP 1 conn" "fastSyncAI UDP 2 conn" "fastSyncAI UDP 4 conn")
UDP_CONN_COUNTS=(1 2 4)
info "Testing UDP mode (${SCENARIO_NAME})..."
for i in "${!UDP_CONN_COUNTS[@]}"; do
n=${UDP_CONN_COUNTS[$i]}
echo -n " ${UDP_LABELS[$i]}... "
local dst="$DST_DIR_BASE/udp_${n}"
local port=$((FASTSYNC_PORT + 100 + n))
rm -rf "$dst"
mkdir -p "$dst"
"$SERVER_BIN" -p "$port" -d "$dst" >/dev/null 2>&1 &
local spid=$!
sleep 1
local output
output=$(timeout 600 "$CLIENT_BIN" -h "$HOST" -p "$port" -s "$SRC_DIR" -n "$n" -u 2>&1) || true
local ms=$(echo "$output" | grep -oP 'ms=\K[0-9.]+' || echo "0")
local mbs=$(echo "$output" | grep -oP 'throughput_mbs=\K[0-9.]+' || echo "0")
local ok=1
verify "$SRC_DIR" "$dst" || ok=0
echo "${ms}|${mbs}|${ok}"
UDP_RES+=("${ms}|${mbs}|${ok}")
[ "$ok" -eq 1 ] && ok "${mbs} MB/s (${ms}ms)" || warn "${mbs} MB/s (${ms}ms) FAILED"
kill "$spid" 2>/dev/null || true
wait "$spid" 2>/dev/null || true
sync
sleep 1
rm -rf "$dst"
done
cleanup_network
else
warn "Skipping UDP tests (packet loss scenarios not yet supported for UDP)"
fi
# Re-setup network for final TCP results display
setup_network
echo ""
echo -e "${BOLD}═══════════════════════════════════════════════════════════════════════════╗${RESET}"
@@ -369,7 +416,7 @@ echo ""
# Calculate max for scaling
calc_max() {
local max=0
for res in "${FS_RES[@]}" "${RSYNC_RES[@]}" "${RSYNCC_RES[@]}"; do
for res in "${FS_RES[@]}" "${RSYNC_RES[@]}" "${RSYNCC_RES[@]}" "${UDP_RES[@]:-}"; do
local mbs=$(echo "$res" | cut -d'|' -f2)
local int=$(echo "$mbs" | awk '{printf "%d", $1+0}')
[ "$int" -gt "$max" ] 2>/dev/null && max=$int
@@ -389,6 +436,16 @@ for i in "${!FS_RES[@]}"; do
printf " %-22s %-10s %-10s %s %s\n" "${FS_LABELS[$i]}" "$ms" "$mbs" "$bar" "$v"
done
# UDP results
if [ ${#UDP_RES[@]} -gt 0 ]; then
for i in "${!UDP_RES[@]}"; do
IFS='|' read -r ms mbs ok <<< "${UDP_RES[$i]}"
bar=$(draw_bar "$mbs" "$MAX_MBS")
v=$([ "$ok" -eq 1 ] && echo "✓" || echo "✗")
printf " %-22s %-10s %-10s %s %s\n" "${UDP_LABELS[$i]}" "$ms" "$mbs" "$bar" "$v"
done
fi
IFS='|' read -r ms mbs ok <<< "${RSYNC_RES[0]}"
bar=$(draw_bar "$mbs" "$MAX_MBS")
v=$([ "$ok" -eq 1 ] && echo "✓" || echo "✗")
@@ -415,6 +472,15 @@ for i in "${!FS_RES[@]}"; do
done
best_label="${FS_LABELS[$best_idx]}"
# Also check UDP results
if [ ${#UDP_RES[@]} -gt 0 ]; then
for i in "${!UDP_RES[@]}"; do
this_mbs=$(echo "${UDP_RES[$i]}" | cut -d'|' -f2 | awk '{printf "%d", $1+0}')
[ "$this_mbs" -gt "$best_mbs" ] && best_mbs=$this_mbs && best_idx=$i && best_is_udp=1
done
[ "$best_is_udp" = "1" ] && best_label="${UDP_LABELS[$best_idx]}"
fi
IFS='|' read -r rs_ms rs_mbs rs_ok <<< "${RSYNC_RES[0]}"
rs_mbs_int=$(echo "$rs_mbs" | awk '{printf "%d", $1+0}')