refactor(benchmark): benchmark script functionality and fairness

This commit is contained in:
yusing
2026-01-03 00:57:50 +08:00
parent 7702fa6696
commit 5c9ccd9963
3 changed files with 29 additions and 9 deletions

View File

@@ -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

View File

@@ -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;

View File

@@ -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 "========================================"