Repository navigation
Conversation
RUSTYGET_TEST_STATE_SYNC_DELAY_MS delays every sync of a saved state file and of its directory, as a disk busy with a post-processing move does (6790: 0.4-3.5 s per fdatasync). queuesyncslow downloads six files with that delay at 1 s and FlushQueue=yes and bounds the time: while the queue coordinator waits for those syncs it hands out no articles. This commit alone shows the slowdown; the fix follows. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LG44gYUGuwLMB2hw7HQGbM
The queue coordinator saves the partial states, the progress and the queue once a second under the queue lock. With FlushQueue=yes each save syncs the file and its directory; on 6790 a post-processing move kept the queue disk busy, a single fdatasync took 0.4-3.5 s, and while the coordinator waited it handed out no articles (108 MB/s fell to 4-20 MB/s, 10-50 of 205 connections busy). The content is still serialized under the lock, so every file is a consistent snapshot, but the write, the sync, the rename and the directory sync now run on a queue-saver thread (statesaver.rs) for the coordinator thread. Jobs run first in, first out; a newer save of a file still queued replaces its content in place, so partial states, progress and queue land in the order they were saved, and a delete goes behind the writes it follows. Crash safety is as before: .new, sync, rename, directory sync. Other threads write inline as before, after the jobs queued for the same file. Readers (restart, a file's article list reloaded) first run or wait for the file's queued job and read with no save touching it. The coordinator drains the saver before it exits. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LG44gYUGuwLMB2hw7HQGbM
A panic in a background save no longer kills the queue-saver thread (later saves and the coordinator's drain would wait for it forever). The message log n<id>.log is appended and read directly, so its delete stays inline instead of queueing behind other saves. The module doc states what crash-time ordering across files is (not) kept. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LG44gYUGuwLMB2hw7HQGbM
queuesyncslow still took 37-41 s (bound 30 s, 86 s before) on Linux x86_64, arm64 and macOS: other threads (the API adding an NZB, post- processing, twin and dupe work, file completion) save the queue and the file infos inline under the queue lock, and the coordinator waits for that lock; and a coordinator reading a file whose save was queued ran that save, sync included, itself. While the coordinator runs, the saves of every thread are now queued; before and after (startup, the final saves of a shutdown) they run inline as before, and leaving the scope drains the queue. A reader of a file whose write is queued reads that content from memory instead of waiting for the sync; a queued delete runs at once (no sync). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LG44gYUGuwLMB2hw7HQGbM
historyeditlist failed at 6846969d (x86_64 and arm64): an API edit's queue save was queued, the call answered, and a kill right after lost the change. Queuing every thread's saves made acknowledged changes non-durable, even against a plain process crash. Now only the coordinator's saves are queued and never waited for. A save another thread makes under the queue lock is queued too, and that thread waits for it right after it releases the lock (qqueue::CurrentQueueLock drop -> statesaver::queue_lock_released): the coordinator never waits for the lock during someone's sync, and an edit or an added NZB is on disk, synced as before, when the caller gets its answer. A write coalesced into a queued one keeps the older sequence number, so a waiter for the older save waits for the newer. Other saves (no queue lock held) run inline as before. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LG44gYUGuwLMB2hw7HQGbM
settled(), an inline save superseding a queued one and a reader running a queued delete took the job off the queue and then waited, with the saver lock released, for an older save of the same file. In that gap the job was neither queued nor running, so a thread waiting for its save could return before the content was on disk. They now wait until the file is idle first and take and mark the job in one hold. Also fixes the indentation of one Job literal. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LG44gYUGuwLMB2hw7HQGbM
RUSTYGET_TEST_COORD_PASS_DELAY_MS sleeps after each pass of the queue coordinator loop, as a long queue and queue-lock waits slow it on 6790. queuebatchstart (30 connections, 1 s per article, 100 ms per pass) asserts that at least 24 articles are in flight at once and that a small first item and a second item download together. Starting one article per pass, this commit alone stays near 10 in flight; the fix follows. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LG44gYUGuwLMB2hw7HQGbM
Each pass of the queue coordinator took the queue lock, scanned the queue, started at most one article, then ran the live drains and slept 5 ms when nothing started. In flight = start rate x article time, so a slow pass (a long queue, lock waits) capped the articles in flight: 6790 held about 117 of 345 connections busy on one item while 148 items waited, and 10-58 earlier. Within one hold of the queue lock the coordinator now keeps starting articles while one is assignable, a connection is free and the downloads limit allows, up to 64. The pick is unchanged per article (get_next_article: fleet rules, dupe gate, held donors), a pick held for its dead-pick probe ends the batch, and a second item starts in the same pass once the first has nothing assignable. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LG44gYUGuwLMB2hw7HQGbM
One hold of the queue lock could cover 64 picks, each a queue scan; on a long queue the API and edits would wait for the lock meanwhile. A pass now also stops starting once 5 ms have gone by (the next pass goes on at once, with no sleep, when it started something). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LG44gYUGuwLMB2hw7HQGbM
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
The coordinator starts up to 64 articles per queue-lock hold, and stops a pass after 5 ms, instead of one article per pass. With 30 connections the baseline peaked at 11 in flight. Adds the RUSTYGET_TEST_COORD_PASS_DELAY_MS hook and the queuebatchstart scenario. Squash of three reviewed commits stacked on the saver-thread change (clean-room and delta reviews G2G). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LG44gYUGuwLMB2hw7HQGbM
|
Merged as the locally signed squash commit 2321559 (verified on GitHub), fast-forward onto 17d15f1 (PR1 squash, #744); tree identical to the reviewed head d63364d. Gate heads: farm x86_64 + arm64 green (cargo 0, test-daemon 0, 437/437 incl. queuebatchstart) on 28b89f07, review G2G. Final rebase onto 80c3fcd was patch-identical over non-overlapping main commits. Farm runs on d63364d continue as post-merge evidence. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d63364dacd
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| st.queue.remove(i); | ||
| st.queue.push_back(job); | ||
| st.next_seq |
There was a problem hiding this comment.
Preserve outstanding tickets when replacing writes with deletes
When the saver is backlogged, a non-coordinator thread can queue a save under the queue lock and wait for its sequence number after unlocking. If the coordinator then replaces that pending write with a delete (for example, when the queue becomes empty), this branch removes the original sequence and assigns a newer one. Since wait_for only waits for sequences <= the original ticket, the waiting caller can return while neither its save nor the superseding delete has reached disk. A crash at that point can restore stale state despite the caller's completed durability wait. Preserve the oldest outstanding sequence when moving a replacement to the back, including write/delete transitions.
AGENTS.md reference: AGENTS.md:L145-L148
Useful? React with 👍 / 👎.
Stacked on #744, merge after it. Owner: 6790-keeper.
What
The coordinator starts up to 64 articles per queue-lock hold (and stops a pass after 5 ms), instead of one per pass. Baseline peak in flight was 11 of 30 connections; with this change scenario queuebatchstart (30 conns, 1 s/article, 100 ms/pass; needs peak >= 24 and both items at once) passes. Test hook RUSTYGET_TEST_COORD_PASS_DELAY_MS.
Review
Clean-room plus delta reviews G2G on the batch commits and the 5 ms cap; rebases onto main are patch-identical.
Validation (GCE farm; Actions unavailable)
Rebased head 28b89f07 (base e00226f): x86_64 437/437, arm64 437/437 incl. queuebatchstart, cargo and test-daemon 0 on both. macOS: cargo test 1621 passed; test-daemon directunpacksimple timed out on the loaded m5air (known m5air-wrapper failure, passes on Linux; triaged separately). Final-base lines are in the comments.
🤖 Generated with Claude Code
https://claude.ai/code/session_01LG44gYUGuwLMB2hw7HQGbM