Repository navigation
runtime: steal hints and batched I/O wakes - #633
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (3)
🚧 Files skipped from review as they are similar to previous changes (3)
📝 WalkthroughWalkthroughThe runtime batches dispatched-completion wakeups and carries optional victim-executor hints through searcher election. Steal scans consume valid hints and propagate victim IDs. Null-callback I/O completions use ChangesExecutor wakeup and completion delivery
Estimated code review effort: 4 (Complex) | ~45 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
armSearcher now records the pusher's executor id in the elected searcher's steal_hint just before the wake (exclusive by construction: only the winner of the idle-bit claim writes, and the wake edge publishes the store), and stealWork consumes the hint as its scan start, falling back to the usual random circular sweep so a stale hint degrades to exactly the old behavior. Pushes whose work lands in the shared overflow queue (shed wakes, remote submissions) pass no hint; a successful steal propagates by pointing the next searcher at the same victim's remaining ring. The wake becomes an invitation with directions rather than a blind search warrant: the woken executor skips the random victim probing (average n_exec/2 cross-ring reads), while the work itself stays in the waker's ring until actually stolen, so the wake-to-pop race still decides whether anything migrates at all. Work distribution stays strictly pull-based; push-based placement remains the job of the shed path, which has a measured trigger. Alternatives probed and rejected on this codebase (details in notes/2026-07-31-scheduler-architecture-vision.md): raising the searcher token cap made fan workloads 11% worse (more thieves racing one ring head), and delivering ring batches into per-executor mailboxes at push time beat main on fan-in but is eager migration, i.e. shedding without a trigger, and needed three new protocol invariants to stay sound.
Task-wake completions (waitForIo) now set a null callback, which the loop routes into the dispatched queue instead of invoking anything: a null callback is the per-completion form of do_not_call_callbacks, and nextDispatched serves both. The executor drains the queue after every poll, signaling each waiter with per-push announces suppressed, and then makes one batched wake decision for the whole poll's worth of newly ready tasks: wake log2(ready) sleepers, hinted at this executor, since each steals half of what remains. Go's injectglist is the precedent - batch arrival deserves batch wakeup, bypassing the single-searcher token, which throttles speculation and a counted batch is not speculation. Early per-completion wakes bought nothing locally: a task woken mid-poll cannot run until the poll returns anyway, so the only thing immediate callbacks enabled was per-completion announce traffic (mid-poll steals, the churny kind). This removes the last per-completion indirect call and up to N-1 announce checks per poll. The subtle requirement, found via a hang in the TCP handshake test: an operation that completes inline during loop.add (socket open) enters the dispatched queue outside any poll, on the very thread about to park. So checkLocalWork drains the queue first, making pending wakes visible to every work check, pre-park checks included; the post-poll drain in park covers the sleeping side. Benchmarks: tcp many (1000 conns) +11% vs main, +9% vs steal-hints - the completion-burst shape this targets; lat/pipe/ping-pong/sleep neutral. worker_pool fan wakes come from running tasks, not completions, so this path does not affect them.
The batch and hint comments narrated the change instead of the code: contrasts with behavior that no longer exists, restated mechanisms at every call site, and justifications that only make sense while reviewing the diff. Keep the invariants (why a check must sit where it sits) and the non-obvious geometry (log2 coverage, token bypass), drop the rest.
Two commits, one story: wakes get smarter about where work is and how much of it there is.
Commit 1: steal hints
armSearcherrecords the pusher's executor id in the elected searcher'ssteal_hintjust before the wake (exclusive by construction: only the winner of the idle-bit claim writes, and the wake edge publishes the store).stealWorkconsumes the hint as its scan start and falls back to the usual random circular sweep, so a stale hint degrades to exactly the old behavior. The wake becomes an invitation with directions instead of a blind search warrant: the elected searcher skips the random victim probing, while the work stays in the waker's ring until actually stolen -- the wake-to-pop race still decides whether anything migrates. Hint sources: local announce passes the pusher's id; shed/remote wakes pass none (their work is in the shared overflow queue, checked first anyway); a successful steal propagates by pointing the next searcher at the same victim's remainder.Commit 2: batched I/O wakes (Go's injectglist, zio-shaped)
Task-wake completions (
waitForIo) now set a null callback, which the loop routes into the dispatched queue instead of invoking anything -- a null callback is the per-completion form ofdo_not_call_callbacks, andnextDispatched()serves both. The executor drains the queue after every poll, signaling each waiter with per-push announces suppressed, then makes one batched wake decision for the whole poll's worth of newly ready tasks: wake log2(ready) sleepers hinted at this executor (each steals half of what remains, so log2 covers the batch). Batches bypass the single-searcher token -- the token throttles speculative announces, and a counted batch is not speculation; Go draws the same line (wakepsingle-flights,injectgliststarts min(batch, idle) threads).Rationale: early per-completion wakes bought nothing locally -- a task woken mid-poll cannot run until the poll returns anyway, so immediate callbacks only enabled per-completion announce traffic and mid-poll steals, the churny kind. This also removes the last per-completion indirect call.
The subtle requirement (found via a hanging TCP handshake test): an operation that completes inline during
loop.add(a socket open) enters the dispatched queue outside any poll, on the very thread about to park.checkLocalWorktherefore drains the queue first, making pending wakes visible to every work check including the pre-park one.Alternatives probed and rejected
Benchmarks (interleaved, rotated order, isolated caches; dev box with +-5% noise -- please rerun on the Xeon box)
loop.add(socket open) lose the completed-inline fast path and pay one park/unpark round trip; where that class is most frequent (tcp many) the net is still +11%. Recovery exists if ever needed (self-drain afteradd).Testing
Native 601/601, epoll 601/601, poll suite, Windows/iocp under Wine 518/518, kqueue cross-compiles, Mutex churn stress clean, all under verbose per-test-timeout runs. Rebased on main (includes #632/#634/#635).