feat(deep_crawling): allow configuring batch_size and dispatcher - #2246
Open
yashikam19 wants to merge 2 commits into
Open
feat(deep_crawling): allow configuring batch_size and dispatcher#2246yashikam19 wants to merge 2 commits into
yashikam19 wants to merge 2 commits into
Conversation
- BestFirstCrawlingStrategy: add a constructor param (default 10, matching the previous hardcoded module constant) controlling how many URLs are pulled from the priority queue per round. - BFSDeepCrawlStrategy and BestFirstCrawlingStrategy: add an optional constructor param, forwarded to their internal arun_many() calls when set. Both are opt-in and default to previous behavior - no change for existing callers.
Adds tests/deep_crawling/test_deep_crawl_dispatcher_batch_size.py: - BestFirstCrawlingStrategy.batch_size defaults to 10 (previous hardcoded value) and is overridable; verifies actual per-round batch sizes change accordingly (e.g. batch_size=5 over 12 queued URLs -> rounds of 5, 5, 2). - dispatcher defaults to None and is NOT forwarded to arun_many() in that case, so existing (pre-dispatcher-signature) test doubles keep working. - dispatcher, when explicitly set, is forwarded to arun_many() for both BFSDeepCrawlStrategy and BestFirstCrawlingStrategy.
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.
Related discussion: #2245
Summary
Adds two constructor parameters to
BFSDeepCrawlStrategyandBestFirstCrawlingStrategyfor finer concurrency control during deep crawls:batch_size(BestFirstCrawlingStrategyonly) — previously a hardcodedmodule constant (
BATCH_SIZE = 10) governing how many URLs are pulled fromthe priority queue per round before being handed to
arun_many(). Now aconstructor parameter, defaulting to the same value (10), so nothing changes
for existing callers.
dispatcher(both strategies) — previously neither strategy forwarded adispatcherto its internalarun_many()calls, so callers had no way tosupply their own (e.g.
SemaphoreDispatcher, or aMemoryAdaptiveDispatcherwith a custom
RateLimiter/CrawlerMonitor) - onlyCrawlerRunConfig.semaphore_countwas reachable, which controls concurrency count but not dispatcher behavior.
Now optional and forwarded when set.
Both changes are additive and opt-in —
dispatcheris only passed toarun_many()when explicitly provided, so the call shape (and any existingtest doubles built against it) is unchanged for the default case.
List of files changed and why
crawl4ai/deep_crawling/bfs_strategy.py- addeddispatcherparam, forwardedin both
_arun_batchand_arun_stream.crawl4ai/deep_crawling/bff_strategy.py- addedbatch_sizeanddispatcherparams;
batch_sizereplaces the module-levelBATCH_SIZEconstant at itsthree usage sites;
dispatcherforwarded in_arun_best_first.tests/deep_crawling/test_deep_crawl_dispatcher_batch_size.py(new) — coversbatch_sizedefaults/override/actual round-size behavior, anddispatcherdefault-omitted vs explicitly-forwarded behavior for both strategies.
How Has This Been Tested?
pytest tests/deep_crawling/ tests/general/test_deep_crawl*.py: 80 passed,0 regressions
Checklist: