Skip to content

Commit 944bd10

Browse files
committed
build(benchmark): add preload variant and update suite for 5 servers
1 parent 7a34136 commit 944bd10

File tree

2 files changed

+47
-26
lines changed

2 files changed

+47
-26
lines changed

benchmark/bench.sh

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
# =============================================================================
33
# bench.sh — Static file server benchmark suite
44
#
5-
# Spins up static-web, nginx, bun, and caddy via docker-compose, runs
6-
# bombardier against each one serving /index.html, prints a ranked summary,
7-
# then tears everything down.
5+
# Spins up static-web (default), static-web (preload), nginx, bun, and caddy
6+
# via docker-compose, runs bombardier against each one serving /index.html,
7+
# prints a ranked summary, then tears everything down.
88
#
99
# Usage:
1010
# ./benchmark/bench.sh [OPTIONS]
@@ -70,17 +70,17 @@ check_deps() {
7070
}
7171

7272
# ---------- servers (parallel indexed arrays — bash 3 compatible) ------------
73-
SERVER_NAMES=( "static-web" "nginx" "bun" "caddy" )
74-
SERVER_URLS=( "http://localhost:8001/index.html" "http://localhost:8002/index.html" "http://localhost:8003/index.html" "http://localhost:8004/index.html" )
75-
SERVER_COUNT=4
73+
SERVER_NAMES=( "static-web" "nginx" "bun" "caddy" "static-web-preload" )
74+
SERVER_URLS=( "http://localhost:8001/index.html" "http://localhost:8002/index.html" "http://localhost:8003/index.html" "http://localhost:8004/index.html" "http://localhost:8005/index.html" )
75+
SERVER_COUNT=5
7676

7777
# ---------- helpers ----------------------------------------------------------
7878
wait_for_server() {
7979
local name=$1
8080
local url=$2
8181
local max=30
8282
local i=0
83-
printf " Waiting for %-12s" "${name}..."
83+
printf " Waiting for %-22s" "${name}..."
8484
while ! curl -sf -o /dev/null "$url" 2>/dev/null; do
8585
sleep 1
8686
i=$((i + 1))
@@ -124,9 +124,9 @@ main() {
124124
mkdir -p "$RESULTS_DIR"
125125

126126
echo ""
127-
echo -e "${BOLD}╔══════════════════════════════════════════════════════════╗${RESET}"
128-
echo -e "${BOLD}║ Static Web Server Benchmark Suite ║${RESET}"
129-
echo -e "${BOLD}╚══════════════════════════════════════════════════════════╝${RESET}"
127+
echo -e "${BOLD}╔════════════════════════════════════════════════════════════════════${RESET}"
128+
echo -e "${BOLD} Static Web Server Benchmark Suite ${RESET}"
129+
echo -e "${BOLD}╚════════════════════════════════════════════════════════════════════${RESET}"
130130
echo ""
131131

132132
if [ -n "$DURATION" ]; then
@@ -158,7 +158,7 @@ main() {
158158
echo -e "${BOLD}→ Warming up (10 000 requests each)...${RESET}"
159159
i=0
160160
while [ $i -lt $SERVER_COUNT ]; do
161-
printf " %-12s" "${SERVER_NAMES[$i]}"
161+
printf " %-22s" "${SERVER_NAMES[$i]}"
162162
bombardier -c "$CONNECTIONS" -n 10000 --print i "${SERVER_URLS[$i]}" >/dev/null 2>&1
163163
echo -e " ${GREEN}done${RESET}"
164164
i=$((i + 1))
@@ -199,7 +199,12 @@ main() {
199199

200200
# ---- rank by req/s (simple insertion sort, bash 3 compatible) -------------
201201
# Build a sorted index array (descending by RPS)
202-
SORTED_IDX=(0 1 2 3)
202+
SORTED_IDX=()
203+
i=0
204+
while [ $i -lt $SERVER_COUNT ]; do
205+
SORTED_IDX[$i]=$i
206+
i=$((i + 1))
207+
done
203208
n=${#SORTED_IDX[@]}
204209
i=1
205210
while [ $i -lt $n ]; do
@@ -223,12 +228,12 @@ main() {
223228

224229
best_rps=${RPS[${SORTED_IDX[0]}]}
225230

226-
echo -e "${BOLD}╔══════════════════════════════════════════════════════════╗${RESET}"
227-
echo -e "${BOLD}║ Results Summary ║${RESET}"
228-
echo -e "${BOLD}╠══════════════════════════════════════════════════════════╣${RESET}"
229-
printf "${BOLD}║ %-4s %-14s %12s %10s %10s ║${RESET}\n" \
231+
echo -e "${BOLD}╔════════════════════════════════════════════════════════════════════${RESET}"
232+
echo -e "${BOLD} Results Summary ${RESET}"
233+
echo -e "${BOLD}╠════════════════════════════════════════════════════════════════════${RESET}"
234+
printf "${BOLD}║ %-4s %-22s %12s %10s %10s ║${RESET}\n" \
230235
"#" "Server" "Req/sec" "p50 lat" "p99 lat"
231-
echo -e "${BOLD}╠══════════════════════════════════════════════════════════╣${RESET}"
236+
echo -e "${BOLD}╠════════════════════════════════════════════════════════════════════${RESET}"
232237

233238
rank=1
234239
for idx in "${SORTED_IDX[@]}"; do
@@ -244,15 +249,15 @@ main() {
244249
elif [ "$rank" -eq 3 ]; then
245250
colour="$YELLOW"; medal="3rd"
246251
else
247-
colour="$RESET"; medal="4th"
252+
colour="$RESET"; medal="${rank}th"
248253
fi
249254

250-
printf "${colour}║ %-4s %-14s %12s %10s %10s ║${RESET}\n" \
255+
printf "${colour}║ %-4s %-22s %12s %10s %10s ║${RESET}\n" \
251256
"$medal" "$name" "$rps" "$p50" "$p99"
252257
rank=$((rank + 1))
253258
done
254259

255-
echo -e "${BOLD}╚══════════════════════════════════════════════════════════╝${RESET}"
260+
echo -e "${BOLD}╚════════════════════════════════════════════════════════════════════${RESET}"
256261
echo ""
257262
echo -e " Full results saved to: ${CYAN}${RESULTS_DIR}/${RESET}"
258263
echo ""

benchmark/docker-compose.benchmark.yml

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11
# docker-compose.benchmark.yml
2-
# Spins up four static file servers all serving the same public/index.html.
2+
# Spins up five static file servers all serving the same public/index.html.
33
# Run via: make benchmark (or ./benchmark/bench.sh directly)
44
#
55
# Port map:
6-
# 8001 → static-web (built from source)
6+
# 8001 → static-web (default config, built from source)
77
# 8002 → nginx
88
# 8003 → bun
99
# 8004 → caddy
10+
# 8005 → static-web-preload (--preload --gc-percent 400)
1011

1112
name: static-web-benchmark
1213

1314
services:
1415

1516
# -------------------------------------------------------------------------
16-
# static-web — our server, built from source
17+
# static-web — our server, default config (baseline)
1718
# -------------------------------------------------------------------------
1819
static-web:
1920
build:
@@ -26,9 +27,6 @@ services:
2627
environment:
2728
- SW_ROOT=/public
2829
- SW_ADDR=0.0.0.0:8080
29-
# Raise the GC target ratio — after warmup the cache is fully populated
30-
# and allocation rate is very low, so running GC less often is a win.
31-
- GOGC=400
3230
# Ensure Go uses all available CPUs (explicit, matches container quota).
3331
- GOMAXPROCS=0
3432
restart: unless-stopped
@@ -69,3 +67,21 @@ services:
6967
- ../public:/www:ro
7068
- ./Caddyfile:/etc/caddy/Caddyfile:ro
7169
restart: unless-stopped
70+
71+
# -------------------------------------------------------------------------
72+
# static-web-preload — our server with preload + GC tuning (production mode)
73+
# -------------------------------------------------------------------------
74+
static-web-preload:
75+
build:
76+
context: ..
77+
dockerfile: benchmark/Dockerfile.static-web
78+
ports:
79+
- "8005:8080"
80+
volumes:
81+
- ../public:/public:ro
82+
environment:
83+
- SW_ROOT=/public
84+
- SW_ADDR=0.0.0.0:8080
85+
- GOMAXPROCS=0
86+
command: ["static-web", "--quiet", "--no-compress", "--preload", "--gc-percent", "400", "/public"]
87+
restart: unless-stopped

0 commit comments

Comments
 (0)