Files
benchmarks/transport/run.sh
zeekayandHanzo Dev 0078a3efcd Refuse without a stray cd
`cd "$(cloud_src)" || exit 1` runs cd on the empty string when the resolver
refuses, so a lane that had just printed how to get the source followed it with
`cd: null directory`. The path is captured first and checked before anything
is entered.

Co-authored-by: Hanzo Dev <[email protected]>
2026-09-16 09:54:04 -07:00

78 lines
3.8 KiB
Bash
Executable File

#!/usr/bin/env bash
# What an agent pays to call an operation, per transport.
#
# Every other lane measures work the machine does. This measures the tax on
# asking it to: one operation, registered once, called over each way this server
# offers to reach it. An agent's loop is call, read, decide, call again, so this
# number is multiplied by every step of every task.
#
# Four transports, and the fourth is why the harness is Go. REST, MCP and the op-call
# plane are HTTP and a script can speak them; ZAP is not, and a Python client
# against three transports with a Go client against the fourth would put the client's
# language into the comparison. One client, four envelopes.
#
# The transports are not variants of one wire. Over REST the operation IS the address.
# Over MCP the address is a single agent endpoint and the operation is a name in
# the body. Over the op-call plane the name is in the path and the body is
# binary. Same handler, same process, three different envelopes — so the
# difference between these rows is the envelope and nothing else.
set -euo pipefail
# The lane runs from the cloud source, which is a different repository now.
# `cloud_src` finds it or says how to get it (../host.sh).
HERE="$(cd "$(dirname "$0")" && pwd)"
. "$HERE/../host.sh"
SRC="$(cloud_src)" || exit 1
cd "$SRC"
export GOWORK=off
N=${N:-200}
P=${P:-18086}; ZP=${ZP:-19663}; HP=${HP:-19096}; AP=${AP:-18087}
DATA=$(mktemp -d); BIN=$(mktemp -u); PID=""; DATA2=""
# A CLEANUP THAT CAN FAIL EARLY DOES NOT CLEAN. set -e is in force inside a
# trap, so `[ -n "$PID" ] && kill ...` returning non-zero — which is what it does
# whenever PID is empty — aborts the handler before anything is removed. Empty is
# exactly the early-exit case, a build that did not compile, where the temporary
# files most want removing. Reproduced in isolation: the marker file survives.
#
# DATA2 is in here too. It belongs to the second phase and used to be removed by
# the last line of the script, so every path that did not reach that line — the
# second server failing to boot, an interrupt — left a data directory behind.
cleanup() {
if [ -n "$PID" ]; then kill "$PID" 2>/dev/null || true; fi
rm -rf "$DATA" "$BIN" "$BIN.transports" "${DATA2:-}"
}
trap cleanup EXIT
go build -o "$BIN" ./cmd/cloud
export CLOUD_DEV_UNENCRYPTED=1
export CLOUD_LISTEN=":$P" CLOUD_ZAP_LISTEN="127.0.0.1:$ZP"
export CLOUD_HEALTH_LISTEN="127.0.0.1:$HP" CLOUD_ADMIN_LISTEN="127.0.0.1:$AP"
export CLOUD_DATA_DIR="$DATA"
"$BIN" serve >"$DATA/log" 2>&1 & PID=$!
for _ in $(seq 1 300); do
curl -s -m 2 "http://127.0.0.1:$HP/healthz" 2>/dev/null | grep -q . && break
sleep 0.1
done
# One READ, because a read is what an agent does most and it writes nothing that
# would make the second call different from the first.
host
# The harness lives in THIS repository, not the one being measured, so it is
# built from here while the server is built from the cloud source above.
(cd "$HERE/harness" && go build -o "$BIN.transports" .)
"$BIN.transports" -base "http://127.0.0.1:$P" -zap "127.0.0.1:$ZP" -zap-name "ZAP tcp" -n "$N" ${BENCH_JSON:+-json "$BENCH_JSON"}
# ZAP over a unix socket is the in-cluster path, and a process serves ONE ZAP
# address, so it is a second phase rather than a fifth row of the first. The
# three HTTP transports are measured again with it: they are the control on drift, and
# the two ZAP rows are only comparable if REST reads the same in both phases.
echo
kill "$PID" 2>/dev/null; wait "$PID" 2>/dev/null || true
DATA2=$(mktemp -d)
CLOUD_DATA_DIR="$DATA2" CLOUD_ZAP_LISTEN="$DATA2/cloud.sock" "$BIN" serve >"$DATA2/log" 2>&1 & PID=$!
for _ in $(seq 1 300); do
curl -s -m 2 "http://127.0.0.1:$HP/healthz" 2>/dev/null | grep -q . && break
sleep 0.1
done
"$BIN.transports" -base "http://127.0.0.1:$P" -zap "$DATA2/cloud.sock" -zap-name "ZAP unix" -n "$N" ${BENCH_JSON:+-json "$BENCH_JSON"}