Repository navigation
feat: keep the default request queue in memory for the first 30 s of a run - #45
Merged
Merged
Conversation
…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
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.
On the platform, the run's default request queue now starts in memory and moves to the platform queue after 30 s. It uses
SpillingRequestQueueBackendfrom 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.tomlpins 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.Noneuses the platform queue from the start.ApifyStorageBackendopts in with.spill_default_request_queue_after(..).RequestQueueAccess::Singlestarts 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
handledAt, which goes through the client'sextrafields; tests check that the platform stores it. Re-adding one reports it as handled, and a resumed run does not crawl it again.Both platform queue backends now treat a request added with
handledAtas handled: it stays out of the local head, counts as handled, and is reported as handled when re-added.When it moves early
migratingandaborting, before the reboot or exit.Actor::exit, if unhandled requests are still in memory.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:
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.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.mddescribe this.🤖 Generated with Claude Code
https://claude.ai/code/session_0148RYR4BTGyCYHENSRZjC3S