feat: implement per-domain request throttling (ThrottlingRequestManager)#3741
Open
harryautomazione wants to merge 2 commits into
Open
feat: implement per-domain request throttling (ThrottlingRequestManager)#3741harryautomazione wants to merge 2 commits into
harryautomazione wants to merge 2 commits 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.
Summary
This PR implements per-domain request rate-limiting and delay logic at the
RequestManagerlayer. It ports the design from Python's Crawlee (PR #1762) to the TypeScriptv4branch, addressing the architectural feedback from PR #3737.Context & Rationale
Previously, receiving an HTTP 429 status code triggered a
SessionErrorwhich retired and rotated the proxy/session immediately, leading to high IP churn and fast session depletion.By moving the throttling to the request manager layer:
Retry-Afterheaders and applies exponential backoff delays precisely to the affected domains.Key Changes
ThrottlingRequestManager(packages/core/src/storages/throttling_request_manager.ts): Implemented a new storage wrapper that implementsIRequestManager. It routes domain-specific requests to sub-managers, manages backoff delays, and runs a wake/sleep loop infetchNextRequestto avoid busy waiting.HttpCrawler&BrowserCrawler: Intercepted HTTP 429 status codes, extracted retry-after, registered the delay withThrottlingRequestManager, and forced a standard retry (avoiding session retirement).BasicCrawler: Integrated withRobotsTxtFileto register thecrawl-delaywhenrespectRobotsTxtFileis active.RobotsTxtFile(packages/utils/src/internals/robots.ts): ExposedgetCrawlDelayfromrobots-parser.Verification Results
test/core/storages/throttling_request_manager.test.tscovering routing, exponential backoff, headers parsing, and crawl-delay settings (5/5 passed).test/core/crawlers/http_crawler.test.tsverifying that HTTP 429 delays are respected and session is not retired (17/17 passed).