Skip to content

feat: keep the default request queue in memory for the first 30 s of a run - #45

Merged
metalwarrior665 merged 2 commits into
masterfrom
feat/spilling-request-queue
Nov 17, 2026
Merged

metalwarrior665 merged 2 commits into
masterfrom
feat/spilling-request-queue

Conversation

@metalwarrior665

@metalwarrior665 metalwarrior665 commented Nov 17, 2026 •

Copy link
Copy Markdown
Member

On the platform, the run's default request queue now starts in memory and moves to the platform queue after 30 s. It uses SpillingRequestQueueBackend from apify/crawlee-rs#27. A short run makes one request queue API call, the startup check below. Unlike in JS, its queue stays empty in the Apify console.

Requires apify/crawlee-rs#27. Cargo.toml pins crawlee-rs to that PR's branch commit (8a69f56). It must be repinned to master once that PR merges.

Option and defaults

  • InitOptions::spill_request_queue_after: Option<Duration>, Some(30 s) by default. None uses the platform queue from the start.
  • The raw ApifyStorageBackend opts in with .spill_default_request_queue_after(..).
  • Only the default queue on the platform with RequestQueueAccess::Single starts in memory. Named, aliased and shared queues stay on the platform from the start, since other clients may read them. Local runs are unchanged.

What is committed

  • Handled requests are added as handled, with handledAt, which goes through the client's extra fields; tests check that the platform stores it. Re-adding one reports it as handled, and a resumed run does not crawl it again.
  • Pending requests keep their order.
  • Requests in progress finish on the platform.

Both platform queue backends now treat a request added with handledAt as handled: it stays out of the local head, counts as handled, and is reported as handled when re-added.

When it moves early

  • At once on migrating and aborting, before the reboot or exit.
  • On Actor::exit, if unhandled requests are still in memory.
  • On persistState, once the 30 s are over, for a queue nobody calls.

Where a restarted run starts. No platform variable tells a restarted run apart, so the queue itself decides:

  • During Actor::init, the run lists one request of the default queue (limit=1). The listing runs in the background, concurrently with the record prefetch, so it adds no round trip in sequence.
  • If the queue holds any request, handled or not, the default queue starts on the platform. This covers a run that migrated or was resurrected after its queue moved.
  • If the queue is empty, it starts in memory.

The listing is used rather than the queue's counters because it is consistent, while the counters can lag for seconds after the previous container's writes, for example right after a migration commit. Opening the queue waits for the check. If the check fails, the platform queue is used.

A short run that is resurrected starts its queue over, because nothing of it was stored. The README and docs/allowed-differences.md describe this.

🤖 Generated with Claude Code

https://claude.ai/code/session_0148RYR4BTGyCYHENSRZjC3S

…a run

On the platform, the run's default request queue now starts in memory and moves
to the platform queue after `InitOptions::spill_request_queue_after` (30 s by
default; `None` keeps the platform queue from the start), through the
`SpillingRequestQueueBackend` of crawlee-rs. A short run then makes no request
queue API calls. Named, aliased and shared queues, and local runs, are as
before; the raw `ApifyStorageBackend` opts in with
`spill_default_request_queue_after`.

At the switch, the handled requests are added to the platform queue as handled
(with `handledAt`), so they stay deduplicated, also in a resumed run; the
pending ones keep their order and those in progress finish on the platform.
The queue moves at once on `migrating` and `aborting`, on exit when requests
are left in memory, and on `persistState` once its time is over, so nothing is
lost. After the move, the run writes `CRAWLEE_REQUEST_QUEUE_SPILLED` to the
default key-value store; `Actor::init` reads it ahead with the other records,
and a migrated or resurrected run that finds it opens the platform queue
directly.

Both platform queues now treat a request added with `handledAt` as handled:
not in the local head, counted as handled, reported as handled when added
again.

Points crawlee-rs at the branch commit with the spilling queue.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0148RYR4BTGyCYHENSRZjC3S
…self

Drops the `CRAWLEE_REQUEST_QUEUE_SPILLED` record: nothing is written at the
switch, nothing read at the start. Instead `Actor::init` lists one request of
the default queue, in the background beside the record reads, so it adds no
round trip. If the queue holds any request, handled or not (a run migrated or
resurrected after its queue moved), the default queue is on the platform from
the start; if it is empty, it starts in memory. The listing is consistent,
unlike the queue's counters, which can lag for seconds after the previous
container's writes. Opening the queue waits for the check; when the check
fails, the platform queue is used.

A short run now makes that one request queue call, and no other.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0148RYR4BTGyCYHENSRZjC3S
@metalwarrior665
metalwarrior665 merged commit f9c5a52 into master Nov 17, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants