Skip to content

feat(autoscaling)!: Add ConcurrencySystem to share one concurrency budget between crawlers - #2322

Open
Mantisus wants to merge 4 commits into
apify:v2from
Mantisus:split-autoscaled-pool
Open

Mantisus wants to merge 4 commits into
apify:v2from
Mantisus:split-autoscaled-pool

Conversation

@Mantisus

@Mantisus Mantisus commented Oct 14, 2026 •

Copy link
Copy Markdown
Collaborator

Description

Load monitoring and concurrency scaling move from AutoscaledPool into a new ConcurrencySystem. Pass one system to several crawlers through the new concurrency_system option to cap their combined concurrency. The autoscaling classes are now public in crawlee.autoscaling.

Autoscaling logs move to DEBUG, and max_tasks_per_minute now counts the tasks started over the last 60 seconds. Breaking changes are in the v2 upgrade guide.

Issues

✍️ Drafted by Claude Code

@github-actions github-actions Bot added the t-tooling Issues with this label are in the ownership of the tooling team. label Oct 14, 2026
@Mantisus Mantisus self-assigned this Oct 14, 2026
@Mantisus
Mantisus force-pushed the split-autoscaled-pool branch 2 times, most recently from a738bbb to 97286df Compare October 14, 2026 18:54
@Mantisus
Mantisus marked this pull request as ready for review October 14, 2026 19:48
@Mantisus
Mantisus requested review from janbuchar and vdusek October 14, 2026 19:48
@Mantisus Mantisus changed the title feat!: Add ConcurrencySystem to share one concurrency budget between crawlers feat(autoscaling)!: Add ConcurrencySystem to share one concurrency budget between crawlers Oct 15, 2026
@vdusek
vdusek requested a review from Pijukatel October 16, 2026 06:50
@vdusek
vdusek force-pushed the split-autoscaled-pool branch 2 times, most recently from 028fd2c to b6e4fad Compare October 16, 2026 07:59
Comment thread docs/guides/scaling_crawlers.mdx
Comment thread src/crawlee/autoscaling/_types.py
Comment thread src/crawlee/autoscaling/_autoscaled_pool.py
Comment thread src/crawlee/autoscaling/_concurrency_system.py Outdated
Comment thread src/crawlee/autoscaling/_concurrency_system.py Outdated
Comment thread src/crawlee/autoscaling/_concurrency_system.py
self._concurrency_system = concurrency_system
self._autoscaled_pool = autoscaled_pool = AutoscaledPool(
concurrency_system=concurrency_system,
consumer=ConcurrencyConsumer(id=str(self._id)),

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Note: self._id is shared by crawlers that share state, and a user-set id can collide with an auto-assigned one. Two such crawlers get equal (frozen) consumers, and both pools number tasks from "0", which breaks the "process-unique" contract for a custom per-consumer system. The bundled ConcurrencySystem ignores the consumer, so nothing breaks today. Maybe build one consumer per crawler in __init__ from its own class counter (e.g. f'{self.__class__.__name__}-{n}') and reuse it across runs?

✍️ Drafted by Claude Code

@Mantisus Mantisus Oct 16, 2026 •

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Good point.

I'd prefer that we switch to using strings for IDs and use them not only for state. We already have an issue for that: #1699

But this will work as a temporary solution.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

yes, we could do it, maybe could you prepare PR for that at first, then rebase this one?

Comment thread src/crawlee/autoscaling/_types.py Outdated
current concurrency 3, desired 5, overloaded: cpu 58% of the time (limit 40%)
```

To read the concurrency values in code, use `crawler.concurrency_system`.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Maybe we should mention the logging changes as well?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Do you think anything should be added to the “## Autoscaling logs moved to DEBUG” section?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Logger names changed as well, right (_autoscaling -> autoscaling)? So probably those please.

Comment thread src/crawlee/crawlers/_playwright/_playwright_crawler.py
Comment thread src/crawlee/autoscaling/_concurrency_system.py Outdated
@Mantisus
Mantisus force-pushed the split-autoscaled-pool branch from b9f1b02 to b6e4fad Compare October 16, 2026 13:39
@Mantisus
Mantisus force-pushed the split-autoscaled-pool branch from 39a2094 to 9294fec Compare October 18, 2026 16:57
@vdusek
vdusek self-requested a review October 19, 2026 11:19

This branch has not been deployed

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

Labels

t-tooling Issues with this label are in the ownership of the tooling team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants