qqt

Interactive latency

Measuring the interactive terminal

Keystroke to glyph on two transports: the probe cells and the two invariants, the two-pane rig and its obstacles, reading the lag back out of the frames, and the publication step — enough to run it again elsewhere.

A terminal is judged by the echo, not by throughput. This page is the whole procedure — measuring that echo on two transports, filming it so a reader can watch it, and reading the lag back out of the frames. The numbers themselves live in the benchmark record §5; this page never restates them.

Written for someone on a different machine: the crate, a client box, and a far end across a WAN. The one rule underneath everything: the picture and the table must be the same event. Every number comes from a pty, and every clip is measured back into a number off its own frames. A clip that only illustrates a table is a claim; a clip that reproduces it is evidence.

Both transports must reach the same machine, with the same client binary, the same key and the same shell, or the comparison is measuring two boxes.

1. What is being measured

cell workload the sample
charecho a remote cat echoes one byte per keystroke write → verified echo of that byte
viscroll vi over a 500-line file, Ctrl-F page down write → last byte of the completed screen repaint
burst twelve keystrokes 6 ms apart write → first glyph, and write → twelfth glyph

The third cell is the one people forget. A single-key echo is one round trip; a burst is where a slow path shows its typeahead queue, and it is the two numbers together that describe what a fast typist feels.

examples/interactive_probe.py builds each sample on a pty in raw mode so the far end sees a terminal, not a pipe — an ssh command without a pty buffers and the measurement collapses.

2. Before the run

  • A release build (cargo build --release --locked); the harness starts a client from $HOME/bin/qqt unless one already listens on QQT_PORT.
  • Client certs, and an ssh key that works on both paths.
  • python3 on the client; on the far end only ssh, cat, vi, seq.
  • For the film: Xvfb, alacritty, tmux, xdotool, screenkey, ffmpeg with libx264, numpy and matplotlib. No GPU.

Confirm the tunnel before measuring anything:

qqt client -l 127.0.0.1:22222:127.0.0.1:22 -r <host>:<udp-port> \
  --certs-dir <dir> --stats 3

--stats must print connected=1 and a plausible rtt. The biggest time sink is the port: a rented container often publishes the server’s UDP port on a different number than it binds inside. Dialing the inside number from outside does not error — it times out, slowly, and looks like a broken build.

3. The numbers run

QQT_REMOTE=<host>:<udp-port> QQT_CERTS=<dir> \
RAW_SSH="ssh -p <port> -i <key> <user>@<relay>" \
  examples/bench-interactive-latency.sh ~/qqt-bench/interactive

SAMPLES (default 120 per cell per transport), BLOCK (10), CELLS and QQT_PORT tune it. Keep n ≥ 100: a p99 off 30 samples is an anecdote and the report claims a p99.

The alternation is not decoration. Transports swap which goes first each block, so a drifting path moves both columns together and a burst of congestion cannot masquerade as a transport win. Run them interleaved, never sequentially.

It writes:

  • samples.csv — cell,transport,metric,index,ms, one row per sample;
  • summary.tsv — n, p50, p90, p99, min, max, mean per cell and transport;
  • env.txt — host, binary version, both ssh command lines, RTT, rejections.

Rejections are counted and printed. A cell that rejects much of itself is telling you the far end is not where you think it is.

Two invariants that were bugs first

Both produced plausible-looking, wrong numbers before they were fixed. Anyone re-implementing the probe should expect to hit them.

Wait for the response to begin, then for it to finish. The reader waits up to first_wait for the first byte, and only then runs to quiet. A reader that times the quiet-off alone gives up before the first byte of a 250 ms round trip — then the late byte arrives during the next sample and is credited to it. The symptom is a slow path reporting suspiciously fast, bimodal numbers.

A redraw sample must actually be a redraw. The viscroll cell rejects any repaint under 1500 bytes. Without it, a Ctrl-F at the end of the file repaints only a cursor and is timed as a full screen; worse, a page-down whose tail is still arriving is counted into the next sample. Alternate Ctrl-F / Ctrl-B so every timed sample is a full screen and the cursor never runs off the end.

4. Film it

The rig is four processes under one Xvfb, captured by a single x11grab:

Xvfb :99  1920x1080x24          ffmpeg -f x11grab -framerate 60
 ├─ alacritty → tmux              └── the whole framebuffer: panes,
 │    ├─ pane 0: ssh via tunnel        keypress band, labels and clock
 │    └─ pane 1: ssh via baseline
 ├─ screenkey  (keypress band)
 └─ rig-overlay.py (labels + live clock)
Xvfb :99 -screen 0 1920x1080x24 -nolisten tcp &
bash examples/rig.sh up "<left label + p50>" "<right label + p50>"
bash examples/rig-record.sh typing /tmp/rig/typing.mp4
bash examples/rig.sh teardown

Scenes: typing, vi, burst, redraw, measure — the last is the measurement clip, one key every two seconds so every band pulse pairs unambiguously with one glyph.

Paths are overridable: RIG_DIR, RIG_DISPLAY, QQT_SSH, RAW_SSH, REMOTE_SHELL, QQT_BIG_FILE. The defaults name this box’s tunnel; set QQT_SSH/RAW_SSH for yours.

Why the panes are tmux panes

synchronize-panes fans one XTest event to both ptys in the same instant. The alternative — two windows, focus moved between them — sends the key to one, then the other, at two different instants, which quietly destroys the side-by-side claim. Both panes must also be the same shell on the same box: one prompt, one clear, one key.

The obstacles, in the order they bite

  • The far end auto-attaches its own tmux (many container images do). Its scrollback fills the frame and its status line eats rows. Start the remote shell as env TMUX_STARTED=1 bash -i or whatever kills the auto-attach. This one costs the most time and looks like a terminal bug.
  • screenkey has no --fixed-pos. Use --window -p fixed -g <WxH+X+Y>. The -s large shorthand computes band height as a fraction of the geometry, so it shrinks the band — and the font is sized from the band, so a taller band is the only way to a bigger glyph.
  • Xvfb has no window manager. Nothing places windows; every geometry is literal, and an overlay must re-lift() on a timer or the later-mapped terminal covers it.
  • pkill -f <pattern> matches the invoking shell’s own command line when the pattern appears in it, and kills the script mid-run. Use pkill -x.
  • Size the terminal to the band. x11grab captures a fixed 1920×1080; a tmux window sized 190×38 leaves a black margin under the panes. Measure the pixel band you have and give the terminal exactly those rows.

The clock is a window

rig-overlay.py draws one borderless window across the top: transport label over each pane, live HH:MM:SS.mmm at centre. Because it is a window it lands in the same x11grab as the terminals — the timestamp a reader freezes on is the frame’s own, not a stamp added at encode. That is what makes the lag measured on screen rather than asserted.

5. Read the lag back off the frames

python3 examples/rig-measure.py /tmp/rig/measure.mp4 --glyph-delta 20 \
  --json /tmp/rig/measure.json

It counts ink per frame in three regions from examples/regions.json — the screenkey band and one text row per pane — takes each band pulse as a key and the next rise in a pane row as its glyph, and pairs them in order. Edit regions.json if your layout differs; the committed values match rig.sh.

--glyph-delta is the pixel threshold for “a glyph appeared”: lower it until it catches the renderer’s antialiased first frame, raise it if the cursor blink counts. A 60 fps capture floors at 16.7 ms, so report the fast column as “one to three frames” rather than pretending to 1 ms precision. Agreement between this reading and the CSV is the check — they measure the same event by different routes, and a disagreement means one is wrong.

6. Publish

Two files per clip: the lossless -qp 0 original for measurement, and a -crf 22 -pix_fmt yuv420p -movflags +faststart transcode for the page. Posters come from the clip itself (ffmpeg -ss <t> -frames:v 1), never a separate screenshot, so a poster cannot show a frame the clip does not carry.

The notes reader turns markdown links into links, so a video is raw HTML:

<video controls preload="metadata" poster="/notes/<cat>/<slug>/pics/01.png" width="100%">
<source src="scene.mp4" type="video/mp4">
</video>

src resolves against the note’s directory; poster resolves against the page URL, so it needs the note-absolute path or the video plays with a broken poster. Verify every asset over HTTPS after the copy — a bucket mount’s read-back proves nothing.

7. What the result does and does not say

The transferable finding is the ratio on one measured path, with the RTT named beside it. The absolute numbers move with the vantage: a client closer to the far end sees both columns shrink and the shape survive. Reproduce it with your own two p50s — and if your baseline is a direct port rather than a relay, expect a much smaller gap, because most of the win is the relay hop the tunnel removes.

State the caveat in the same breath as the number. A benchmark that does not say where it was taken is a rumour.

← All documentation