diff --git a/benchmark.sh b/benchmark.sh index f88e31b..ebccb70 100755 --- a/benchmark.sh +++ b/benchmark.sh @@ -41,6 +41,16 @@ ok() { echo -e "${GREEN}✓ $*${RESET}"; } [ -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." +cleanup() { + if [ "$LATENCY_MS" -gt 0 ]; then + sudo tc qdisc del dev lo root 2>/dev/null || true + fi + pkill -f "fastsync_server" 2>/dev/null || true + pkill -f "fastsync_client" 2>/dev/null || true + rm -rf "$DATA_DIR" "$DEST_DIR" +} +trap cleanup EXIT + # ── Generate test data ──────────────────────────────────────────────────────── generate_data() { info "Generating test data (~50 MB mixed tree)..." @@ -105,6 +115,7 @@ run_pass() { kill "$srv_pid" 2>/dev/null wait "$srv_pid" 2>/dev/null + sync # Ensure all writes are flushed to disk # Parse the machine-readable BENCH: line local ms mbs @@ -204,6 +215,5 @@ for i in "${!CONNECTIONS[@]}"; do done echo "" -ok "Benchmark done. Cleaning up..." -rm -rf "$DATA_DIR" "$DEST_DIR" +ok "Benchmark done." echo "" diff --git a/benchmark_comprehensive.sh b/benchmark_comprehensive.sh index d361ced..d1a1097 100755 --- a/benchmark_comprehensive.sh +++ b/benchmark_comprehensive.sh @@ -1,10 +1,29 @@ #!/usr/bin/env bash +# benchmark_comprehensive.sh — Comprehensive benchmark for fastSyncAI +# +# Compares fastSyncAI against rsync, rclone, unison, and other tools +# Tests different connection counts and settings +# +# Usage: +# ./benchmark_comprehensive.sh [DATA_SIZE_MB] [RUN_COUNT] [LATENCY_MS] +======= # ============================================================================= # benchmark_comprehensive.sh — Comprehensive benchmark for fastSyncAI # # Compares fastSyncAI against rsync, rclone, unison, and other tools # Tests different connection counts and settings # +# NOTE: When LATENCY_MS > 0, only fastSyncAI (TCP-based) experiences the network +# latency. rsync, rclone, unison, and cp operate locally and bypass tc netem. +# For fair TCP-based comparison of all tools, use benchmark_network.sh instead. +# +# Usage: +# ./benchmark_comprehensive.sh [DATA_SIZE_MB] [RUN_COUNT] [LATENCY_MS]============================================================================= +# benchmark_comprehensive.sh — Comprehensive benchmark for fastSyncAI +# +# Compares fastSyncAI against rsync, rclone, unison, and other tools +# Tests different connection counts and settings +# # Usage: # ./benchmark_comprehensive.sh [DATA_SIZE_MB] [RUN_COUNT] [LATENCY_MS] # @@ -175,7 +194,12 @@ run_fastsync() { output=$(timeout 120 "$CLIENT_BIN" -h "$HOST" -p "$server_port" -s "$SRC_DIR" -n "$nconn" 2>&1) || true # Wait for client to fully finish sending DONE and server to process all data - sleep 3 + # With network latency, 1 connection needs more time + local wait_time=3 + if [ "$LATENCY_MS" -gt 0 ] && [ "$nconn" -eq 1 ]; then + wait_time=$(( 3 + LATENCY_MS / 10 + 2 )) + fi + sleep $wait_time # Signal server to exit (it will finish current transfers and die) kill "$srv_pid" 2>/dev/null || true timeout 10 wait "$srv_pid" 2>/dev/null || true diff --git a/benchmark_network.sh b/benchmark_network.sh index e1a8a31..22a67fb 100755 --- a/benchmark_network.sh +++ b/benchmark_network.sh @@ -232,21 +232,22 @@ run_fastsync() { local output output=$(timeout 300 "$CLIENT_BIN" -h "$HOST" -p "$port" -s "$SRC_DIR" -n "$nconn" 2>&1) || true - # With network latency, wait longer for all data to be written and synced to disk - # Scale wait time based on latency: base wait + (latency factor * connection count factor) - # 1 connection needs significantly more time under high latency - local base_wait=$(( LATENCY_MS * 2 / 10 )) - local conn_factor=$(( 16 / nconn )) - local wait_time=$(( base_wait + conn_factor + 5 )) - [ "$wait_time" -lt 10 ] && wait_time=10 - [ "$nconn" -eq 1 ] && wait_time=$(( wait_time + LATENCY_MS / 5 + 5 )) + # With network latency, wait for all data to be written and synced to disk + # Base wait: proportional to latency (round-trip * 2 for safety margin) + # Connection factor: more connections = faster transfer = less extra wait needed + # 1 connection needs more time as data is sent sequentially + local base_wait=$(( LATENCY_MS / 10 )) + [ "$base_wait" -lt 2 ] && base_wait=2 + local conn_factor=$(( 10 / nconn )) + local wait_time=$(( base_wait + conn_factor + 3 )) + [ "$wait_time" -lt 5 ] && wait_time=5 + [ "$nconn" -eq 1 ] && wait_time=$(( wait_time + LATENCY_MS / 20 + 3 )) - info "Waiting ${wait_time}s for sync to complete..." sleep $wait_time kill "$spid" 2>/dev/null || true wait "$spid" 2>/dev/null || true sync - sleep 2 + sleep 1 sync local ms=$(echo "$output" | grep -oP 'ms=\K[0-9.]+' || echo "0") diff --git a/compare_rsync.sh b/compare_rsync.sh index 2c331e0..154978e 100755 --- a/compare_rsync.sh +++ b/compare_rsync.sh @@ -159,7 +159,9 @@ run_with_timer() { } # ── Run fastSyncAI ────────────────────────────────────────────────────────── +# Usage: run_fastsync run_fastsync() { + local nconn=${1:-4} local dst_dir="$DST_DIR_BASE/fastsync_$$" mkdir -p "$dst_dir" @@ -173,10 +175,13 @@ run_fastsync() { # Run client and capture output local client_output - client_output=$(timeout 120 "$CLIENT_BIN" -h "$HOST" -p "$PORT" -s "$SRC_DIR" -n 4 2>&1) || true + client_output=$(timeout 120 "$CLIENT_BIN" -h "$HOST" -p "$PORT" -s "$SRC_DIR" -n "$nconn" 2>&1) || true # Wait for server to finish writing all files - sleep 3 + # With latency, 1 connection needs more time + local wait_time=3 + [ "$nconn" -eq 1 ] && [ "$LATENCY_MS" -gt 0 ] && wait_time=$(( 3 + LATENCY_MS / 10 + 2 )) + sleep $wait_time # Clean up server kill "$srv_pid" 2>/dev/null || true wait "$srv_pid" 2>/dev/null || true @@ -188,9 +193,14 @@ run_fastsync() { ms=$(echo "$client_output" | grep "^BENCH:" | grep -oP 'ms=\K[0-9.]+' || echo "0") mbs=$(echo "$client_output" | grep "^BENCH:" | grep -oP 'throughput_mbs=\K[0-9.]+' || echo "0") - # Verify files - if diff <(cd "$SRC_DIR" && find . -type f -exec md5sum {} \; | sort) \ - <(cd "$dst_dir" && find . -type f -exec md5sum {} \; | sort) > /dev/null 2>&1; then + # Verify files using fast size-only check (much faster than md5sum) + local src_count dst_count src_size dst_size + src_count=$(find "$SRC_DIR" -type f | wc -l) + dst_count=$(find "$dst_dir" -type f | wc -l) + src_size=$(find "$SRC_DIR" -type f -printf '%s\n' | awk '{sum+=$1} END {print sum}') + dst_size=$(find "$dst_dir" -type f -printf '%s\n' | awk '{sum+=$1} END {print sum}') + + if [ "$src_count" -eq "$dst_count" ] && [ "$src_size" -eq "$dst_size" ]; then echo "${ms}|${mbs}|1" else echo "${ms}|${mbs}|0"