From 5c9ccd99638b069190bc5944e6f1ff51642b1441 Mon Sep 17 00:00:00 2001 From: yusing Date: Sat, 3 Jan 2026 00:57:50 +0800 Subject: [PATCH] refactor(benchmark): benchmark script functionality and fairness --- Makefile | 6 +++++- dev.compose.yml | 12 ++++++++++-- scripts/benchmark.sh | 20 ++++++++++++++------ 3 files changed, 29 insertions(+), 9 deletions(-) diff --git a/Makefile b/Makefile index 32209f32..627c10f9 100755 --- a/Makefile +++ b/Makefile @@ -124,7 +124,11 @@ dev-build: build docker compose -f dev.compose.yml up -t 0 -d app --force-recreate benchmark: - @docker compose -f dev.compose.yml up -d --force-recreate whoami godoxy traefik caddy nginx + @if [ -z "$(TARGET)" ]; then \ + docker compose -f dev.compose.yml up -d --force-recreate whoami godoxy traefik caddy nginx; \ + else \ + docker compose -f dev.compose.yml up -d --force-recreate whoami $(TARGET); \ + fi sleep 1 @./scripts/benchmark.sh diff --git a/dev.compose.yml b/dev.compose.yml index 4e71291a..acc368f8 100644 --- a/dev.compose.yml +++ b/dev.compose.yml @@ -184,11 +184,11 @@ configs: default_bind 0.0.0.0 servers { - protocols h2c h1 + protocols h1 h2c } } - http://whoami.domain.com:80 { + http://whoami.domain.com { reverse_proxy whoami:80 } nginx_config: @@ -221,6 +221,14 @@ configs: keepalive 128; } + server { + listen 80 default_server; + server_name _; + http2 on; + + return 404; + } + server { listen 80; server_name whoami.domain.com; diff --git a/scripts/benchmark.sh b/scripts/benchmark.sh index 77a2bbe8..d17d5783 100644 --- a/scripts/benchmark.sh +++ b/scripts/benchmark.sh @@ -6,9 +6,10 @@ set -e # Configuration HOST="whoami.domain.com" -DURATION="10s" -THREADS=4 -CONNECTIONS=100 +DURATION="${DURATION:-10s}" +THREADS="${THREADS:-4}" +CONNECTIONS="${CONNECTIONS:-100}" +TARGET="${TARGET:-}" # Color functions for output red() { echo -e "\033[0;31m$*\033[0m"; } @@ -46,6 +47,9 @@ echo "Target: $HOST" echo "Duration: $DURATION" echo "Threads: $THREADS" echo "Connections: $CONNECTIONS" +if [ -n "$TARGET" ]; then + echo "Filter: $TARGET" +fi echo "" # Define services to test @@ -103,7 +107,9 @@ echo "" # Run connection tests for all services for name in "${!services[@]}"; do - test_connection "$name" "${services[$name]}" + if [ -z "$TARGET" ] || [ "${name,,}" = "${TARGET,,}" ]; then + test_connection "$name" "${services[$name]}" + fi done echo "" @@ -152,7 +158,7 @@ run_benchmark() { h2load -t"$THREADS" -c"$CONNECTIONS" --duration="$h2_duration" \ -H "Host: $HOST" \ -H ":authority: $HOST" \ - "$url" | grep -vE "^(starting benchmark...|spawning thread #|progress: |Warm-up )" + "$url" | grep -vE "^(starting benchmark...|spawning thread|progress: |Warm-up |Main benchmark duration|Stopped all clients|Process Request Failure)" echo "" green "✓ $name benchmark completed" @@ -162,7 +168,9 @@ run_benchmark() { # Run benchmarks for each service for name in "${!services[@]}"; do - run_benchmark "$name" "${services[$name]}" + if [ -z "$TARGET" ] || [ "${name,,}" = "${TARGET,,}" ]; then + run_benchmark "$name" "${services[$name]}" + fi done blue "========================================"