fix(cleanup): use batch-level rate limiting to bypass remove_stream buffered(20)#6
Merged
Merged
Conversation
…uffered(20) The S3 object_store crate's delete_stream uses .try_chunks(1000).buffered(20), which runs up to 20 concurrent DeleteObjects batch requests. The previous per-path IntervalStream rate limiter was defeated by this internal buffering. Replace with manual batch collection: collect paths into batches of 1000, send each batch to remove_stream individually (producing exactly 1 API call per batch), and sleep between batches. This gives precise control over the actual S3 API request rate. Co-Authored-By: Jan van der Vegt <jan@exa.ai>
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
For S3 (batch_size=1000) and Azure (batch_size=256), batch files together matching the DeleteObjects API limit. For local/other backends (batch_size=1), rate-limit per file, matching the old per-path IntervalStream behavior. Co-Authored-By: Jan van der Vegt <jan@exa.ai>
Co-Authored-By: Jan van der Vegt <jan@exa.ai>
dpruijt
approved these changes
May 28, 2026
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.
Summary
The
delete_rate_limitparameter was ineffective because the S3 object_store crate'sdelete_streamimplementation uses.try_chunks(1000).buffered(20), running up to 20 concurrentDeleteObjectsbatch requests. The previous approach — wrapping the input path stream with anIntervalStreamticker — was defeated by this internal buffering.Fix: Replace per-path stream rate limiting with manual batch-level control:
remove_streamindividually (producing exactly 1DeleteObjectsAPI call per batch)ceil(1000/rate)ms between batchesThis gives precise control over the actual S3 API request rate. With
delete_rate_limit=3, the delete phase now sends exactly 3DeleteObjectsrequests per second (3000 keys/s), well under S3's 3,500 DELETE/s per-prefix limit.Also renames
calculate_duration→calculate_batch_intervalwith clearer semantics.Review & Testing Checklist for Human
calculate_batch_intervalmath: rate=3 → 334ms, rate=1 → 1000ms, rate=0 → clamped to 1000msdelete_rate_limit=3and confirm no 503 errors in the delete phaseNotes
Root cause:
object_store-0.12.5/src/aws/mod.rs:272-290—delete_streamdoes.try_chunks(1_000).buffered(20). Thebuffered(20)pre-fetches chunks from the rate-limited input stream faster than the ticker can gate them, allowing bursts of concurrent API calls that trigger S3 503 throttling.The non-rate-limited path (when
delete_rate_limitisNone) is unchanged — it still usesremove_streamdirectly for maximum throughput.Link to Devin session: https://app.devin.ai/sessions/bb810ab5769542e0a12b08c2505d2ae1
Requested by: @jan-exa