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 ----------------------------------------------------------
7878wait_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 " "
0 commit comments