Skip to content

[Fusion] Reuse request timeout sources in the timeout middleware - #10622

Closed
tobias-tengler wants to merge 1 commit into
mainfrom
tte/fusion-pooled-request-timeout-source
Closed

tobias-tengler wants to merge 1 commit into
mainfrom
tte/fusion-pooled-request-timeout-source

Conversation

@tobias-tengler

@tobias-tengler tobias-tengler commented Oct 19, 2026 •

Copy link
Copy Markdown
Member

For every request, the Fusion timeout middleware creates a timeout CancellationTokenSource with its own timer, a linked source over request abort, timeout and schema shutdown, and a registration on the schema shutdown token, which all requests share.

This PR rents a pooled RequestTimeoutSource that keeps one token source and one timer and registers on the schema shutdown token once, so a request only registers on its abort token and arms and disarms the timer. The timeout keeps its own flag, so a request abort or schema shutdown is still not reported as a timeout, and a timer callback dispatched for an earlier request cannot cancel a later one. Streams keep the source until their cleanup as before.

Method Version Allocated (round 1) Allocated (round 2) Mean Delta
POST through the gateway before 22,348 B 22,344 B 22,346 B
POST through the gateway PR 21,781 B 21,798 B 21,790 B −556 B

Allocations per request from an allocation probe: a TestServer gateway answers a { value } POST through an in-process source schema handler that yields once, 20,000 sequential requests after 5,000 warmup requests, GC.GetTotalAllocatedBytes(precise: true) across all threads (client, server, gateway and source handler), two rounds. The probe ran with the series applied cumulatively on main, so the before row is main with #10618, #10619, #10620 and #10621.

For context, the k6 constant screen of this change together with the other request pipeline changes (#10618, #10619, #10620, #10621 and #10623) and one further change that is not proposed, A B B A per gateway (3 × 30 s runs per invocation). RPS is the median of the six runs, CPU per request the mean of the six runs, p95 and p99 are per invocation.

Gateway Version RPS CPU per request p95 p99
Composite schema (net10.0) main 4,461 590.6 μs 19.47 / 19.36 ms 24.87 / 25.15 ms
Composite schema (net10.0) Bundle 4,434 586.1 μs 19.21 / 19.45 ms 24.96 / 24.98 ms
Apollo Federation (net11.0) main 4,109 566.6 μs 19.96 / 19.96 ms 25.50 / 25.48 ms
Apollo Federation (net11.0) Bundle 4,104 563.3 μs 19.84 / 19.91 ms 25.59 / 25.05 ms

The change saves about 556 B per request, far beyond the probe's run-to-run noise of about ±50 B, and requests no longer register on the shared schema shutdown token. The bundle shows no regression: RPS (−27 and −5), CPU per request (−0.76% and −0.58%) and latency all stay within the A/A noise measured on main (σ about 65 RPS for the composite schema gateway and 40 RPS for the Apollo Federation gateway, CPU per request CV 0.5 to 0.8%), so the end-to-end gain is not measurable on its own.

The timeout middleware created a timeout CancellationTokenSource with its own timer and a
linked source over request abort, timeout and schema shutdown for every request. It now
rents a pooled RequestTimeoutSource that keeps one timer and registers the schema shutdown
token once, so a request only registers on its abort token. The timeout keeps its own
flag, so a request abort or schema shutdown is still not reported as a timeout.
@github-actions

Copy link
Copy Markdown
Contributor

Patch coverage

97.3% of changed lines covered (71/73)

File Covered Changed Patch %
…/Fusion.Execution/Execution/Pipeline/RequestTimeoutSource.cs 59 61 96.7% 🟡
…/src/Fusion.Execution/Execution/Pipeline/TimeoutMiddleware.cs 12 12 100.0% 🟢
Uncovered changed lines (JSON)
{
  "sha": "933d7ef799b4693f2adec4025a8700c0498f48a1",
  "files": [
    { "path": "src/HotChocolate/Fusion/src/Fusion.Execution/Execution/Pipeline/RequestTimeoutSource.cs", "ranges": [[121, 122]] }
  ]
}

Project coverage: 59.0% (311605/527913 lines)

@tobias-tengler
tobias-tengler deleted the tte/fusion-pooled-request-timeout-source branch October 21, 2026 15:52
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.

1 participant