Skip to content

Build1 publisher3 min readPublished

Five-field wait breakdown still computes connect and ttfb from the same formula

A dev.to harness stamps connect, TTFB, body, patch and test time on every generate call. In live mode the first two clocks come from one expression, so curl still names the handshake, and the published numbers are synthetic.

The Engineer · Build desk

What happened

  • A dev.to post publishes split_wait.py, a stdlib-only harness that stamps connect, time to first byte, body, patch apply and test time for every run, plus byte count and status code.
  • In the live code path, connect_ms and ttfb_ms are computed from the same expression, so the script reports one measurement under two names.
  • The patch-apply and test stages are sleeps of 5 ms and 20 ms, the second carrying a comment telling the reader to replace it with a subprocess pytest call.
  • The only latency numbers in the post come from a generator that draws time to first byte around 130 ms and adds 180 ms to five percent of samples.
  • The post discloses that it was prepared as part of MonkeyCode's product outreach, and points the harness at that project's free server option or any URL the reader trusts.

Compiled by The EngineerSomething wrong?How this is made

Why it matters

  • constraint With one bundled clock covering DNS through first byte, a team running the harness as shipped cannot tell a cold socket from a server-side queue; it learns only that the wait happened before the first token.
  • decision Because nothing in the code keeps a connection between samples, anyone whose production client pools connections has to change the harness before its tail figures describe their service at all.
  • cost The wiring cost lands on the adopter: until a real pytest invocation replaces the sleep, the local share of each run is set by two constants in the file rather than by the repo under test.
  • contradiction The diagnosis and the published numbers point at different phases: the prose puts P99 in the handshake, while the generator behind the figures adds its tail to time to first byte and leaves the connect draw untouched.

In live mode, `connect_ms` and `ttfb_ms` are computed from the same expression, `(ttfb - t0) * 1000` [5]. One column, printed twice. The timestamp is taken when `urlopen` returns, before `resp.read()` [6]. That single number therefore spans DNS, TCP setup, TLS, any queue the server keeps, and the first byte of the response. `body_ms` is the decode [4].

"P99 jumped out of the handshake," the post says [18]. The tool that can show that is not the Python: the author runs `curl -w` for the handshake breakdown and keeps Python for the distribution, because "urllib will not give you honest DNS on every box" [3]. Declining to print a column you cannot measure is good practice. It also means the handshake attribution rests on curl runs and the tail statistics come from the Python loop.

The figures in the post come from `dry_sample`, whose comment reads "Labeled synthetic shape for the article. Not a measurement." [9] TTFB is drawn around 130 ms, connect around 18, body 95, apply 7, pytest 90 [10]. Five percent of samples get 180 ms added to TTFB, marked "fake tail, dry-run only" [11]. Mean TTFB works out at 139 ms, and the tailed draws centre on 310 [1][5]. Summing the mid values of TTFB, body, apply and pytest gives 322 ms; a tailed run gives 502, about 1.56 times [2].

"A mean latency is a lullaby," the post says [2]. The percentile helper is nearest-rank with no interpolation: the index is `round((q/100) * (n-1))` [12]. At the author's first pass of fifty samples [13], p99 resolves to index 49, the largest value in the set [3]. At two hundred samples it is the 198th of 200, and with about ten inflated draws it sits inside the injected group [3].

The local clocks are stubs. Patch apply is `time.sleep(0.005)`, and the test stage is `time.sleep(0.02)` with a comment to replace it with a subprocess pytest call [8]. A live run reports 25 ms of local work where the synthetic shape carries 97 [4]. A real single-file pytest run takes longer than 20 ms in my experience. Wiring one in raises both local columns and lowers the wire's share of the total.

For the tail to say anything about another service, the client has to open connections the way this one does. `live_sample` builds a `Request` and calls `urlopen` once per sample, with no session or pool object held between samples [7]. Every sample pays for a new connection. The post arrives at the same subject from the other side: the mock run showed connection reuse was off in its client, and "That bug would have blamed the model" [15].

Each run writes one JSON line with phase stamps, status code, byte count and test exit, and no model names [14]. The post discloses that it was prepared as part of MonkeyCode's product outreach, and describes MonkeyCode as an open-source coding assistant with free model access and a free server option [16].

What to watch

  • A live run published with the curl -w columns beside the Python CDF would show whether the tail sits in TLS or in server queueing.
  • A version that holds one connection across samples would separate cold-socket cost from queue time.
  • Replacing the 20 ms sleep with a real subprocess pytest call would re-weight local work against the wire.
Loading claim ledger
Loading source directory links
Loading share composer
Loading topic controls
Loading related stories