-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_benchmark.sh
More file actions
executable file
·133 lines (112 loc) · 3.8 KB
/
Copy pathrun_benchmark.sh
File metadata and controls
executable file
·133 lines (112 loc) · 3.8 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
#!/bin/bash
# run_benchmark.sh - Quick start script for MCP ASGI Server Benchmark
# Launches both servers and runs comprehensive benchmark
set -e # Exit on any error
echo "🚀 MCP ASGI Server Benchmark Suite - Quick Start"
echo "================================================"
echo "Testing Uvicorn (HTTP/1.1) vs Hypercorn (HTTP/2)"
echo "For DACA Agent Communication Patterns"
echo "================================================"
# Check if uv is available
if ! command -v uv &> /dev/null; then
echo "❌ Error: uv not found. Please install uv first:"
echo " curl -LsSf https://astral.sh/uv/install.sh | sh"
exit 1
fi
# Function to check if port is in use
check_port() {
local port=$1
if lsof -Pi :$port -sTCP:LISTEN -t >/dev/null ; then
return 0 # Port is in use
else
return 1 # Port is free
fi
}
# Function to wait for server to be ready
wait_for_server() {
local url=$1
local name=$2
local max_attempts=10
local attempt=1
echo " Waiting for $name to be ready..."
while [ $attempt -le $max_attempts ]; do
if curl -s -X POST "$url" \
-H "Content-Type: application/json" \
-d '{"jsonrpc": "2.0", "method": "tools/list", "params": {}, "id": "test"}' \
>/dev/null 2>&1; then
echo " ✅ $name is ready!"
return 0
fi
echo " ⏳ Attempt $attempt/$max_attempts - waiting for $name..."
sleep 2
((attempt++))
done
echo " ❌ $name failed to start after $max_attempts attempts"
return 1
}
# Function to cleanup background processes
cleanup() {
echo ""
echo "🧹 Cleaning up background processes..."
if [ ! -z "$UVICORN_PID" ] && kill -0 $UVICORN_PID 2>/dev/null; then
echo " Stopping Uvicorn server (PID: $UVICORN_PID)"
kill $UVICORN_PID
fi
if [ ! -z "$HYPERCORN_PID" ] && kill -0 $HYPERCORN_PID 2>/dev/null; then
echo " Stopping Hypercorn server (PID: $HYPERCORN_PID)"
kill $HYPERCORN_PID
fi
echo "✅ Cleanup complete"
}
# Set trap to cleanup on script exit
trap cleanup EXIT
# Check if ports are already in use
if check_port 8000; then
echo "⚠️ Port 8000 is already in use (expected for Uvicorn)"
echo " If it's not our server, stop it first"
fi
if check_port 8001; then
echo "⚠️ Port 8001 is already in use (expected for Hypercorn)"
echo " If it's not our server, stop it first"
fi
echo ""
echo "📦 1. Installing/checking dependencies..."
uv sync
echo ""
echo "🖥️ 2. Starting servers in background..."
# Start Uvicorn server
echo " Starting Uvicorn server on http://localhost:8000..."
uv run python uvicorn_server.py > uvicorn.log 2>&1 &
UVICORN_PID=$!
echo " Uvicorn started (PID: $UVICORN_PID)"
# Start Hypercorn server
echo " Starting Hypercorn server on http://localhost:8001..."
uv run python hypercorn_server.py > hypercorn.log 2>&1 &
HYPERCORN_PID=$!
echo " Hypercorn started (PID: $HYPERCORN_PID)"
echo ""
echo "⏳ 3. Waiting for servers to be ready..."
# Wait for both servers to be ready
if wait_for_server "http://localhost:8000/mcp/" "Uvicorn" && \
wait_for_server "http://localhost:8001/mcp/" "Hypercorn"; then
echo ""
echo "🚀 4. Running benchmark suite..."
echo ""
# Run the benchmark
uv run python benchmark_client.py
echo ""
echo "✅ Benchmark completed successfully!"
echo ""
echo "📁 Check the following files for detailed results:"
echo " - mcp_benchmark_results_*.json (detailed data)"
echo " - uvicorn.log (Uvicorn server logs)"
echo " - hypercorn.log (Hypercorn server logs)"
else
echo ""
echo "❌ Failed to start servers. Check logs:"
echo " - uvicorn.log"
echo " - hypercorn.log"
exit 1
fi
echo ""
echo "🏁 Benchmark suite completed!"