Skip to content

fix(autoscaling)!: Finish AutoscaledPool only when idle and scope stop() to the current run - #2332

Merged
vdusek merged 5 commits into
apify:v2from
Mantisus:pool-optimization
Oct 28, 2026
Merged

vdusek merged 5 commits into
apify:v2from
Mantisus:pool-optimization

Conversation

@Mantisus

Copy link
Copy Markdown
Collaborator

Description

AutoscaledPool now calls is_finished_function only when none of its own tasks are running and it can't start a new one, either because no task is ready or because a shared concurrency system has no free capacity. Before, it was called on every loop iteration, even with tasks in flight.

  • Crawlers no longer query the request manager's is_finished() every half second during a crawl, so storage backends get fewer calls.
  • A pool whose is_task_ready_function always resolves to True no longer finishes. It has to resolve to False once the work runs out. The upgrade guide covers this.
  • A paused pool doesn't finish until it's resumed.
  • crawler.stop() now applies only to the current run. A crawler that was stopped once used to end every later run() immediately.
  • After stop() or reaching max_requests_per_crawl, the crawler logs once that it takes no new requests and again when the remaining requests have finished. The stop reason no longer ends with a double period.

Issues

@github-actions github-actions Bot added the t-tooling Issues with this label are in the ownership of the tooling team. label Oct 15, 2026
@Mantisus Mantisus changed the title fix!: call is_finished_function only when AutoscaledPool is idle fix!: Call is_finished_function only when AutoscaledPool is idle Oct 15, 2026
@Mantisus Mantisus self-assigned this Oct 15, 2026
@Mantisus Mantisus changed the title fix!: Call is_finished_function only when AutoscaledPool is idle fix(autoscaling)!: Call is_finished_function only when AutoscaledPool is idle Oct 15, 2026
@Mantisus
Mantisus marked this pull request as ready for review October 21, 2026 17:39
@Mantisus
Mantisus requested review from Pijukatel and vdusek and removed request for vdusek October 21, 2026 18:06

@vdusek vdusek left a comment

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.

Probably a few last comments

Comment thread docs/upgrading/upgrading_to_v2.md Outdated
Comment thread tests/unit/autoscaling/test_autoscaled_pool.py Outdated
Comment thread src/crawlee/crawlers/_basic/_basic_crawler.py
@Mantisus
Mantisus requested a review from vdusek October 27, 2026 20:23
@vdusek vdusek changed the title fix(autoscaling)!: Call is_finished_function only when AutoscaledPool is idle fix(autoscaling)!: Finish AutoscaledPool only when idle and scope stop() to the current run Oct 28, 2026

@vdusek vdusek left a comment

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.

LGTM

@vdusek
vdusek merged commit d4f1520 into apify:v2 Oct 28, 2026
34 of 35 checks passed
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