Repository navigation
perf(s3): probe the fan-out with one chunk instead of a full wave (#514) - #528
Conversation
An abandoned parallel read used to transfer 98% of the stored body before learning it was on the wrong path — 4,221,321 of 4,293,520 bytes for a 2 MiB read of an 8 MiB compressed object, which are precisely the bytes seekable framing (#185) exists to avoid. Two requests made to learn something already known added up to that: - every chunk was launched at once, so concurrency x chunk_size was in flight before any chunk's headers said the object was encoded; - the abandoned fan-out reported only *that* the object was encoded, so GetObject issued a ranged GET to find the seekable descriptor that the abandoned chunk's own response headers had already carried. That GET comes back encoded, so its bytes are stored bytes nobody uses. Neither was a mistake when written. #228 chose attempt-then-fall-back over HEAD-first so establishing whether an object is encoded costs compressed objects rather than every large read, and at the time a compressed object was already paying a whole-body fetch — the chunks were free. Framing removed that fetch and left them as the entire cost. Chunk 0 now goes out alone and the rest wait on its response headers, a headerProbe declines that chunk's body once the headers say the object is encoded, and the encoded signal carries the metadata so the framed path starts from what is in hand. The 2 MiB read at offset 0 drops from 4,221,321 bytes to 1,074,275 — the same cost as the same read past the end of the stored body, which is what framing says it should be. What it pays instead is one round trip of first-wave parallelism, not a HEAD: chunk 0 is a chunk of the read itself, wanted whatever the answer turns out to be. TestFanOutOnAnUncompressedObjectCostsNoExtraHead still holds that. The probe's decline is reported as a success, not an error. Every non-nil return in that closure reaches s3-get's circuit breaker and the health tracker, and a routing decision is neither — an error there would degrade the component on reads that all succeed.
…ame (#514) The type carrying the encoded signal's metadata is fanOutEncodedError, not fanOutEncoded: errname requires the xxxError form for a type implementing error, and only `--new-from-merge-base` sees it because the rest of this file predates the linter. The CHANGELOG entry lands under Changed rather than Fixed. Every read on this path returned the right bytes before and after; what moved is the byte count.
#514) CI measured 2,122,851 bytes on the read the local run measured at 1,074,275: the same 1 MiB difference the "probe never declines the body" mutation produced. Both runs declined the body. Only one could see it. testaws counts bytes the emulator *wrote* toward the client, and closing a response body mid-stream does not unwrite what a socket buffer already accepted. darwin's write failed after 614 bytes; the Linux runner's loopback swallowed the whole 1,048,576-byte chunk before the close landed. So the saving is real and the measurement of it is not portable. Assert it where it is deterministic instead. BackendMetrics gains FanOutProbes and FanOutProbeDeclines, recorded where the verdict is acted on, in the shape SeekableWholeFallbacks already uses and for the same reason: a silent failure mode needs a number attached to it. The byte budget grows to tolerate one abandoned chunk, which demotes it to a backstop — an abandoned body and an extra chunk are the same 1 MiB — so the comment now says which assertion catches what.
…med to (#514) 6d874a8's message says it recorded the CHANGELOG entry and its diff touches two Go files. The entry was never written, so a user-facing byte-count change and a new pair of metric fields had no line in Unreleased. Written now, with the metrics and the test under Added and the read itself under Changed rather than Fixed: every read on this path returned the right bytes before and after, and what moved is what it cost to get them.
CI caught the assertion, not the fixThe 2,122,851 is 1,074,275 + 1,048,576 — the framed cost plus exactly one chunk. It is also, to the
So the saving is real and platform-independent, and the measurement of it is neither. What changed
Mutations, re-run against the new assertions
The third row is new and is the one that matters for a counter-based assertion: it confirms the |
Closes #514.
Measured, before and after
A 2 MiB read of an 8 MiB ~50%-compressible object, 1 MiB chunks, concurrency 4, stored in ~4.29 MB:
The second row is what #514 says a framed read should cost. The first row now matches it to within 51
bytes, which is the point: both reads end up on the framed path, so they should cost the same thing,
and the difference was entirely bytes moved before the read knew where it was going.
Where the 98% came from
Two requests made to learn something already known.
parallel_read_concurrency × read_chunk_sizewas in flightbefore any chunk's headers could report a
Content-Encoding.GetObjectthen issued aranged GET to find the seekable descriptor — which the abandoned chunk's own response headers had
already carried. That GET comes back encoded, so its bytes are stored bytes the read never uses. For
the measured case it was half the waste: 2 MiB of chunks plus 2 MiB of rediscovery.
Neither was a mistake when written, and the issue says so. #228 chose attempt-then-fall-back over
HEAD-first so that establishing whether an object is encoded costs compressed objects rather than every
large read, and at the time a compressed object was already paying a whole-body fetch — the abandoned
chunks were genuinely free. #185 removed that fetch and left them as the entire cost. The premise
changed; the code did not.
The fix
Option 2 from the issue, all three parts:
0 produced no headers, so it failed — a 416 for a read starting past the end of a compressed stored
body is the routine way that happens — and the rest are not launched then either.
headerProbedeclines chunk 0's own body once those headers say the object is encoded.getObjectRangegains an optional hook that runs where the headers are in hand and the body has notbeen touched.
fanOutEncodedError), so the framed path startsfrom the descriptor already in hand instead of issuing the rediscovery GET.
What this pays is one round trip of first-wave parallelism on a large read. Not a HEAD — chunk 0 is
a chunk of the read itself, wanted whatever the answer turns out to be, which is the distinction
TestFanOutOnAnUncompressedObjectCostsNoExtraHeadexists to hold and which the issue names as the testany fix has to keep green. It is green.
The probe's decline is a success, not an error
Every non-nil return in that closure reaches
s3-get's circuit breaker and the health tracker. Arouting decision is neither. Returning an error there would trip the breaker on every large read of a
compressed object and take a component degraded on reads that all succeed — the same class of mistake
TestFanOutFallbackLeavesNoHealthErrorswas written for, and that test still passes.One integrity restriction worth naming
Only chunk 0's own headers are handed forward, and only when chunk 0 is what saw the encoding. A
later chunk seeing an encoding chunk 0 did not means the object was overwritten mid-read, so the
descriptor in hand describes a generation that is gone; pointing the framed read at frame offsets from
the wrong object is worse than spending a request. That case returns the bare sentinel and falls back to
rediscovery, which is what every case did before this. The HEAD-resolved path is safe to hand forward,
because the HEAD is a fresh authoritative read of the current generation.
Mutation testing
Six mutations, each a compiling change, each caught:
GetObjectignores the metadata handed backTwo of those changed the test rather than confirming it.
The first mutation I wrote survived, and it was the wrong mutation: it left the
<-probedwait inplace and only dropped the verdict check, so the siblings were launched after chunk 0's headers and
cancelled microseconds later, transferring nothing. The real pre-fix behaviour launches them before
the wait. Rewritten that way it is caught — but a mutation that passes for the wrong reason is worth
recording, because it looks identical to a load-bearing line in a survivor list.
The byte assertion was originally a fixed budget (
stored * 3/4) and that budget passes with theprobe's body-declining removed — 2,122,851 against a 3.2 MB budget. Any budget loose enough to
survive the compression ratio moving is loose enough to hide a whole 1 MiB chunk. It is now calibrated
against the read past the end of the stored body: every chunk of that read is refused with a 416, so it
cannot transfer a chunk byte even in principle, and what it moves is the framed cost of a 2 MiB read
of this object. The allowance is a quarter of a chunk; the observed difference is 51 bytes.
The last mutation deadlocks rather than failing, and it deadlocks on the ordinary case. No test can turn
that into a clean failure — the line itself is the fix — so the code comment says so rather than leaving
it to be rediscovered from a timeout.
Verification
go test -race ./internal/storage/s3/passes; so dointernal/vfs,internal/fuse, andinternal/compression.golangci-lint run --new-from-merge-base=mainon the package: 0 issues.internal/adaptercannot be built on this machine —runtime/cgorefuses without an accepted Xcodelicense — so CI is the first place that package compiles against this change.