~ knotless Search/
↑↓ move↵ open⇧↵ all results
0
0

Blobstore connections kept 90 s; a request failed on its way sent again

Merged
Merged chadtmiller.com asked to merge into main from chadtmiller.com/monolith:perf/blobstore-idle

In production, the server's blobstore requests to R2 averaged 162 ms across 13,141 requests. The bucket client dropped idle connections after 2 s, so most requests paid a new connection and TLS handshake: from the box, 75–110 ms on a new connection, 26 ms on a reused one. This keeps connections for 90 s, and sends once more over a new connection a request that failed before any answer.

Claude Opus 5.5 · high

What changes

Spec. BLOBS.md, "Requests to the store": a request goes over a connection an earlier one left open, and the server keeps one unused for up to 90 s. Every request to the store can be made twice to the same effect (a PUT of the same bytes to the same key, a GET, a DELETE). So a request that fails on its way, the connection closed before any answer came, is sent once more over a connection of its own, within the same time limit. Only one that fails so twice, or one the store answers and then fails, fails as "The objects" says. Two new entries under "How it is checked".

Harness. lib/s3.mjs records which connection each request came on. Two new --s3 steps:

  • resetOnce: the store resets each side's first read of a referenced blob, once. getBlob is compared, and both sides must answer 200 with the blob whole. The reference retries too.
  • keptConnection, on the server alone: two getBlobs 3 s apart. That is past the old 2 s idle timeout and within the store's 5 s keep-alive. The second read must go over the first one's connection.

pds-server. blobstore::Bucket holds a pooled client (90 s idle) and a client that keeps no connection. Bucket::send sends a failed request again over the second one, unless it failed to connect or timed out. All three ways of sending (exchange, get, fetch) go through it.

Why

pds_outbound_request_duration_seconds{target="blobstore"} on monolith.chadtmiller.com averaged 162 ms. Only 162 of 13,141 requests took under 50 ms. getBlob's median there is 96 ms. The 2 s idle timeout guarded against a store closing a connection just as a request goes out on it. Sending once more over a new connection handles that race, and keeps connections between requests.

How it was checked

  • Against the server as on main (its blobstore.rs built apart): resetOnce differs (reference 200, server 500), and keptConnection fails (connections 1 then 3). With the change, both pass: --s3 --only resetOnce,keptConnection.
  • cargo test -p pds-server --lib -- blobstore passes.
  • just quick passes here (all 7 runs, the --s3 crash run among them); cargo test -p pds-server --lib -- blobs:: migrate_blobs passes.

Shortcomings

  • The outbound client (outbound.rs, forwarded requests and did:web documents) still keeps idle connections for only 2 s. A forwarded POST cannot safely be sent twice, so it needs a different answer than this one.
  • An upload that the store took, but that failed on its way back, is now PUT a second time. That is the same object, and costs one more request.
Approved

This pull keeps blobstore connections for 90 s and sends a request that failed before any answer once more over a connection of its own. I found nothing that must change.

  • Server: Bucket::send sends over the pooled client. It repeats over the no-pool client only for errors that are neither connect nor timeout errors, and only when the request body clones. The retry runs inside the existing tokio::time::timeout at each call site, so the time limit stays as the spec says.
  • Spec and changeset: BLOBS.md and the changeset describe the behaviour, and the harness steps are named under "How it is checked".
  • Harness: the new steps tighten the suite and loosen nothing. The existing failedUpload and failedRead checks use unlimited failure rules, so a retry still fails and they should keep passing. I did not run them.

I did not check whether docs/guide/ mentions the 2 s idle timeout.

All checks have passed

4 passed, 1 skipped

Merged as 77b758e