Skip to content

[Fusion] Reuse the timeout CTS and complete cache hits synchronously in the request pipeline - #10713

Merged
michaelstaib merged 3 commits into
mainfrom
perf/pipeline-timeout-cache
Oct 27, 2026
Merged

michaelstaib merged 3 commits into
mainfrom
perf/pipeline-timeout-cache

Conversation

@michaelstaib

Copy link
Copy Markdown
Member

Each request created a timer-backed cancellation token source plus a linked token source to enforce the execution timeout, and the document cache and plan cache middlewares added an async step even when the cache already had the entry. The timeout middleware now reuses pooled cancellation token sources, and both cache middlewares hand a cache hit straight to the next middleware. Timeout errors, request cancellation and deferred streams behave as before.

Metric Before Optimization After Optimization
Throughput 4,453 req/s 4,487 req/s (within noise)
Latency p50 10.04 ms 9.90 ms
CPU per request 0.817 ms 0.806 ms
Memory allocated per request 32.5 KB 31.4 KB (-3.4%)
GC collections per second 12.5 13.2
Memory usage (avg working set) 162.9 MB 163.6 MB

Measured on the federation benchmark twin machine with the benchmark's deep-recursion query (constant 50 VUs, gateway pinned to 4 logical cores), median of 4 interleaved 60 s runs against main. Throughput differences below about 2% are within run-to-run noise.

@github-actions

github-actions Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Patch coverage

100.0% of changed lines covered (63/63)

File Covered Changed Patch %
…/Core/src/Execution.Pipeline/DocumentCacheMiddleware.cs 7 7 100.0% 🟢
…/Execution/Pipeline/OperationPlanCacheMiddleware.cs 11 11 100.0% 🟢
…/src/Fusion.Execution/Execution/Pipeline/TimeoutMiddleware.cs 45 45 100.0% 🟢

Project coverage: 59.2% (318145/537321 lines)

@michaelstaib
michaelstaib added this pull request to stack #10724 October 27, 2026 19:19
@michaelstaib
michaelstaib force-pushed the perf/pipeline-timeout-cache branch from c87443e to 792c24d Compare October 27, 2026 19:22
…in the request pipeline

The Fusion TimeoutMiddleware allocated a timer CancellationTokenSource and a
three-way linked source for every request. It now rents one pooled source per
request, arms it with CancelAfter and links the request-aborted and schema
shutdown tokens through UnsafeRegister. After a non-stream result it restores
the original RequestAborted token, disposes the registrations and returns the
source only when TryReset succeeds. A stream result keeps the source (timer
stopped) until the stream is disposed, as before. A timeout is reported when
the source is canceled while neither parent token is.

DocumentCacheMiddleware and OperationPlanCacheMiddleware return the next
delegate's task directly on a cache hit; misses, cache adds and plan
coalescing keep their async path, and the plan cache is still looked up once
per attempt.
The test gave every request a 100 ms execution timeout, so a fast request that
was scheduled late under full test-suite load timed out as well. It now uses a
1 second timeout, which only the request that waits forever reaches.
@michaelstaib
michaelstaib force-pushed the perf/pipeline-timeout-cache branch from 792c24d to cd38823 Compare October 27, 2026 19:25
@michaelstaib
michaelstaib merged commit 0e578de into main Oct 27, 2026
9 checks passed
@michaelstaib
michaelstaib deleted the perf/pipeline-timeout-cache branch October 27, 2026 19:27
This was referenced Oct 28, 2026
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