Repository navigation
Conversation
Allow a runnable producer to post a signal while a worker is waiting for new work. Yield on alternating capped backoffs after an unsuccessful acquire, while there is still spin budget left.
|
Azure Pipelines: Successfully started running 3 pipeline(s). 12 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
Contributor
|
Tagging subscribers to this area: @JulieLeeMSFT, @VSadov |
Author
|
@dotnet-policy-service agree company="Furth Fortune" |
This was referenced Nov 24, 2026
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
On a Linux x64 server handling 32 outstanding requests, an idle portable thread-pool worker can spend the entire semaphore spin budget polling before it parks. This patch gives other runnable threads a scheduling opportunity between alternating capped spins. It checks for a signal before yielding and only yields while there is budget left. The one-shot acquire, initial short backoffs, waiter registration and wake accounting keep their existing behavior. The single-processor path skips the spin loop.
Where the regression appeared
With the same application, Kestrel binaries and load process, #122726 took WebSocket throughput from 79,919 to 58,636 requests/s and HTTP from 103,495 to 79,238. These are comparisons between the commit and its immediate parent. Restoring only the parent's wait loop and iteration count on top of that commit recovered WebSocket throughput from 53,580 to 83,978 requests/s in a separate paired run. An earlier, smaller WebSocket drop was also reproducible at #117788. The report describes the component builds and their limitations. Historical source comparisons
Proposed patch on matched source builds
Each comparison used two independently restarted service processes per arm in A/B/B/A order. The 11.0.0 table uses four timed observations per arm per transport. The 12 alpha table uses two. Across these 24 timed observations, the driver completed 19,451,391 requests with zero errors, timeouts, reconnects or sampled reply-validation failures. The tested nightly was
12.0.0-alpha.1.26573.102, runtime source4ab5617c35e2. The patch was compiled on upstream main as well.The host was Docker Desktop on WSL2. The service used four guest logical CPUs and the client used two, with one request outstanding per connection. The application runs used a minimum of 256 workers and disabled dynamic GC adaptation. The standalone Kestrel echo app also reproduces the stock release difference using framework defaults, from 180,603 WebSocket round trips/s on 10.0.12 to 123,441 on 11.0.0. Client CPU placement affects the magnitude.
In separate 11.0.0 traces, the mean from epoll readiness to entering the successful receive fell from 35.2 to 24.0 µs on WebSocket and from 84.5 to 71.3 µs on HTTP. The WebSocket median rose from 4.7 to 7.5 µs while its p99 fell from 224 to 186 µs. The syscall itself averaged roughly 1 µs. Each trace covers all 32 connections and at least 126,000 matched cycles.
On the upstream nightly using framework-default thread-pool and GC settings, the public Minimal API JSON benchmark gained 43.4% at 32 clients and 35.1% at 256. Raw Kestrel JSON gained 45.8% and 36.2%, respectively. Client p99 decreased in all four comparisons. These are local
aspnet/Benchmarksapplication runs using the fixed client, on the same WSL2 machine.A separate, non-socket producer-to-worker control reduced single-item queue-to-start p99 from 23.47 to 7.14 µs. With two additional CPU-bound competitors, it fell from 24.30 to 4.61 µs. Batches of 32 increased from 1.84 to 2.97 million items/s. The report includes the control, CPU time and individual observations. Full benchmark results
The standalone WebSocket echo also improved with the proposed patch on .NET 11.0.0, from 101,209 to 143,317 round trips/s (+41.6%) with the application's worker and GC settings. The upstream
System.Threading.ThreadPool.Testssuite ran on the patched Linux x64 nightly using the repository's test selection. It passed 68 tests and skipped two.Extract the evidence ZIP and run
cd repro && bash run.shfor stock releases. Usebash build-edge.sh release-fix "$HOME/socket-runtime-fix", then the emitted A/B command for the patch. The same script can rebuild the January parent/child comparison and the wait-loop reversal. I would appreciate a cross-check on native Linux with a separate load host.Download the reproducer and measurements · Reproducer instructions
Prepared with assistance from OpenAI Codex.