Skip to content

bench: deterministic reality-tlsin upload, nightly perf check in CI - #127

Merged
Nemu-x merged 4 commits into
devfrom
bench/ci-nightly
Oct 18, 2026
Merged

Nemu-x merged 4 commits into
devfrom
bench/ci-nightly

Conversation

@Nemu-x

@Nemu-x Nemu-x commented Oct 18, 2026 •

Copy link
Copy Markdown
Collaborator

Two harness follow-ups to #126: a deterministic reality-tlsin upload, and a nightly perf check in CI.

1. reality-tlsin upload: Vision goes direct on every stream

Xray's Vision client switches an upload to direct copy only when one of its reads from the local socket contains nothing but whole TLS application-data records (IsCompleteRecord in proxy/proxy.go). cmp wrote the 1-byte inner command record and the bulk data back to back. A stream therefore went direct (~3000 MB/s) or stayed padded to the end (~400 MB/s), depending on how the client's reads split the writes. This happened on every server, Xray's included.

Fix (TLS sink only, so the other protocols are unchanged):

  • The TLS sink writes one ready byte after its handshake. cmp waits for it before sending the command, so the client's CCS+Finished flight and the command record are never in the same read.
  • The sink acknowledges the upload command with one byte. cmp waits for it before sending any data, so the command record is read alone and Vision switches on it.

Observability: on reality-tlsin the Xray client logs at debug level. cmp measure reads the client log of each bulk phase and counts, per session, the XtlsPadding … 2 (upload) and Xtls Unpadding … command 2 (download) lines, where 2 is CommandPaddingDirect. It stores vision: {streams, up_direct, down_direct} per phase in the run JSON and records an anomaly when a stream did not switch. cmp report adds a table of these counts to tables.md. It ranks the reality-tlsin upload metrics only when every upload stream of every run went direct. Results recorded before this change have no Vision data, so they stay "not comparable", and 2026-10-18-four-cores/RESULTS.md is left as it is.

Proof, on a runner (throwaway PR #128, run 39109702359: all four servers × 3 repetitions, bulk + fixed phases):

phase Xray sing-box mihomo Citrus
dl1 up 3/3, down 3/3 up 3/3, down 3/3 up 3/3, down 3/3 up 3/3, down 3/3
ul1 up 3/3, down 3/3 up 3/3, down 3/3 up 3/3, down 3/3 up 3/3, down 3/3
dl32 up 96/96, down 96/96 up 96/96, down 96/96 up 96/96, down 96/96 up 96/96, down 96/96
ul32 up 96/96, down 96/96 up 96/96, down 96/96 up 96/96, down 96/96 up 96/96, down 96/96
dl1_fixed / ul1_fixed 3/3, 3/3 3/3, 3/3 3/3, 3/3 3/3, 3/3

That is 324 of 324 tunnels direct in both directions. Single-stream upload per repetition, MB/s: Xray 1370/1126/1197, sing-box 1192/1336/1350, mihomo 1446/1478/1408, Citrus 932/1413/1267. There is no ~400 MB/s mode any more; before, Citrus's three values were 385, 392 and 2209. On the runner's single-vCPU sink these MB/s are sink-bound, so they show the switch, not a ranking.

A local run on the reference host (i7-14700K) did not happen: the shared Docker host was busy with other benchmarks for hours, and a process from another build was stuck in D state there (see the pkill fix below).

Also: startClient used to kill a stale client with pkill -f. With --pid=host that reads every process of the host and blocks on one stuck in D state, which hung runs on our shared Docker host. It now kills the client named in its own pid file.

2. Nightly perf check (.github/workflows/perf-nightly.yml)

  • Triggers: nightly (37 2 * * *), workflow_dispatch (both check out dev), and pull_request on changes under test/bench/compare/** or the workflow itself. Schedule and dispatch only run from the default branch, so the nightly starts once this reaches main.
  • Runs run.sh with BUILD=host: Citrus is built with the release flags on the pinned toolchain (setup-go.sh 1.26), with Go caches. Servers are Citrus and mihomo v1.19.32 (the harness pin); protocols are REALITY, Trojan, SS2022 and Hysteria2; phases are mem (1000 tunnels, SETTLE=2s), hs and bulk, with 2 repetitions of a 1 s ramp + 3 s window. On the 4-vCPU runner the server gets cpuset 0, the client 1-2 and the sink 3.
  • Gate (cmp gate): for each protocol and metric (dl/ul 1 and 32 streams, CPU/GB dl32/ul32, conn/s, CPU per connection, RSS per tunnel) it computes the ratio of medians Citrus/mihomo, inverted for CPU and memory so that above 1 means Citrus is better. It compares that ratio with test/bench/compare/ci/baseline.json and fails if the ratio is more than tolerance (0.2) below the baseline, or if Citrus has no value where mihomo has one. The table goes to the job summary. runs/, tables.md and ratios.json (this run's ratios, ready to become a new baseline) go to the perf-results artifact.
  • Baseline: the lowest ratio of three runs of this PR per metric. Run-to-run spread on the runner was 1–6% for conn/s, CPU per connection and most uploads, and up to 25–38% for 32-stream download on REALITY and Trojan (only upward from the minimum). The minimum minus 20% leaves room for that. I checked that a lowered baseline fails the job: a ×1.5 trojan ul32_mbps baseline produced ratio 1.584, baseline 2.376 (-33%) and exit 1.
  • Permissions: contents: read. Actions are pinned by SHA (the same pins as bench.yml/pr-build.yml). actionlint is clean. The job takes about 12–14 min (perf job runs: 13m40s, 12m, 12m, 12m04s).

run.sh knobs added: BUILD=host (build with the host's Go) and SETTLE (the memory-phase wait). README updated.

…y per stream

The TLS sink writes a ready byte after its handshake and acknowledges the
upload command, and cmp waits for both, so Xray's Vision client reads the
command record alone and switches every upload stream to direct copy
instead of at random. The Xray client of reality-tlsin logs at debug
level; cmp measure counts per bulk phase the streams whose upload and
download went direct, and cmp report ranks the reality-tlsin upload
metrics only when every upload stream of every run went direct.
…aseline

Short comparison (REALITY, Trojan, SS2022, Hysteria2; mem, hs, bulk) on
ubuntu-latest, nightly on dev, on demand and on pull requests touching
the harness. cmp gate compares the Citrus/mihomo ratio of each metric
with test/bench/compare/ci/baseline.json and fails on a drop of more than
the tolerance. run.sh: BUILD=host builds with the host's Go, SETTLE
shortens the memory phase.
With --pid=host, pkill -f reads the command line of every process of the
host and blocks on a process stuck in the kernel (D state), which hung
the runs of the comparison for minutes on a shared Docker host.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant