Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .github/workflows/benchmark-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,11 @@ jobs:
if m3 and rows:
rows[-1].update(cpureq=m3.group(1), p99=m3.group(2),
p999=m3.group(3), ratio=m3.group(4))
continue
# connections-ramp-h1: how far the ramp got, which is its result.
m4 = re.match(r"^=== Ramp: (.+) ===$", line)
if m4 and rows:
rows[-1]["ramp"] = m4.group(1)
return rows

def table(rows, deltas):
Expand Down Expand Up @@ -474,6 +479,9 @@ jobs:
out.append(base + mid + tail_)
else:
out.append(base + tail_)
for r in rows:
if r.get("ramp"):
out += ["", "{} / {}: {}".format(r["prof"], r["conns"], r["ramp"])]
return "\n".join(out)

def tail(path, n):
Expand Down
1 change: 1 addition & 0 deletions frameworks/actix/meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"connections-5m",
"connections-1m-tls",
"connections-1m",
"connections-ramp-h1",
"latency-10k",
"pipelined",
"limited-conn",
Expand Down
4 changes: 4 additions & 0 deletions frameworks/actix/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,10 @@ async fn main() -> io::Result<()> {
// even the default cap of its 2-CPU box - so only the held-connection
// profiles ever reach it.
.max_connections(100_000)
// connections-ramp-h1 wants an idle connection kept for at least 30 seconds.
// actix's default is 5 s, timed on a clock that ticks every 500 ms, so 35
// clears the 30 by more than that tick.
.keep_alive(std::time::Duration::from_secs(35))
.tcp_nodelay(true)
.bind("0.0.0.0:8080")?;

Expand Down
1 change: 1 addition & 0 deletions frameworks/aspnet-minimal/meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"connections-5m",
"connections-1m-tls",
"connections-1m",
"connections-ramp-h1",
"json-comp",
"json-tls",
"8gbit",
Expand Down
1 change: 1 addition & 0 deletions frameworks/bun/meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"connections-5m",
"connections-1m-tls",
"connections-1m",
"connections-ramp-h1",
"pipelined",
"limited-conn",
"json-comp",
Expand Down
1 change: 1 addition & 0 deletions frameworks/fib/meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"connections-5m",
"connections-1m-tls",
"connections-1m",
"connections-ramp-h1",
"latency-10k",
"json-comp",
"json-tls",
Expand Down
2 changes: 1 addition & 1 deletion frameworks/genhttp-ioxide/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ FROM mcr.microsoft.com/dotnet/sdk:11.0 AS build
# GenHTTP built from source: the branch of Kaliumhexacyanoferrat/GenHTTP#953
# (update-ioxide-0.20.396) rather than the 11.3.0 release. Pinned to one commit,
# because a build on cached layers would otherwise keep whichever it cloned first.
ARG GENHTTP_COMMIT=5967f5c6bf64d3d67a0eed7a669fa2f8c846dd02
ARG GENHTTP_COMMIT=0229cfba8ac5d250d2151578e95ba646ee34de9c
RUN git init -q /genhttp \
&& git -C /genhttp fetch -q --depth 1 https://github.com/Kaliumhexacyanoferrat/GenHTTP.git "$GENHTTP_COMMIT" \
&& git -C /genhttp checkout -q FETCH_HEAD
Expand Down
5 changes: 5 additions & 0 deletions frameworks/genhttp-ioxide/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@
{
WriteSlabSize = writeSlab ?? new TcpTransportOptions().WriteSlabSize,

// An idle connection is closed after 35 s, as is one whose client stops draining a flush
// for as long. Past the 30 s connections-ramp-h1 asks an idle connection to be kept for.
ReadTimeoutMs = 35_000,
SendTimeoutMs = 35_000,

// Kernel TLS on the way out, which is what this entry measured before the engine made it
// opt-in: ioxide.tls used to default it on, so json-tls has always been kTLS TX with
// OpenSSL still decrypting inbound. It needs the Linux tls module - without it every
Expand Down
6 changes: 3 additions & 3 deletions frameworks/genhttp-ioxide/genhttp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
</PropertyGroup>

<!-- GenHTTP from source, cloned by the Dockerfile into GenHttpSource (see there). Its
GenHTTP.Engine.Ioxide pins ioxide 0.26.563; ioxide.pg and ioxide.timer below are built
GenHTTP.Engine.Ioxide pins ioxide 0.29.656; ioxide.pg and ioxide.timer below are built
against the same ioxide, so they move with it. -->
<PropertyGroup>
<GenHttpSource Condition="'$(GenHttpSource)' == ''">/genhttp</GenHttpSource>
Expand All @@ -33,9 +33,9 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="ioxide.pg" Version="0.26.563" />
<PackageReference Include="ioxide.pg" Version="0.29.656" />
<!-- Ring-native timeouts for /delay: the wait completes on the reactor, not the thread pool. -->
<PackageReference Include="ioxide.timer" Version="0.26.563" />
<PackageReference Include="ioxide.timer" Version="0.29.656" />
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="11.0.0-preview.5.26302.115" />
</ItemGroup>

Expand Down
1 change: 1 addition & 0 deletions frameworks/genhttp-ioxide/meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"connections-5m",
"connections-1m-tls",
"connections-1m",
"connections-ramp-h1",
"latency-10k",
"pipelined",
"limited-conn",
Expand Down
1 change: 1 addition & 0 deletions frameworks/node/meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"connections-5m",
"connections-1m-tls",
"connections-1m",
"connections-ramp-h1",
"pipelined",
"limited-conn",
"json-comp",
Expand Down
4 changes: 4 additions & 0 deletions frameworks/node/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,10 @@ if (cluster.isPrimary) {

const server = http.createServer(handle);

// connections-ramp-h1 wants an idle connection kept for at least 30 seconds;
// node closes it after 5 by default (plus the second of keepAliveTimeoutBuffer).
server.keepAliveTimeout = 35_000;

// Scaling is cluster to fork the workers, but not its round robin: with reusePort
// every worker binds 8080 itself with SO_REUSEPORT and the kernel spreads the
// accepts, the way bun and deno do it. node sets exclusive on its own when
Expand Down
33 changes: 25 additions & 8 deletions scripts/benchmark.sh
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ done
# and any combination thereof.
_has_isolated_test=false
for t in baseline pipelined limited-conn json-comp json-tls upload \
static-tls async-db async latency-1m latency-10k connections-5m connections-1m-tls connections-1m \
static-tls async-db async latency-1m latency-10k connections-5m connections-1m-tls connections-1m connections-ramp-h1 \
baseline-h2 static-h2 baseline-h2c json-h2c \
baseline-h3 static-h3 \
unary-grpc unary-grpc-tls \
Expand Down Expand Up @@ -356,13 +356,16 @@ run_one() {
# three runs, which is not known until all three have happened. Every run is
# recorded here and the choice is made below.
local _mdir=""
case "$endpoint" in latency-1m|latency-10k|8gbit|connections-5m|connections-1m-tls|connections-1m) _mdir=$(mktemp -d) ;; esac
case "$endpoint" in latency-1m|latency-10k|8gbit|connections-5m|connections-1m-tls|connections-1m|connections-ramp-h1) _mdir=$(mktemp -d) ;; esac

BEST_M=()
local run
# connections-ramp-h1 is one ramp, after a warm-up at the offered rate
# (gcannon's --settle), and not a best-of.
local run runs="$RUNS"
[ "$endpoint" = "connections-ramp-h1" ] && runs=1

for run in $(seq 1 "$RUNS"); do
echo ""; echo "[run $run/$RUNS]"
for run in $(seq 1 "$runs"); do
echo ""; echo "[run $run/$runs]"

# The held-connection profiles give every run a fresh server. One that
# has just held five million connections keeps what it grew to after
Expand Down Expand Up @@ -487,7 +490,7 @@ run_one() {
# fresh one. After the last run it is left for the profile's cleanup.
if held_conn_profile "$endpoint" && ! $is_gateway; then
held_conn_drain "after run $run"
if [ "$run" -lt "$RUNS" ]; then
if [ "$run" -lt "$runs" ]; then
framework_stop
fi
elif [ "$CONNS" -ge 32768 ]; then sleep 15
Expand Down Expand Up @@ -584,8 +587,14 @@ run_one() {
if [ -n "${BEST_M[hold_error]:-}" ]; then
warn "$endpoint did not run: ${BEST_M[hold_error]}"
else
echo "=== Connections: ${BEST_M[connections_open]:-n/a} open of $CONNS | connect errors in the window ${BEST_M[connect_errors]:-n/a} ==="
if [ -n "${BEST_M[connections_open]:-}" ] \
if [ "$endpoint" = "connections-ramp-h1" ]; then
# Not a fleet that was held: how far the ramp got, and what
# stopped it (ceiling, p99 or rate; scripts/conn_hold.py).
echo "=== Ramp: reached ${BEST_M[ramp_reached]:-n/a} of $CONNS connections (${BEST_M[connections_open]:-n/a} open, ${BEST_M[idle_closed]:-n/a} idle closed by the server) | stopped by ${BEST_M[ramp_stop]:-n/a} ==="
else
echo "=== Connections: ${BEST_M[connections_open]:-n/a} open of $CONNS | connect errors in the window ${BEST_M[connect_errors]:-n/a} ==="
fi
if [ "$endpoint" != "connections-ramp-h1" ] && [ -n "${BEST_M[connections_open]:-}" ] \
&& [ "${BEST_M[connections_open]}" -lt $(( CONNS * 99 / 100 )) ] 2>/dev/null; then
warn "held ${BEST_M[connections_open]} of $CONNS connections through the window"
fi
Expand Down Expand Up @@ -703,6 +712,14 @@ save_result() {
\"p50_latency\": \"${BEST_M[p50_lat]:-}\",
\"connections_open\": ${BEST_M[connections_open]:-null},
\"window_connect_errors\": ${BEST_M[connect_errors]:-null}"
# connections-ramp-h1: the ramp's outcome (conn_hold.py
# ramp_summary), which the score is.
if [ "$profile" = "connections-ramp-h1" ]; then
eff_extra="$eff_extra,
\"ramp_reached\": ${BEST_M[ramp_reached]:-null},
\"ramp_stop\": \"${BEST_M[ramp_stop]:-}\",
\"idle_closed\": ${BEST_M[idle_closed]:-null}"
fi
fi
fi

Expand Down
133 changes: 128 additions & 5 deletions scripts/conn_hold.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
"""Run gcannon --rate for a held-connection profile; report a fixed-rate summary.

connections-5m holds five million keep-alive connections and paces requests
across them, connections-1m-tls a million over TLS 1.3. gcannon does the load
across them, connections-1m-tls a million over TLS 1.3. connections-ramp-h1
opens two million over two minutes instead, 95% of them idle, and this wrapper
reads from gcannon's interval timeline how many it took to push the active
ones' p99 over the limit (--ramp-p99-us). gcannon does the load
itself (gcannon >= 0.8.2: --rate, --addr-span, --connect-limit, --settle,
--warmup-max) in one process: ~3.3 KiB a connection, against the ~303 KiB that
sank the first million-connection attempt with zrk 2.3.0. (connections-1m
Expand Down Expand Up @@ -35,7 +38,7 @@
conn_hold.py --profile connections-5m --conns N --rate R --port P
--probe 127.0.0.2,127.0.0.160 [--span 127.0.0.1-127.0.0.160]
[--cpu-stat FILE] [--server-mem 128g] [--kib-per-conn 4]
[--kernel-kib-per-conn 8]
[--kernel-kib-per-conn 8] [--ramp-p99-us 2000]
-- <gcannon command prefix...> --args-- <gcannon arguments...>
"""

Expand Down Expand Up @@ -65,6 +68,22 @@
# server past its handshake timeout, which closed them mid-handshake: a fleet
# that never finished connecting.
MIN_VERSION_TLS = (0, 8, 4)
# connections-ramp-h1 is driven by --ramp-up and --idle, and read off the
# interval lines they print (gcannon#35).
MIN_VERSION_RAMP = (0, 10, 0)
# An interval's rate has to reach this share of what was offered, or the p99
# next to it describes a server that is not keeping up (or one that has
# answered nothing at all, and has no p99).
RAMP_RATE_SHARE = 0.9
# connections-ramp-h1: the least time an idle connection has to be left open,
# and how much earlier a close still passes - a server's timer may be coarse.
# validate-keepalive.py asks the same of a handful of connections; this asks it
# of the run, where a server under load might do otherwise.
IDLE_MIN_S = 30.0
IDLE_SLACK_S = 1.0
# Closes below this share of the idle connections opened are not looked at: a few
# resets are not a server shedding.
IDLE_CLOSED_SHARE = 0.01


def log(msg: str) -> None:
Expand Down Expand Up @@ -174,6 +193,83 @@ def _raise_nofile(want: int) -> str | None:
"fs.nr_open")


def idle_age(rows: list, i: int) -> float | None:
"""How long the idle connections the server closed by the end of row i had
been open, in seconds: the time since the idle_closed(i)-th idle connection
was opened. A server that gives every connection the same time closes them
oldest first, so the n-th close is the n-th open and this is its timeout; one
that closes in another order comes out as the mean age. None while too few
were closed to say."""
closed = rows[i].get("idle_closed") or 0
opened = rows[i].get("idle_opened") or 0
if opened <= 0 or closed < IDLE_CLOSED_SHARE * opened:
return None
now = rows[i].get("t") or 0.0
t0, n0 = 0.0, 0
for r in rows[:i + 1]:
t, n = r.get("t") or 0.0, r.get("idle_opened") or 0
if n >= closed:
return now - (t0 + (t - t0) * (closed - n0) / (n - n0) if n > n0 else t)
t0, n0 = t, n
return None


def ramp_summary(args, g: dict) -> tuple[dict | None, str | None]:
"""How far the ramp got before the active connections' p99 went over the
limit, from gcannon's timeline (one row per interval). Returns (summary,
None) or (None, why not).

The row that counts is the last one before the limit is crossed. A crossing
is an interval over the limit - its p99, its rate short of what was offered,
which is also how a server that stopped answering reads, or idle connections
closed younger than IDLE_MIN_S - with the one after it over too, or with
nothing after it: one noisy interval on its own is not the end of a ramp.
`reached` is every connection opened by then, idle ones included, whether or
not the server has closed some since; `connections_open` is the most of them
that were open at once."""
rows = g.get("timeline") or []
if not rows:
return None, "no interval timeline in gcannon's summary"

def over(i: int) -> str:
r = rows[i]
if (r.get("rps") or 0) < RAMP_RATE_SHARE * args.rate:
return "rate"
age = idle_age(rows, i)
if age is not None and age < args.idle_min_s - IDLE_SLACK_S:
return "shed"
if (r.get("p99_us") or 0) > args.ramp_p99_us:
return "p99"
return ""

reached = open_now = idle_closed = 0
stop, crossed = "ceiling", None
for i, r in enumerate(rows):
why = over(i)
if why and (i + 1 == len(rows) or over(i + 1)):
stop, crossed = why, i
break
if why:
continue # one interval on its own
# opened so far: the active connections open now, and every idle one
# ever opened (the timeline has no idle_* keys without --idle)
reached = (r.get("active") or 0) + (r.get("idle_opened") or 0)
open_now = max(open_now, (r.get("active") or 0) + (r.get("idle_open") or 0))
idle_closed = r.get("idle_closed") or 0
out = {"reached": reached, "connections_open": open_now, "stop": stop,
"idle_closed": idle_closed, "p99_limit_us": args.ramp_p99_us,
"intervals": len(rows)}
if crossed is not None:
r = rows[crossed]
out["stop_t"] = r.get("t")
out["stop_p99_us"] = r.get("p99_us")
out["stop_rps"] = r.get("rps")
age = idle_age(rows, crossed)
if age is not None:
out["stop_idle_age_s"] = round(age, 2)
return out, None


def _error(args, msg: str) -> dict:
log(msg)
return {"hold_error": msg, "connections": args.conns, "target_rate": args.rate,
Expand All @@ -185,10 +281,12 @@ def _error(args, msg: str) -> dict:
def run(args, prefix: list[str], gargs: list[str]) -> dict:
ver = _version(prefix)
tls = bool(gargs) and gargs[0].startswith("https://")
need = MIN_VERSION_TLS if tls else MIN_VERSION
ramp = args.ramp_p99_us > 0
need = MIN_VERSION_RAMP if ramp else MIN_VERSION_TLS if tls else MIN_VERSION
if ver is None or ver < need:
# prefix[-1] is the image or the binary: which gcannon was asked
why = ("--connect-limit held through the TLS handshake" if tls else
why = ("--ramp-up, --idle and the interval lines" if ramp else
"--connect-limit held through the TLS handshake" if tls else
"--settle, and --rate with every thread spread over the whole interval")
return _error(args, "%s needs gcannon >= %s (%s); %s %s"
% (args.profile, ".".join(map(str, need)), why, prefix[-1],
Expand Down Expand Up @@ -273,7 +371,7 @@ def watch_stderr():
and cpu.get("end") is not None and cpu["end"] >= cpu["start"] else None
if g.get("connections_active") is not None:
log(f"{g['connections_active']} of {args.conns} connections open at the end of the window")
return {
summary = {
"connections": args.conns,
"connections_open": g.get("connections_active"),
"target_rate": args.rate,
Expand All @@ -290,6 +388,25 @@ def watch_stderr():
"server_cpu_usec": cpu_win,
"gcannon": g,
}
if ramp:
found, why = ramp_summary(args, g)
if found is None:
return _error(args, why or "no ramp in gcannon's summary")
tail = ""
if found["stop"] != "ceiling":
tail = " at %.0f s (p99 %.2f ms, %.0f req/s" % (
found.get("stop_t") or 0, (found.get("stop_p99_us") or 0) / 1000,
found.get("stop_rps") or 0)
if found["stop"] == "shed":
tail += ", idle connections closed after %.1f s, at least %.0f s is required" % (
found.get("stop_idle_age_s") or 0, args.idle_min_s)
tail += ")"
log("reached %d connections (at most %d open at once) within %.1f ms p99; stopped by %s%s"
% (found["reached"], found["connections_open"], args.ramp_p99_us / 1000,
found["stop"], tail))
summary["ramp"] = found
summary["connections_open"] = found["connections_open"]
return summary


def main(argv: list[str]) -> int:
Expand All @@ -312,6 +429,12 @@ def main(argv: list[str]) -> int:
ap.add_argument("--profile", default="connections-5m", help="for messages")
ap.add_argument("--span", default="127.0.0.1-127.0.0.160",
help="the addresses the fleet is spread over, for messages")
ap.add_argument("--ramp-p99-us", dest="ramp_p99_us", type=int, default=0,
help="connections-ramp-h1: the p99 limit (microseconds) the ramp is "
"read against; 0 = not a ramp")
ap.add_argument("--idle-min-s", dest="idle_min_s", type=float, default=IDLE_MIN_S,
help="connections-ramp-h1: the least time (seconds) an idle connection "
"has to be left open before the server may close it")
args = ap.parse_args(argv[:i])
print(json.dumps(run(args, argv[i + 1:j], argv[j + 1:]), indent=1))
return 0
Expand Down
Loading
Loading