Repository navigation
Expand file tree
/
Copy pathrun_experiments.sh
More file actions
executable file
Β·159 lines (140 loc) Β· 7.9 KB
/
Copy pathrun_experiments.sh
File metadata and controls
executable file
Β·159 lines (140 loc) Β· 7.9 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
#!/bin/bash
# run_experiments.sh
# Runs all four baselines serially. For each:
# 1. Start ./server <mode>
# 2. Start resource_monitor.py
# 3. Run load_tester.py (foreground, wait for completion)
# 4. Archive all logs into logs/exp_<mode>_<timestamp>/
#
# Usage:
# ./run_experiments.sh # run all 4 modes
# ./run_experiments.sh ewma # run a single mode
#
# CSCI 599: Network Systems for Cloud Computing
# University of Southern California
set -e
cd "$(dirname "$0")"
# ββ Colour helpers ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
RED='\033[0;31m'; GREEN='\033[0;32m'; YELLOW='\033[1;33m'; CYAN='\033[0;36m'; NC='\033[0m'
info() { echo -e "${CYAN}[INFO]${NC} $*"; }
success() { echo -e "${GREEN}[OK]${NC} $*"; }
warn() { echo -e "${YELLOW}[WARN]${NC} $*"; }
error() { echo -e "${RED}[ERR]${NC} $*"; }
# ββ Build βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
info "Building server..."
make -s
success "Build OK"
# ββ Experiment runner βββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
# run_one <label> <server_args...>
# label: directory-safe name (e.g. "ewma", "static_15")
# server_args: args passed to ./server (e.g. "static 15")
run_one() {
local label="$1"; shift
local server_args="$@" # remaining args go to ./server
echo ""
echo "ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ"
info "Experiment: ${label} (./server ${server_args})"
echo "ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ"
local exp_ts; exp_ts=$(date +%Y%m%d_%H%M%S)
local exp_dir="logs/exp_${label}_${exp_ts}"
mkdir -p "$exp_dir"
# Kill ALL lingering gateway server processes by exact binary name.
# pkill -x matches the process name field exactly (not cmdline substring),
# so it only kills our compiled 'server' binary, not vscode or other tools.
pkill -x server 2>/dev/null || true; sleep 1
# Clean stale sockets from previous runs
rm -f /tmp/faas_worker_*.sock /tmp/faas_template_ctrl.sock /tmp/faas_arima.sock
# Remove previous server log for this mode (avoid confusion with archived copy)
rm -f "logs/server_${label}.log"
# ββ Start server ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
info "Starting server (mode=${label})..."
./server $server_args &
local SERVER_PID=$!
# Wait until template process signals READY (appears in server log).
# Pillow import takes ~800ms; poll for up to 10s.
local ready=0
for i in $(seq 1 20); do
sleep 0.5
if ! kill -0 "$SERVER_PID" 2>/dev/null; then
error "Server exited unexpectedly for mode '${label}'."
return 1
fi
local log_file="logs/server_${label}.log"
if [ -f "$log_file" ] && grep -q "READY\|starting\|Pre-warming" "$log_file" 2>/dev/null; then
ready=1; break
fi
done
if [ "$ready" -eq 0 ]; then
warn "Server did not signal ready in 10s β proceeding anyway."
fi
# Extra buffer: let workers settle after READY
sleep 1
success "Server running (pid=${SERVER_PID})"
# ββ Start resource monitor ββββββββββββββββββββββββββββββββββββββββββββββββ
local resource_csv="${exp_dir}/resource.csv"
info "Starting resource monitor β ${resource_csv}"
python3 resource_monitor.py "$resource_csv" > "${exp_dir}/resource_monitor_output.txt" 2>&1 &
local MONITOR_PID=$!
sleep 0.5 # give monitor time to find the server process
# ββ Run load tester βββββββββββββββββββββββββββββββββββββββββββββββββββββββ
info "Running load_tester.py..."
local load_tester_log="${exp_dir}/load_tester_output.txt"
# Use a sentinel file to reliably find the test log created during this run
local sentinel; sentinel=$(mktemp logs/.sentinel.XXXXXX)
python3 load_tester.py 2>&1 | tee "$load_tester_log"
success "Load test complete"
# ββ Stop monitor and server βββββββββββββββββββββββββββββββββββββββββββββββ
kill "$MONITOR_PID" 2>/dev/null; wait "$MONITOR_PID" 2>/dev/null || true
kill "$SERVER_PID" 2>/dev/null; wait "$SERVER_PID" 2>/dev/null || true
success "Server and monitor stopped"
# ββ Archive logs ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
# Server log β mode label matches the log filename exactly
# (e.g. label=ewma β server_ewma.log; label=static_15 β server_static_15.log)
local server_log="logs/server_${label}.log"
if [ -f "$server_log" ]; then
mv "$server_log" "${exp_dir}/server.log"
else
warn "Server log not found: ${server_log}"
fi
# Find the test_*.log created after the sentinel file
local test_log
test_log=$(find logs -maxdepth 1 -name "test_*.log" -newer "$sentinel" 2>/dev/null \
| sort | tail -1)
rm -f "$sentinel"
if [ -n "$test_log" ] && [ -f "$test_log" ]; then
mv "$test_log" "${exp_dir}/test.log"
else
warn "Test log not found for mode '${label}'"
fi
success "Archived β ${exp_dir}/"
echo " server.log test.log resource.csv load_tester_output.txt"
}
# ββ Main ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
OVERALL_TS=$(date +%Y%m%d_%H%M%S)
if [ $# -gt 0 ]; then
# Single mode passed as argument
mode="$1"
case "$mode" in
ewma) run_one "ewma" ewma ;;
ewma_adaptive) run_one "ewma_adaptive" ewma_adaptive ;;
reactive) run_one "reactive" reactive ;;
static) run_one "static_15" static 15 ;;
arima) run_one "arima" arima ;;
*) error "Unknown mode '$mode'. Valid: ewma ewma_adaptive reactive static arima"; exit 1 ;;
esac
else
# Run all five serially
run_one "ewma" ewma
run_one "ewma_adaptive" ewma_adaptive
run_one "reactive" reactive
run_one "static_15" static 15
run_one "arima" arima
fi
# ββ Final summary βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
echo ""
echo "ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ"
success "All experiments complete. Results:"
ls -d logs/exp_*/ 2>/dev/null | sort | while read d; do
echo " ${d}"
done
echo "ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ"