Repository navigation
S3: avoid full-object reads for GetObject ranges - #10564
Open
tonypottera24 wants to merge 1 commit into
Open
tonypottera24 wants to merge 1 commit into
tonypottera24 wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Ranged
GetObjectcurrently reads the entire stored object before_handle_range_headerslices the requested bytes. Repeated small ranges over a large object therefore read the full object once per request.Add a slice reader to
FakeKey, using its existingSpooledTemporaryFileand per-key seek/read lock. The fullvaluegetter uses the same reader. Pass the selected key to the existing Range handler so it can resolve the range before reading its body. Authorization, version selection, conditional requests, Range parsing, checksum headers and byte responses retain their existing behavior.The HTTP regression test covers memory-backed and disk-backed keys, with both unversioned objects and a non-current version. It checks actual bytes and headers as well as the underlying read size. All four variants fail on the original source because a 16-byte response performs an unbounded read.
Validation on Python 3.14.4, boto3/botocore 1.44.3:
ruff check moto/s3 tests/test_s3,ruff format --check moto/s3 tests/test_s3with repository-pinned Ruff 0.14.10, andmypy moto/s3passed.A local decorator-mode comparison uses one disk-backed 128 MiB object and 32 requests for 1 MiB each. Each request verifies its returned bytes. Upload time is excluded; each source is sampled three times.
980d15c304e72c384dfb6aa8cae9b4bf39c73100fd4fa84f3Base wall-time samples: 1.973463, 2.007409, 2.068236 s. Changed samples: 0.036211, 0.035621, 0.034498 s. Both perform 32 underlying reads; the read amplification drops from 128x to 1x. These are local SDK/mock measurements, not AWS or network throughput.
Reproduce the measurement
Run this script in the same environment on the base and PR commits:
The
UploadPartCopyfollow-up is #10565 and reuses this reader in a separate commit.