Feat: Add LAN/WAN simulation to compare_rsync.sh

Added latency simulation support to compare_rsync.sh with:
- Direct latency value: ./compare_rsync.sh 100 1 20 (20ms RTT)
- Preset profiles: ./compare_rsync.sh 100 1 --lan (10ms) or --wan (100ms)
- tc netem integration for network delay simulation
- Clean display of network condition in output

This brings compare_rsync.sh in line with benchmark.sh and
benchmark_comprehensive.sh which already supported latency simulation.

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
This commit is contained in:
Theo Tappe
2026-06-24 12:49:28 +02:00
parent 31b8e890d2
commit 43701a44e6
+117 -3
View File
@@ -1,8 +1,85 @@
# compare_rsync.sh — Compare fastSyncAI performance against rsync
#
# Usage:
# ./compare_rsync.sh [DATA_SIZE_MB] [RUN_COUNT]
#
# Examples:
# ./compare_rsync.sh # 100 MB, 3 runs (default)
# ./compare_rsync.sh 500 # 500 MB, 3 runs
# ./compare_rsync.sh 100 5 # 100 MB, 5 runs
#
# Tests:
# - Small files (many files, 256KB each)
# - Medium files (fewer files, 1-5MB each)
# - Large single file
# - Mixed directory structure
#
# Compares: fastSyncAI (TCP, multi-connection) vs rsync vs rsync with compression
# =============================================================================
set -euo pipefail
# ── Defaults ──────────────────────────────────────────────────────────────
DATA_SIZE_MB=${1:-100}
RUN_COUNT=${2:-3}
PORT=19199
HOST="127.0.0.1"
=======
#!/usr/bin/env bash
# =============================================================================
# compare_rsync.sh — Compare fastSyncAI performance against rsync
#
# Usage:
# ./compare_rsync.sh [DATA_SIZE_MB] [RUN_COUNT] [LATENCY_MS|--lan|--wan]
#
# Examples:
# ./compare_rsync.sh # 100 MB, 3 runs, no latency
# ./compare_rsync.sh 500 # 500 MB, 3 runs, no latency
# ./compare_rsync.sh 100 5 # 100 MB, 5 runs, no latency
# ./compare_rsync.sh 100 1 20 # 100 MB, 1 run, 20ms RTT (LAN-like)
# ./compare_rsync.sh 100 1 100 # 100 MB, 1 run, 100ms RTT (WAN-like)
# ./compare_rsync.sh 100 1 --lan # 100 MB, 1 run, 10ms RTT (LAN preset)
# ./compare_rsync.sh 100 1 --wan # 100 MB, 1 run, 100ms RTT (WAN preset)
#
# Tests:
# - Small files (many files, 256KB each)
# - Medium files (fewer files, 1-5MB each)
# - Large single file
# - Mixed directory structure
#
# Compares: fastSyncAI (TCP, multi-connection) vs rsync vs rsync with compression
#
# Network Presets:
# --lan : 10ms RTT (typical LAN)
# --wan : 100ms RTT (typical WAN)
# =============================================================================
set -euo pipefail
# ── Defaults ──────────────────────────────────────────────────────────────
DATA_SIZE_MB=${1:-100}
RUN_COUNT=${2:-3}
# ── Parse latency argument ────────────────────────────────────────────────
LATENCY_MS=0
if [ $# -ge 3 ]; then
case "${3}" in
--lan) LATENCY_MS=10 ;;
--wan) LATENCY_MS=100 ;;
*)
# Check if it's a numeric value
if [[ "${3}" =~ ^[0-9]+$ ]]; then
LATENCY_MS="${3}"
fi
;;
esac
fi
PORT=19199
HOST="127.0.0.1"=============================================================================
# compare_rsync.sh — Compare fastSyncAI performance against rsync
#
# Usage:
# ./compare_rsync.sh [DATA_SIZE_MB] [RUN_COUNT]
#
# Examples:
@@ -45,12 +122,35 @@ info() { echo -e "${CYAN}▶ $*${RESET}"; }
ok() { echo -e "${GREEN}$*${RESET}"; }
warn() { echo -e "${YELLOW}$*${RESET}"; }
# ── Latency simulation (tc netem) ────────────────────────────────────────
setup_latency() {
if [ "$LATENCY_MS" -gt 0 ]; then
info "Adding ${LATENCY_MS}ms RTT latency to lo via tc netem..."
if ! sudo -n true 2>/dev/null; then
echo -e "${YELLOW}⚠ sudo required for tc netem — enter password if prompted${RESET}"
fi
local half=$(( LATENCY_MS / 2 ))
sudo tc qdisc del dev lo root 2>/dev/null || true
sudo tc qdisc add dev lo root netem delay "${half}ms" || \
die "tc netem failed. Install iproute2 or run without latency argument."
ok "Latency applied (${half}ms one-way = ${LATENCY_MS}ms RTT)"
fi
}
cleanup_latency() {
if [ "$LATENCY_MS" -gt 0 ]; then
sudo tc qdisc del dev lo root 2>/dev/null || true
ok "Latency removed"
fi
}
# ── Sanity checks ──────────────────────────────────────────────────────────
[ -x "$SERVER_BIN" ] || die "Server binary not found: $SERVER_BIN — run 'make' first."
[ -x "$CLIENT_BIN" ] || die "Client binary not found: $CLIENT_BIN — run 'make' first."
command -v rsync >/dev/null 2>&1 || die "rsync not found. Install rsync first."
cleanup() {
cleanup_latency
pkill -f "fastsync_server" 2>/dev/null || true
pkill -f "fastsync_client" 2>/dev/null || true
rm -rf "$TEST_DIR"
@@ -258,9 +358,23 @@ echo -e "${BOLD}╔════════════════════
echo -e "${BOLD}║ fastSyncAI vs rsync — Performance Comparison ║${RESET}"
echo -e "${BOLD}╚══════════════════════════════════════════════════════════════╝${RESET}"
echo ""
echo -e " Data size : ${CYAN}${DATA_SIZE_MB} MB${RESET}"
echo -e " Runs per test : ${CYAN}${RUN_COUNT}${RESET}"
echo -e " Server port : ${CYAN}${PORT}${RESET}"
# Display network condition
if [ "$LATENCY_MS" -gt 0 ]; then
echo -e " Data size : ${CYAN}${DATA_SIZE_MB} MB${RESET}"
echo -e " Runs per test : ${CYAN}${RUN_COUNT}${RESET}"
echo -e " Network : ${CYAN}${LATENCY_MS}ms RTT${RESET}"
echo -e " Server port : ${CYAN}${PORT}${RESET}"
else
echo -e " Data size : ${CYAN}${DATA_SIZE_MB} MB${RESET}"
echo -e " Runs per test : ${CYAN}${RUN_COUNT}${RESET}"
echo -e " Network : ${GREEN}no latency (loopback)${RESET}"
echo -e " Server port : ${CYAN}${PORT}${RESET}"
fi
echo ""
# Setup latency if configured
setup_latency
echo ""
# Collect all results