Skip to content

[Fusion] Wake the plan executor without thread pool work item allocations - #10852

Merged
michaelstaib merged 4 commits into
mainfrom
perf/executor-wakeup
Nov 12, 2026
Merged

michaelstaib merged 4 commits into
mainfrom
perf/executor-wakeup

Conversation

@michaelstaib

Copy link
Copy Markdown
Member

Whenever a plan node finished, the executor was woken through a newly allocated thread pool work item, and it always yielded to the thread pool even when a node had already finished while it was busy. The wake-up signal now completes right away when it is already set, and it queues itself as a reusable work item instead of allocating one.

Metric Before Optimization After Optimization
Constant-latency throughput (AOT) 3,341 req/s 3,322 req/s (within noise)
Constant-latency latency p50 / p95 (AOT) 14.01 / 19.63 ms 14.05 / 19.85 ms
Constant-latency throughput (JIT) 3,419 req/s 3,402 req/s (within noise)
Constant-latency latency p50 / p95 (JIT) 13.63 / 19.36 ms 13.72 / 19.40 ms
Constant throughput (AOT) 4,805 req/s 4,833 req/s (+0.6%, within noise)
Constant throughput (JIT) 5,244 req/s 5,260 req/s (+0.3%, within noise)
Thread pool work items per request (JIT) 18.4 13.8 (-25% in every run)
Memory allocated per request (JIT) 26.4 KB 26.1 KB
In-process execution time (harness, AOT / JIT) baseline -12% / -12 to -14% (every pair significant)
In-process memory allocated per execution (harness) baseline -2.0 to -2.3 KB
AOT idle memory / startup to first response 51.5 MB / 57 ms 51.2 MB / 57 ms

Measured on the federation benchmark twin machine against upstream main 4adcdf2 (16.8.0-p.7) with alias batching and the deep-recursion query, 50 VUs, median of 3 interleaved 60 s rounds per mode (constant-latency adds a 4 ms subgraph delay); the harness runs the same query in process against canned subgraph responses. The k6 runs use default Kestrel and socket settings, not the inline settings the official benchmark now uses. Under 50-VU load the thread pool is busy, so the saved hop barely shows in k6, while the sequential harness shows it directly. Peak AOT memory in constant-latency was higher in 2 of 3 rounds (134 MB vs at most 114 MB) while average memory stayed the same; peak memory is noisy in this setup.

…ions

The executor's AsyncAutoResetEvent now lets an await complete synchronously
when a signal is already stored. IsCompleted consumes the stored signal under
the lock, so a node that completes while the executor is busy no longer forces
a suspension and a thread pool round trip. OnCompleted keeps its locked
re-check for a signal that arrives after IsCompleted.

The event also implements ICriticalNotifyCompletion and IThreadPoolWorkItem.
A wake-up queues the event itself with ThreadPool.UnsafeQueueUserWorkItem
instead of allocating a QueueUserWorkItemCallback per wake, and the awaiting
method restores its own ExecutionContext. OnCompleted still runs the
continuation in the context captured at registration.

OperationExecutionNode enqueues its merge without signaling, because the
completion it reports right afterwards wakes the executor for both.
A failed wait before the gate release left the node that ignores cancellation
blocked, so the fixture disposed its services while the request still held a
pooled context. Each iteration now cancels, releases the gate and waits a bounded
time for the request when it did not complete.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

@github-actions

github-actions Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Patch coverage

94.7% of changed lines covered (54/57)

File Covered Changed Patch %
…/Fusion/src/Fusion.Execution/Execution/AsyncAutoResetEvent.cs 51 54 94.4% 🟡
…/Fusion/src/Fusion.Execution/Execution/ExecutionState.cs 1 1 100.0% 🟢
…/Fusion.Execution/Execution/Nodes/OperationExecutionNode.cs 1 1 100.0% 🟢
…/src/Fusion.Execution/Execution/OperationPlanContext.cs 1 1 100.0% 🟢
Uncovered changed lines (JSON)
{
  "sha": "c13edb20a95a2d374c5a1789bed5a4cd5efaafa3",
  "files": [
    { "path": "src/HotChocolate/Fusion/src/Fusion.Execution/Execution/AsyncAutoResetEvent.cs", "ranges": [[48, 48], [118, 119]] }
  ]
}

Project coverage: 59.5% (322296/541522 lines)

@michaelstaib
michaelstaib merged commit 4316878 into main Nov 12, 2026
9 of 10 checks passed
@michaelstaib
michaelstaib deleted the perf/executor-wakeup branch November 12, 2026 20:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants