@@ -94,15 +94,15 @@ cleanup() {
94
94
# Function to start router
95
95
start_router () {
96
96
local log_file=" $LOG_DIR /router.log"
97
-
97
+
98
98
print_status " Starting router with round-robin routing (stress test mode)"
99
-
99
+
100
100
# Create log directory
101
101
mkdir -p " $( dirname " $log_file " ) "
102
-
102
+
103
103
# Set stress test mode
104
104
export VLLM_ROUTER_STRESS_TEST_MODE=true
105
-
105
+
106
106
# Start router with detailed logging
107
107
python3 -m src.vllm_router.app --port " $ROUTER_PORT " \
108
108
--service-discovery static \
@@ -112,10 +112,10 @@ start_router() {
112
112
--routing-logic roundrobin \
113
113
--log-stats \
114
114
--log-stats-interval 5 > " $log_file " 2>&1 &
115
-
115
+
116
116
ROUTER_PID=$!
117
117
print_status " Router started with PID: $ROUTER_PID "
118
-
118
+
119
119
# Wait for router to be ready
120
120
print_status " Waiting for router to be ready..."
121
121
timeout 30 bash -c " until curl -s http://localhost:$ROUTER_PORT /v1/models > /dev/null 2>&1; do sleep 1; done" || {
@@ -131,7 +131,7 @@ start_router() {
131
131
run_stress_test () {
132
132
print_status " Running stress test with Apache Bench"
133
133
print_status " Concurrent: $CONCURRENT , Total: $REQUESTS "
134
-
134
+
135
135
# Create payload file
136
136
local payload_file=" /tmp/stress_payload.json"
137
137
cat > " $payload_file " << EOF
@@ -144,7 +144,7 @@ run_stress_test() {
144
144
"temperature": 0.7
145
145
}
146
146
EOF
147
-
147
+
148
148
# Run Apache Bench
149
149
ab -c " $CONCURRENT " \
150
150
-n " $REQUESTS " \
@@ -153,53 +153,53 @@ EOF
153
153
-H " Authorization: Bearer test" \
154
154
-H " x-user-id: stress-test-user" \
155
155
" http://localhost:$ROUTER_PORT /v1/chat/completions"
156
-
156
+
157
157
# Clean up payload file
158
158
rm -f " $payload_file "
159
-
159
+
160
160
print_status " Stress test completed"
161
-
161
+
162
162
# Small delay to ensure all logs are written
163
163
sleep 2
164
164
}
165
165
166
166
# Function to check round-robin correctness
167
167
check_roundrobin_correctness () {
168
168
local log_file=" $LOG_DIR /router.log"
169
-
169
+
170
170
print_status " Checking round-robin routing correctness..."
171
-
171
+
172
172
if [ ! -f " $log_file " ]; then
173
173
print_error " Router log file not found: $log_file "
174
174
return 1
175
175
fi
176
-
176
+
177
177
# Extract backend routing decisions from logs
178
178
# Look for "Routing request ... to http://localhost:XXXX"
179
179
local backend1_count=$( grep -c " to http://localhost:$BACKEND1_PORT " " $log_file " || echo " 0" )
180
180
local backend2_count=$( grep -c " to http://localhost:$BACKEND2_PORT " " $log_file " || echo " 0" )
181
181
local total_routed=$(( backend1 _count + backend2 _count))
182
-
182
+
183
183
print_status " Round-robin routing results:"
184
184
print_status " Backend localhost:$BACKEND1_PORT : $backend1_count requests"
185
185
print_status " Backend localhost:$BACKEND2_PORT : $backend2_count requests"
186
186
print_status " Total routed: $total_routed requests"
187
-
187
+
188
188
if [ " $total_routed " -eq 0 ]; then
189
189
print_error " No routing decisions found in logs"
190
190
return 1
191
191
fi
192
-
192
+
193
193
# Calculate percentages
194
194
local backend1_pct=$(( backend1 _count * 100 / total_routed))
195
195
local backend2_pct=$(( backend2 _count * 100 / total_routed))
196
-
196
+
197
197
print_status " Backend localhost:$BACKEND1_PORT : ${backend1_pct} %"
198
198
print_status " Backend localhost:$BACKEND2_PORT : ${backend2_pct} %"
199
-
199
+
200
200
# Check if distribution is roughly even (within 20% tolerance)
201
201
local diff=$(( backend1 _pct > backend2 _pct ? backend1 _pct - backend2 _pct : backend2 _pct - backend1 _pct))
202
-
202
+
203
203
if [ " $diff " -le 20 ]; then
204
204
print_status " ✅ Round-robin routing is working correctly (${diff} % difference)"
205
205
return 0
@@ -214,7 +214,7 @@ check_roundrobin_correctness() {
214
214
# Function to show log summary
215
215
show_log_summary () {
216
216
local log_file=" $LOG_DIR /router.log"
217
-
217
+
218
218
if [ -f " $log_file " ]; then
219
219
print_status " Log summary (last 20 lines):"
220
220
tail -20 " $log_file " | sed ' s/^/ /'
292
292
print_error " Test completed but round-robin routing correctness check failed!"
293
293
show_log_summary
294
294
exit 1
295
- fi
295
+ fi
0 commit comments