-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrun_all.sh
More file actions
executable file
·196 lines (163 loc) · 5.58 KB
/
Copy pathrun_all.sh
File metadata and controls
executable file
·196 lines (163 loc) · 5.58 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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
#!/bin/bash
# Run all benchmark servers and execute benchmark
# Supports both Docker and local development modes
set -e
cd "$(dirname "$0")"
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# Mode selection
USE_DOCKER=false
if [ "$1" = "--docker" ]; then
USE_DOCKER=true
shift
fi
# Load environment variables
if [ -f config.env ]; then
export $(cat config.env | grep -v '^#' | xargs)
fi
echo -e "${GREEN}=== Framework Benchmark ===${NC}"
echo ""
# Check if bombardier is installed
if ! command -v bombardier &> /dev/null; then
echo -e "${RED}ERROR: bombardier not found${NC}"
echo "Install with: go install github.com/codesenberg/bombardier@latest"
exit 1
fi
if [ "$USE_DOCKER" = true ]; then
echo -e "${YELLOW}Mode: Docker (Sequential - one framework at a time)${NC}"
echo ""
# Check if docker compose is available
if ! docker compose version &> /dev/null; then
echo -e "${RED}ERROR: docker compose not found${NC}"
echo "Install Docker Desktop (includes Docker Compose V2)"
exit 1
fi
# Ensure framework Docker image is built
echo -e "${YELLOW}Ensuring framework Docker image is built...${NC}"
if ! docker image inspect benchmark-framework:latest &> /dev/null; then
echo "Building benchmark-framework:latest..."
docker build -t benchmark-framework:latest .
else
echo "Image benchmark-framework:latest already exists"
fi
echo ""
# Only start PostgreSQL (frameworks will be started sequentially by bench.py)
echo -e "${YELLOW}Starting PostgreSQL...${NC}"
docker compose up -d postgres
# Wait for PostgreSQL to be healthy
echo ""
echo -e "${YELLOW}Waiting for PostgreSQL to be ready...${NC}"
until docker compose exec -T postgres pg_isready -U benchmark 2>/dev/null; do
sleep 1
done
echo -e "${GREEN}PostgreSQL is ready${NC}"
# Cleanup function for Docker
cleanup() {
echo -e "\n${YELLOW}Stopping all Docker services...${NC}"
docker compose down
echo -e "${GREEN}Cleanup complete${NC}"
}
trap cleanup EXIT INT TERM
else
echo -e "${YELLOW}Mode: Local Development${NC}"
echo ""
# PID file to track servers
PID_FILE=".benchmark_pids"
cleanup() {
echo -e "\n${YELLOW}Stopping servers...${NC}"
if [ -f "$PID_FILE" ]; then
while read pid; do
if kill -0 "$pid" 2>/dev/null; then
kill "$pid" 2>/dev/null || true
fi
done < "$PID_FILE"
rm -f "$PID_FILE"
fi
echo -e "${GREEN}Cleanup complete${NC}"
}
trap cleanup EXIT INT TERM
# Clear old PIDs
rm -f "$PID_FILE"
# Start FastAPI
echo -e "${YELLOW}Starting FastAPI on port 9031...${NC}"
uv run uvicorn fastapi_app:app --host 0.0.0.0 --port 9031 --workers 1 --no-access-log &
echo $! >> "$PID_FILE"
# Start Litestar
echo -e "${YELLOW}Starting Litestar on port 9041...${NC}"
uv run litestar run --host 0.0.0.0 --port 9041 &
echo $! >> "$PID_FILE"
# Start Django Ninja
echo -e "${YELLOW}Starting Django Ninja on port 9051...${NC}"
DJANGO_SETTINGS_MODULE=django_project.settings_ninja uv run python manage.py runserver 0.0.0.0:9051 &
echo $! >> "$PID_FILE"
# Start Django Bolt
echo -e "${YELLOW}Starting Django Bolt on port 9001...${NC}"
DJANGO_SETTINGS_MODULE=django_project.settings_bolt uv run python manage.py runbolt --host 0.0.0.0 --port 9001 --processes 1 &
echo $! >> "$PID_FILE"
# Start Django REST Framework
echo -e "${YELLOW}Starting Django REST Framework on port 9021...${NC}"
DJANGO_SETTINGS_MODULE=django_project.settings_drf uv run python manage.py runserver 0.0.0.0:9021 &
echo $! >> "$PID_FILE"
# Wait for servers to start
echo ""
echo -e "${YELLOW}Waiting for servers to start...${NC}"
sleep 5
fi
# Verify servers are running (skip for sequential Docker mode)
if [ "$USE_DOCKER" = false ]; then
check_server() {
local name=$1
local port=$2
local prefix=$3
if curl -s "http://127.0.0.1:${port}${prefix}/json-1k" > /dev/null 2>&1; then
echo -e " ${GREEN}✓${NC} $name (port $port)"
return 0
else
echo -e " ${RED}✗${NC} $name (port $port) - NOT RESPONDING"
return 1
fi
}
echo ""
echo "Checking servers:"
all_ok=true
check_server "FastAPI" 9031 "" || all_ok=false
check_server "Litestar" 9041 "" || all_ok=false
check_server "Django Ninja" 9051 "/ninja" || all_ok=false
check_server "Django Bolt" 9001 "" || all_ok=false
check_server "Django DRF" 9021 "/drf" || all_ok=false
if [ "$all_ok" = false ]; then
echo ""
echo -e "${RED}Some servers failed to start. Check the logs above.${NC}"
exit 1
fi
echo ""
echo -e "${GREEN}All servers running!${NC}"
echo ""
fi
# Run benchmark
echo -e "${YELLOW}Running benchmark...${NC}"
echo ""
if [ "$USE_DOCKER" = true ]; then
# Docker mode: Use sequential mode for fair comparison
uv run python bench.py --docker --sequential "$@"
else
# Local mode: All servers already running
uv run python bench.py "$@"
fi
echo ""
echo -e "${GREEN}Benchmark complete!${NC}"
# Generate visualizations
echo ""
echo -e "${YELLOW}Generating visualizations...${NC}"
if [ "$USE_DOCKER" = true ]; then
uv run python visualize.py --docker
else
uv run python visualize.py
fi
echo ""
echo -e "${GREEN}Visualizations complete!${NC}"
echo -e "Results saved to: BENCHMARK_RESULTS.md"
echo -e "Graphs saved to: graphs/"