Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

The performance gate

Every pull request that changes what the server is built from runs the perf job of CI, a required part of conclusion. It also runs on every push to main, and the release workflow runs it on the release commit before the release is drafted. The job measures the release build of ferropix with ferrohealth-perf, the performance gate every FerroHEALTH server shares. It fails when the server is busy at rest, or slower, heavier or busier under load than the build of its base, measured beside it on the same runner in the same job.

Why the head is judged against its base

GitHub’s hosted runners differ: two runners that report the same CPU model and memory can measure one commit 25 to 45 % apart in p50 latency and CPU per request. A baseline stored from one machine failed unchanged code on another, so the gate keeps none. It builds the base of the change and the change itself, the head, runs both on one runner, and judges the head over the base. The difference between machines reaches both alike and cancels.

The base is:

  • for a pull request, the merge base of the commit CI checks out with the pull request’s base branch, which is main as the pull request was merged into it;
  • for a push to main, the commit before the push;
  • for the release commit and a manual dispatch, the previous release tag.

What it runs

scripts/perf/gate.sh build builds the release server of the base, from git archive of the base commit under target/perf-base/, and of the head. scripts/perf/gate.sh run starts PostgreSQL and the stub OpenID Provider from the test image pins of docs/VERSIONS.md, then both servers, each with a database of its own: the head on port 8080 and MLLP port 2575 with perf/ferropix.toml, the base on 8081 and 2576 with the base’s own perf/ferropix.toml when it has one. The PIXm Manager, the PDQm Supplier, the PMIR Registry with its feed, the MLLP listener, the operator API and the outbox sender are all on. The script seeds the two patients of the testkit’s ITI-104 fixtures into each server and runs ferrohealth-perf ab over perf/plan.toml:

  1. Idle. No request for 60 seconds. The head’s CPU time must stay under 2 % of one core and its database under one transaction a second. These limits are absolute and compared with nothing: the outbox sender looks at the outbox at most every 30 seconds when it has nothing to send.
  2. Load, in pairs. Four pairs, each a load phase against both servers at once: 50 arrivals a second to each for 60 seconds after a 10-second warm-up, open loop, one server’s arrivals half an interval after the other’s, the server that leads alternating by pair. Run side by side, both arms see the same runner, whose speed can move by a third from one minute to the next. The arrivals go over PIXm ITI-83 by GET and by POST, the ITI-104 feed, PDQm ITI-78, the ITI-119 match, and the HL7 v2 feed, ITI-8, as an ADT^A01 over MLLP. Every request must be answered with the status the plan names, and every ITI-8 message with an AA acknowledgment of its own MSH-10.

Then the script plants an outbox poller that never waits beside the head, a sender that polls PostgreSQL while it has nothing to send, and runs the idle phase of perf/busy-loop.toml again. That run must fail on idle transactions, or the job fails: it proves the gate still catches the case it was built for.

Reading the report

Each load metric (throughput, latency p50, p95 and p99 per group, peak memory, CPU time per request and transactions per request) is the median of an arm’s four phases. Its noise floor is the worse of the two arms’ spread, how far an arm’s worst phase strayed from its median. A metric breaches when the head’s median is worse than the base’s by more than the larger of its tolerance and that floor; the tolerances are the plan’s [tolerance] table: latency and CPU 25 %, throughput 20 %, memory 20 %, transactions per request 10 %. It fails only when the head also breaches against the base in most of the pairs, so a stall in one phase clears and a regression, which repeats in every pair, fails.

The job summary holds the tool’s report: the outcome, the base commit, the head’s idle limits, and per metric the base, the head, their ratio, the tolerance, the floor, the threshold and in how many pairs the head breached. Requests the head answered other than expected are listed and fail the gate; those the base answered other than expected, such as a route the change adds, are notes, and a metric only one arm measured is noted and not judged. Each attempt uploads its reports as perf-report-attempt-<n>: the JSON reports under target/perf/, with every phase’s histograms, both servers’ logs and the base commit, so ferrohealth-perf compare --report target/perf/latest.json judges a report again without a server.

The tool exits 0 for a pass, 1 for a breach or a request answered other than expected, and 2 for a run it cannot judge: a phase whose generator could not hold its rate, whose second half differs from its first, or that stalled, and a base that fell behind the schedule.

Retries

Some runners stall every route for a whole job: the tails reach 100 to 500 ms while the p50 holds. The cause is the runner’s disk. Every audited request waits until its record is synced to disk (Deployment), and on those runners a sync takes up to hundreds of milliseconds, where a steady runner syncs in about 8 ms.

So the script samples the runner four times a second while the tool runs, into target/perf/runner.tsv, part of the attempt’s artifact. Each sample records how long a 16 KiB record takes to reach the disk the way the audit spool stores one (the file synced, renamed, its directory synced, on the spool’s file system), the CPU time stolen by the hypervisor and spent waiting on I/O, and the CPU clock. The job summary gives the percentiles.

An attempt is not judged, and exits 2, when:

  • a phase stalled: every route’s p99 is over ten times its p50 at once. The tool reports the phase and leaves it out of the judgement;
  • the head breached on a runner whose sync p99 is over 50 ms (SLOW_SYNC_MS in scripts/perf/gate.sh). That bound is six times the 8 ms of a steady runner and a fifth of the 270 ms of a stalling one.

An attempt that ends with exit 2 runs again on a fresh runner, since a run that cannot be judged says nothing about the code. At most two retries run, and the gate passes when the last attempt passed. A breach on a runner whose disk syncs in time fails at once, whatever its CPU model. The job summary names each attempt’s CPU model, its verdict, the runner’s samples and why a retry ran.

The budget of each transaction

The gate compares the head with its base under load. The budget holds each hot transaction to fixed ceilings, so a change that adds work fails in CI’s e2e job without a load run. The cases under app/ferropix-server/tests/it/e2e/budget/ send 20 requests of each of ITI-104 (a revision of a known patient), ITI-83 by GET and by POST, ITI-78, ITI-119 and ITI-8 over MLLP, over a store of about 200 persons. For each request they count:

  • the statements the server sends, BEGIN and COMMIT included, each a round trip, and the statements PostgreSQL runs nested in them, from pg_stat_statements;
  • the shared buffers those statements touch, which grows with the store when a statement reads more than it needs;
  • the bytes of write-ahead log, from pg_walinspect, with no full-page images;
  • the bytes of audit record the spool takes, and the bytes of the answer;
  • for ITI-8, the translations it asks the terminology server for.

Each ceiling is the measured value. A change that lowers a figure lowers its ceiling in the same pull request, and no ceiling is raised.

The capacity campaign

The gate compares a change with its base, and the budget holds each request’s cost; neither says how far the server goes. scripts/perf/capacity.sh measures that on a quiet host. up starts PostgreSQL, the stub OpenID Provider, the terminology server and the release server of the checkout; seed N feeds N synthetic patients over ITI-104; snapshot and restore keep the seeded store so every step starts from the same one; and run GROUP RATE runs one open-loop step of a plan under perf/capacity/ (ITI-83 by GET and POST, ITI-78, ITI-119, ITI-104, ITI-8, and a mix of nine reads to one feed) at the rate you give it, with the server’s CPU and memory sampled beside it.

Changing the plan or the tolerances

The plan is the head’s: a change to perf/plan.toml is measured on both servers in the same pull request. A tolerance is the product’s and moves only in a pull request that says why.