Let ab.sh measure without keep-alive

--no-keep-alive sends "Connection: close" so that every request opens a
new connection, which measures the cost of accepting and setting one up.
bombardier's default fasthttp client ignores its own -a flag, so the
header is the way to do it.

On macOS, keep runs short (--duration 1s): at about 20k connections per
second, closed connections pile up in TIME_WAIT and a 5-second run
starts failing, on any ref.
This commit is contained in:
yhirose committed 2026-11-25 23:15:41 -05:00
1 parent eea8ce9798
commit 8037789492
1 file changed
+12 -2
+12 -2
View File
@@ -4,7 +4,7 @@
# #
# Usage: ./ab.sh [--base REF] [--head REF] [--rounds N] [--duration S] # Usage: ./ab.sh [--base REF] [--head REF] [--rounds N] [--duration S]
# [--connections N] [--threads N] [--path PATH] [--tls] # [--connections N] [--threads N] [--path PATH] [--tls]
# [--large-mib N] [--timeout S] # [--large-mib N] [--timeout S] [--no-keep-alive]
# #
# --path selects the workload. The harness serves: # --path selects the workload. The harness serves:
# / small body via set_content(); the response line, the # / small body via set_content(); the response line, the
@@ -20,6 +20,9 @@
# --tls runs the same workload over HTTPS, which writes through # --tls runs the same workload over HTTPS, which writes through
# SSLSocketStream instead of SocketStream. # SSLSocketStream instead of SocketStream.
# #
# --no-keep-alive opens a new connection for every request, which measures
# the cost of accepting and setting up a connection.
#
# --timeout is bombardier's per-request timeout. Its 2s default aborts large # --timeout is bombardier's per-request timeout. Its 2s default aborts large
# TLS responses, and the run then fails on the non-2xx check. # TLS responses, and the run then fails on the non-2xx check.
# #
@@ -43,6 +46,7 @@ REQ_PATH="/"
TLS=0 TLS=0
LARGE_MIB=1 LARGE_MIB=1
TIMEOUT="30s" TIMEOUT="30s"
NO_KEEP_ALIVE=0
while [ $# -gt 0 ]; do while [ $# -gt 0 ]; do
case "$1" in case "$1" in
@@ -56,10 +60,16 @@ while [ $# -gt 0 ]; do
--large-mib) LARGE_MIB="$2"; shift 2 ;; --large-mib) LARGE_MIB="$2"; shift 2 ;;
--timeout) TIMEOUT="$2"; shift 2 ;; --timeout) TIMEOUT="$2"; shift 2 ;;
--tls) TLS=1; shift ;; --tls) TLS=1; shift ;;
--no-keep-alive) NO_KEEP_ALIVE=1; shift ;;
*) echo "Unknown option: $1" >&2; exit 1 ;; *) echo "Unknown option: $1" >&2; exit 1 ;;
esac esac
done done
# bombardier's default fasthttp client ignores -a, so close each connection
# with the request header instead.
CLOSE_HEADER=()
if [ "$NO_KEEP_ALIVE" -eq 1 ]; then CLOSE_HEADER=(-H "Connection: close"); fi
command -v bombardier >/dev/null || { echo "Error: bombardier not found" >&2; exit 1; } command -v bombardier >/dev/null || { echo "Error: bombardier not found" >&2; exit 1; }
command -v python3 >/dev/null || { echo "Error: python3 not found" >&2; exit 1; } command -v python3 >/dev/null || { echo "Error: python3 not found" >&2; exit 1; }
@@ -162,7 +172,7 @@ measure() {
done done
set +e set +e
json=$(bombardier -c "$CONNECTIONS" -d "$DURATION" -t "$TIMEOUT" -o json -p r $INSECURE \ json=$(bombardier -c "$CONNECTIONS" -d "$DURATION" -t "$TIMEOUT" -o json -p r $INSECURE ${CLOSE_HEADER[@]+"${CLOSE_HEADER[@]}"} \
"$SCHEME://127.0.0.1:$PORT$REQ_PATH" 2>/dev/null) "$SCHEME://127.0.0.1:$PORT$REQ_PATH" 2>/dev/null)
rc=$? rc=$?
set -e set -e