Internals: benchmark reports

Replica keys on the proxy path (1.1.1, Task 12)

Question: what do the 1.1.1 replica keys cost a proxied 1 KiB response, against the same route without them, and against nginx?

Status: after the retry fix (commit d953ff6b) the gate PASSES on both layouts: 0.994 at 1 CPU and 0.986 at 6 CPUs (run 2 below). The first measurement (runs 1 and diagnostic, kept below as history) had failed at 1 CPU (0.942 and 0.964): the route retry key copied the request head on every request; without it the row was at 0.995 and 0.999.

Results: run 2, after the retry fix (3 rounds, replica-off and replica-on)

  • Build: tree of commit d953ff6b (“Proxy: retry keeps the request head without a per-request clone”; the tree of 1457e156 plus the fix), tools/pgo-build.sh with PGO_FEATURES=scalwsd/http3, checkout [private host path].
    • scalwsd sha256 89c6f2afa1df07ad2adf70566c5c47e6161d9a2dafb9048cc42e382eb534ff9a
    • scalws-bench-upstream sha256 2a391a7f73d6ea8229afb2d915bdf2db7061945ab3c67d38cd2d7c6b8cdcb65e (unchanged)
    • bench/replica.sh md5 1a8184d5467c299da73b730d9d8b9653 (unchanged), run with SERVERS="scalws-off scalws-on", same pinning and durations as run 1.
  • Quiet at start: nothing else running; 1-minute load 1.81, the tail of the PGO build that finished a minute earlier (the script’s check is under 2). Raw rows: [private host path] on xeon, copied below.
CPUsRowreq/sCPU us/reqp99 msRatio to replica-off
1replica-off1721058.14.041.000
1replica-on1718258.24.070.994 (0.966-1.000) PASS
6replica-off10009359.90.901.000
6replica-on9871260.80.910.986 (0.978-1.007) PASS

Per-round req/s (off / on): 1 CPU 17291 / 17182, 17087 / 16503, 17210 / 17212; 6 CPUs 98953 / 99646, 100093 / 98712, 100744 / 98499. Non-2xx answers: 0. CPU per request at 1 CPU is now equal (58.2 against 58.1 us; it was 61.1 against 58.6 before the fix). One round at 1 CPU (round 2, 0.966) is below 0.97; the other two are at 0.994 and 1.000.

The fix: forward keeps the prepared head across attempts and sets each attempt’s Host in place. The own client (the default) encodes the head from a reference before its future starts, so no attempt copies it, whatever the retry.on conditions (connect_error, timeout and status_5xx alike). The hyper client (upstream_client: hyper, the fallback) owns what it sends, so it still gets a copy for an attempt that may be followed by another, as before. pipeline_cost row proxy+retry (the ScalPanel retry on a failover route): 26.0 allocations per request, equal to proxy+failover and proxy+pool; it was 31.0 before the fix (5 allocations: the HeaderMap copy).

Setup (all runs; build of runs 1, perf and diagnostic)

  • Host xeon: 2x Xeon E5-2650 v2 (no AVX2), kernel 7.0.0-43-generic, quiet at start (load under 2, nothing else running). Server on socket 0 (CPU 0 for 1 CPU, CPUs 0-5 for 6 CPUs), bench upstream on 6,7,22,23, oha 1.16.0 on socket 1 (8-15,24-31), 64 connections, 5 s warm-up and 15 s per row, 3 rounds, server order rotated per round.
  • Build (runs 1, perf and diagnostic): tree of commit 1baaba26 (branch replica, Tasks 1 to 11) plus the two new bench files of this commit, tools/pgo-build.sh with PGO_FEATURES=scalwsd/http3, checkout [private host path].
    • scalwsd sha256 82ad4c78a35ae248ded960b7aa327888cb41253884a91912d610d7e321c9bd09
    • scalws-bench-upstream sha256 2a391a7f73d6ea8229afb2d915bdf2db7061945ab3c67d38cd2d7c6b8cdcb65e
    • nginx 1.31.6 (/opt/nginx-1.31.6/sbin/nginx).
  • Script: bench/replica.sh (new, modelled on bench/edge.sh; edge.sh is bound to the ScalPanel edge fixture, so the rows live in their own script) and bench/configs/nginx-replica.conf. replica.sh md5 on xeon equals the local file (1a8184d5467c299da73b730d9d8b9653 for the diagnostic run, bbabf455c98fd0a470ebfdd3287edf02 for run 1, which lacks only the optional scalws-noretry row).
  • Both pools have the bench upstream (127.0.0.1:9000) as their only member, so the upstream sees the same load in every row. Every request carries Host: www.example.com.

Rows:

RowRoute
replica-offbackends: [{pool: p}, {pool: q}], no replica key (weighted 1/1, as 1.1.0)
replica-ontwo pools with active_health (1 s, timeout 500 ms), balance: failover, retry: {on: [connect_error, timeout], max: 1, only_idempotent: true}, write_backend: 0, no sticky
replica-stickybalance: weighted with sticky: {cookie: sp, key_file} (key file 0600) and active_health on both pools
replica-noretryreplica-on without retry (diagnostic, not in the default row set)
nginx-offupstream { server local; server local; } (round robin)
nginx-onupstream { server local max_fails=1 fail_timeout=1s; server peer backup; }

Sticky is not part of replica-on: key list rule 3 allows sticky only with balance: weighted; with failover it is warned about and ignored. replica-sticky is reported with its ratio and not gated. It costs about 6.7 us per request without a cookie (measured: 65.3 against 58.6 us at 1 CPU, 6.6 us at 6 CPUs); oha sends no cookie, so every request makes a new choice, signs it and sets a cookie.

History: run 1 before the fix (3 rounds, all rows)

Medians of the three rounds; the ratio is the median of the per-round ratios (min-max in brackets). Raw rows: [private host path] on xeon, copied below.

CPUsRowreq/sCPU us/reqp99 msRatio to replica-offRatio to nginx (same variant)
1replica-off1707458.64.071.0000.968 (0.952-0.982)
1replica-on1637061.14.340.942 (0.938-0.963) FAIL0.903 (0.886-0.922)
1replica-sticky1531765.34.510.881 (0.879-0.899)n/a
1nginx-off1791655.83.90n/an/a
1nginx-on1806655.43.86n/an/a
6replica-off9870760.70.931.0000.941 (0.937-0.948)
6replica-on9554462.81.010.978 (0.966-0.984) PASS0.912 (0.910-0.922)
6replica-sticky8913367.31.060.908 (0.903-0.918)n/a
6nginx-off10428157.40.94n/an/a
6nginx-on10478957.10.90n/an/a

nginx’s own cost of backup plus max_fails against two servers: 1.010 (1 CPU) and 1.006 (6 CPUs). Non-2xx answers: 0.

Per-round req/s (round: off / on / sticky / nginx-off / nginx-on):

CPUsR1R2R3
117377 / 16370 / 15317 / 17950 / 1812217074 / 16436 / 15001 / 17384 / 1781717061 / 16003 / 15330 / 17916 / 18066
698707 / 96503 / 89133 / 104917 / 10465298870 / 95461 / 89762 / 104281 / 10487797096 / 95545 / 89116 / 103676 / 104789

History: diagnostic run before the fix (3 more rounds, off, on, noretry)

Same binary, same checkout, run after the perf run. Medians.

CPUsRowreq/sCPU us/reqRatio to replica-off
1replica-off1691159.11.000
1replica-on1616561.90.964 (0.950-0.979) FAIL
1replica-noretry1692759.10.995 (0.980-1.015)
6replica-off9952660.21.000
6replica-on9709161.80.982 (0.967-1.001) PASS
6replica-noretry9734661.60.999 (0.975-1.004)

Over both sets the 1 CPU ratio never reaches 0.97 as a median (0.942, 0.964, and 0.952 in the perf run); 6 CPUs passes in both sets (individual rounds as low as 0.966).

History: the missed gate, where the time went

perf record -F 999 -g on CPU 0 (1-CPU layout) during the measured 15 s, replica-off against replica-on ([private host path], round 2, 250 136 and 234 331 requests; the perf run itself gave 0.952, 15899 against 16704 req/s). Samples per 1000 requests: 56.8 (off) and 60.6 (on), +6.7%. The profile is flat (the largest user symbol is 2.9%), most of it kernel TCP and nftables. Symbols that exist only with the replica keys, or grow most, user space, in samples per 1000 requests:

SymboloffonDelta
http::header::map::HeaderMap::clone0.000.26+0.26
drop_glue::<HeaderMap>0.000.13+0.13
PoolProxyHandler::selected0.000.14+0.14
route_select::select (failover choice)0.000.11+0.11
PoolProxyHandler::choose0.150.00-0.15
scalws_server::pipeline::handle1.541.78+0.24
own_client::Lease::poll_head0.831.09+0.26
_mi_page_malloc_zero (allocator)0.220.33+0.11

The head clone and its drop (+0.39 per 1000, 0.7% of all samples) are the only new work of that size; the rest is spread over the pipeline and kernel TCP symbols and mostly reflects the extra allocator and memory traffic (the on row also serves fewer requests per sample window, which shifts per-request shares of the TCP path). The diagnostic row confirms it: without retry the route costs nothing measurable (0.995 and 0.999).

Cause in the code: crates/scalws-proxy/src/pool.rs, forward builds the attempt loop with retries > 0 when the route has retry (Replay::new(body, retries > 0)), and the loop keeps a copy of the request head via clone_head (a full HeaderMap clone, one allocation per header block) for the next attempt even when the first attempt succeeds, which is almost every request. A fix that clones the head only when an attempt fails and a retry follows (or that retains the head by value for the first attempt and rebuilds it from the prepared parts), would remove this. pipeline_cost does not see it because no row combines retry with a pool route; a row proxy+retry should be added with the fix.

pipeline_cost rows

After the fix (tree of d953ff6b), cargo test --release -p scalws-server pipeline_cost -- --ignored --nocapture on xeon: every row keeps its allocation count; proxy+retry is new.

Rowns/requestallocations/requestbytes/request
proxy6808522.07809
proxy+pool7175326.09493
proxy+active_health7346626.09493
proxy+read_only7326226.09493
proxy+backends7415426.09493
proxy+failover7286126.09493
proxy+retry7301226.09493
proxy+sticky7725727.09585
proxy+cookie7605527.09585
proxy+networks6981022.07809
proxy+access_log7192026.08540
proxy+other_log6935822.07809
respond370015.05432
respond+referer378515.05432
respond+listeners390615.05432
respond+xff560720.06094
respond+countries594320.06094
static997017.08256
php1131818.010496
respond+cache372515.05432
respond+cloudflare399115.05432
respond+trusted549018.05492

The pool rows allocate 144 bytes less per request than before (9493 against 9637), with the same allocation count (not investigated further). Before the fix, with the new row added, proxy+retry was 31.0 allocations and 10501 bytes per request.

History, before the fix: same checkout (commit 1baaba26 and the bench files), unit time includes an in-process upstream:

Rowns/requestallocations/requestbytes/request
proxy6872322.07809
proxy+pool7316026.09637
proxy+active_health7296126.09637
proxy+read_only7341126.09637
proxy+backends7325726.09637
proxy+failover7357926.09637
proxy+sticky7812627.09729
proxy+cookie7452627.09729
proxy+networks7008222.07809
proxy+access_log7292726.08541
proxy+other_log6915122.07809
respond346715.05432
respond+referer353415.05432
respond+listeners360815.05432
respond+xff559920.06094
respond+countries593120.06094
static946617.08256
php1074418.010496
respond+cache344715.05432
respond+cloudflare370815.05432
respond+trusted550018.05492

The Task 1 to 7 rows are equal where the plan requires: proxy+pool = proxy+active_health = proxy+read_only = proxy+backends = proxy+failover (26.0), and proxy+sticky = proxy+cookie (27.0, the cookie header’s own cost). None of the rows had retry, which is why the clone above was invisible there.

Other observations

  • ScalWS without any replica key is at 0.94 to 0.97 of nginx on this two-pool route and 1 KiB body (replica-off against nginx-off), at about 58.6 against 55.8 us of CPU per request at 1 CPU. This is not part of the replica gate and was not investigated here.
  • active_health at 1 s on two pools (two probes per second) is not visible: replica-noretry equals replica-off.