Skip to content

perf(cache): parallel sub-range requests for large S3 ranged reads#387

Open
worstell wants to merge 1 commit into
mainfrom
worstell/s3-parallel-ranged-reads
Open

perf(cache): parallel sub-range requests for large S3 ranged reads#387
worstell wants to merge 1 commit into
mainfrom
worstell/s3-parallel-ranged-reads

Conversation

@worstell

Copy link
Copy Markdown
Contributor

Full-object S3 reads already fan out across parallel range GETs, but a ranged read was served as a single-stream S3 GET capped at a fraction of available bandwidth. Chunked clients (e.g. the parallel git-snapshot restore) issuing ranged reads against an object that must be served from S3 therefore paid a structural penalty per chunk.

Large ranges now split into parallel sub-range requests, scaling the part size down (to a 4MiB floor) so ranges smaller than one configured download part still fan out across multiple streams. Small ranges (<8MiB) keep the single-stream path. All sub-range requests remain pinned to the same object revision via ETag.

Parallel downloads also now bound run-ahead: a token window caps fetched-but-unwritten chunks at 2×workers, so a consumer slower than the aggregate download rate applies backpressure to the workers instead of letting chunks pile up in RAM. Peak memory is 2 × download-concurrency × part size regardless of object size.

In end-to-end testing of cold-cache restores of a large repository, this cut restore time by ~38% and raised per-serve bandwidth ~2.7×.

@worstell worstell changed the title Parallel sub-range requests for large S3 ranged reads perf(cache): parallel sub-range requests for large S3 ranged reads Jul 14, 2026
@worstell worstell force-pushed the worstell/s3-parallel-ranged-reads branch from 07ef9f7 to 3ade69d Compare July 14, 2026 21:15
@worstell worstell marked this pull request as ready for review July 14, 2026 21:15
@worstell worstell requested a review from a team as a code owner July 14, 2026 21:15
@worstell worstell requested review from jrobotham-square and removed request for a team July 14, 2026 21:15

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3ade69dd3a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +72 to +74
// Read one byte then stall. The workers must park once the admission
// window (2 × concurrency fetched-but-unwritten chunks) fills, rather than
// racing ahead and buffering the remaining chunks in RAM.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Remove comments from top-level tests

This new inline explanation is inside a top-level test function, but /workspace/cachew/AGENTS.md explicitly says, "NEVER add comments to top-level tests," and only permits comments for non-obvious larger code blocks. Please remove this and the analogous explanatory comments in the new tests, or make the intent clear through subtest/helper names instead.

Useful? React with 👍 / 👎.

Full-object S3 reads already fan out across parallel range GETs, but a
ranged read was served as one single-stream S3 GET capped at a fraction
of available bandwidth. Clients issuing ranged reads against an object
that must be served from S3 therefore paid a structural penalty per
chunk.

Large ranges now split into parallel sub-range requests, scaling the
part size down (to a 4MiB floor) so ranges smaller than one configured
part still fan out. Small ranges keep the single-stream path, and all
sub-range requests remain etag-pinned.

Parallel downloads also now bound run-ahead: a token window caps
fetched-but-unwritten chunks at 2 x workers, so a consumer slower than
the aggregate download rate applies backpressure instead of letting
chunks pile up in RAM. Peak memory is 2 x DownloadConcurrency x part
size regardless of object size.
@worstell worstell force-pushed the worstell/s3-parallel-ranged-reads branch from 3ade69d to 0ba43f7 Compare July 14, 2026 21:42
@alecthomas

Copy link
Copy Markdown
Collaborator

I actually have no idea what a "sub-range" request is, as opposed to just a range request, but instead of this, can we replace all the internal S3 parallelisation with our existing range reader machinery?

That was what I was planning to do after getting all the other range reading working.

ie. delete the internal S3 parallelisation and instead use ParallelGet in the Tiered backend for syncing the lower tiers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants