-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_load_balancing.sh
More file actions
executable file
·76 lines (57 loc) · 2.26 KB
/
test_load_balancing.sh
File metadata and controls
executable file
·76 lines (57 loc) · 2.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/bin/bash
# Test script to verify load balancing across multiple processes
# This script sends multiple HTTP requests through the proxy and checks
# if they are distributed across different PIDs
echo "🧪 Testing load balancing across proxy processes..."
# Start the proxy in background
echo "🚀 Starting proxy in multi-process mode..."
./target/release/rust-forward-proxy &
PROXY_PID=$!
# Wait for proxy to start
sleep 3
echo "📊 Sending test requests through proxy..."
# Send 100 requests through the proxy and capture the log output
for i in {1..100}; do
curl -s -x http://127.0.0.1:80 http://httpbin.org/get > /dev/null 2>&1 &
if [ $((i % 20)) -eq 0 ]; then
echo " Sent $i requests..."
fi
done
# Wait for all requests to complete
wait
echo "⏱️ Waiting 5 seconds for requests to process..."
sleep 5
echo "📈 Analyzing PID distribution from logs..."
# Analyze the PID distribution in the logs
if [ -f "logs/proxy.log" ]; then
echo "🔍 PID distribution analysis:"
echo " Process distribution (requests per PID):"
# Extract unique PIDs and count their requests
grep "✅.*INTERCEPTED\|✅.*completed" logs/proxy.log | \
grep -o "PID:[0-9]*" | \
sort | uniq -c | sort -nr | \
head -10 | \
while read count pid; do
echo " $pid: $count requests"
done
echo ""
# Check if requests are distributed across multiple processes
unique_pids=$(grep "✅.*INTERCEPTED\|✅.*completed" logs/proxy.log | \
grep -o "PID:[0-9]*" | sort -u | wc -l | tr -d ' ')
total_requests=$(grep "✅.*INTERCEPTED\|✅.*completed" logs/proxy.log | wc -l | tr -d ' ')
echo "📊 Load balancing summary:"
echo " Total unique processes handling requests: $unique_pids"
echo " Total requests processed: $total_requests"
if [ "$unique_pids" -gt 1 ]; then
echo " ✅ SUCCESS: Load balancing is working - requests distributed across $unique_pids processes!"
else
echo " ❌ ISSUE: All requests handled by single process - load balancing not working"
fi
else
echo "❌ No log file found - cannot analyze load distribution"
fi
# Clean up
echo "🧹 Stopping proxy..."
kill $PROXY_PID
wait $PROXY_PID 2>/dev/null
echo "✅ Test completed!"