Repository navigation
Description
Description
After moving an OPC UA server and client (https://github.com/OPCFoundation/UA-.NETStandard) from .NET 10 to .NET 11, CPU time per request rose substantially, with identical allocations and an identical number of thread-pool work items per request. The extra time is entirely user-mode spinning in the thread pool's LowLevelLifoSemaphore.
Comparing System.Private.CoreLib 10.0.15 with 11.0.0:
UnfairSemaphoreSpinLimitchanged from 70 spin iterations to 1024 units ofBackoff.Exponential.- A worker that was woken but found no work (spurious dispatch) skips the spin only when more than
SpuriousDispatchNoSpinThreshold=ProcessorCount * 2 / 3workers are processing. In our workload, fewer workers than that are busy, so every spurious wake-up costs a full spin. - Spurious wake-ups are frequent in request/response code. A common source is
ThreadPool.UnsafeQueueUserWorkItem(..., preferLocal: true), or aManualResetValueTaskSourceCorewithRunContinuationsAsynchronously, issued by a thread that runs the item itself as soon as it returns to the pool. The enqueue still signals a worker, which then finds nothing.
Configuration
- .NET 11.0.0 vs .NET 10.0.15, Windows 11 x64.
- 24 logical processors (AMD hybrid: 8 + 16).
- Two processes on loopback TCP: a server, and a load client with 20 connections, each with one request in flight (closed loop).
- Workstation concurrent GC on both sides; otherwise default settings.
Data
Medians of 4 rotated rounds per configuration, discarding runs with other load on the machine. CPU is per request, measured in each process (Process.TotalProcessorTime / completed requests).
| Workload | Metric | .NET 10 | .NET 11 | .NET 11 + DOTNET_ThreadPool_SpuriousDispatchNoSpinThreshold=0 |
|---|---|---|---|---|
| Read 1 value | req/s | 214k | 184k (−14 %) | 222k (vs .NET 11: +9 %) |
| server µs/req | 45.1 | 52.2 | 44.7 | |
| client µs/req | 36.3 | 42.6 | 33.0 | |
| Write 100 values | server µs/req | 253 | 386 (+52 %) | 210 |
| client µs/req | 112 | 181 (+61 %) | 84 | |
| Browse | client µs/req | 84 | 120 (+43 %) | 66 |
Other observations:
DOTNET_ThreadPool_UnfairSemaphoreSpinLimit=46(hex, = 70) brings CPU back to the .NET 10 level as well, but without the throughput gain.DOTNET_ThreadPool_UnfairSemaphoreWakeCooldown=0has no measurable effect.- Thread-pool work items per request (
ThreadPool.CompletedWorkItemCount) are the same on both runtimes (client 3.0, server 2.1–4.0). Kernel CPU per request is unchanged; the whole increase is user mode. - Thread-time samples (EventPipe) on the .NET 11 client show
LowLevelLifoSemaphore.MaybeWakeWaiterSlowat 22 % of on-CPU samples (server 6 %). That is the CAS loop with exponential backoff on the signalling side, which runs inline on the thread that queues work. On .NET 10 the comparableReleaseCorewas about 10 %.
Regression?
Yes, compared with .NET 10.0.15 (CPU efficiency). Throughput at this load level ranges from −14 % (small requests) to +5–10 % (larger ones).
Analysis / suggestion
The ⅔-of-processors threshold seems too high for moderately loaded request/response servers: most wake-ups there are spurious, and each one spins the full 1024-unit budget. Setting the threshold to 0 both removes the extra CPU and improves throughput. Options:
- a lower default threshold;
- a spin budget that shrinks with the recent rate of spurious dispatches;
- not signalling a worker for a
preferLocalitem when the queuing thread is about to return to the dispatch loop.
The MaybeWakeWaiterSlow backoff on the signalling path is also worth a look, since it adds latency to the thread that produces the work.
Reproduction
- Build the load harness for both runtimes, as described in https://github.com/OPCFoundation/UA-.NETStandard/blob/master/perf/README.md:
CustomTestTarget=net10.0 dotnet build perf/ServerLoadHarness -c ReleaseCustomTestTarget=net11.0 dotnet build perf/ServerLoadHarness -c Release
- Run the same command with each build, alternating between the two:
ServerLoadHarness run --sessions 20 --duration 12 --warmup 6 --scenario write --nodes 100
- Compare the
per-op: cpuUs(server) andclient-per-op: cpuUslines. - To check the setting, set
DOTNET_ThreadPool_SpuriousDispatchNoSpinThreshold=0for the client andSERVER_DOTNET_ThreadPool_SpuriousDispatchNoSpinThreshold=0for the server child.
Workaround applied on our side: OPCFoundation/UA-.NETStandard#5078. It removes one preferLocal enqueue per client request, which recovers about a quarter to a third of the client regression.
Activity
dotnet-policy-service commentedon Nov 13, 2026
Tagging subscribers to this area: @JulieLeeMSFT, @VSadov
See info in area-owners.md if you want to be subscribed.
MihuBot commentedon Nov 13, 2026
I'm a bot. Here are possible related and/or duplicate issues (I may be wrong):
Client: run response continuations on the receive loop thread once it…
The benchmark README says where .NET 11's fire-path slowdown comes fr…
The benchmark README says where .NET 11's fire-path slowdown comes fr…
lahma commentedon Nov 18, 2026
Another workload with the same cause, in a single process with no sockets: Quartz.NET's job scheduler firing no-op jobs from its in-memory store. On .NET 11 it loses throughput as well as CPU.
SpuriousDispatchNoSpinThreshold=0removes the loss and leaves .NET 11 faster than .NET 10.Shape. One async loop takes a permit from a
SemaphoreSlim(10), then does about a microsecond of work under aSystem.Threading.Lock. It then callsTask.Factory.StartNew(..., TaskScheduler.Default). The work item takes the same lock briefly and releases the permit. Ten workers at most are processing, below the default threshold ofProcessorCount * 2 / 3= 21 on this machine. So every spurious wake-up spins the full budget.Machine. AMD Ryzen 9 5950X (16 cores, 32 logical), Windows 11 x64, workstation concurrent GC. The same
net10.0app runs on 10.0.15, and on 11.0.0 throughDOTNET_ROLL_FORWARD=LatestMajor. Each run is 25 s, with two rounds in rotated order, on an otherwise idle machine:DOTNET_ThreadPool_SpuriousDispatchNoSpinThreshold=0DOTNET_ThreadPool_UnfairSemaphoreSpinLimit=0DOTNET_ThreadPool_UnfairSemaphoreSpinLimit=0EventPipe sampled thread time (
Microsoft-DotNETCore-SampleProfiler, 1 ms), two captures per runtime. These are thread-ns per firing summed over all threads;[cpu]means the sample was in managed code,[native]that it was outside it.LowLevelLifoSemaphore.Wait[cpu]LowLevelLifoSemaphore.WaitForSignal[native] (parked)LowLevelLifoSemaphore.Block[cpu + native]WaitHandle.WaitForMultipleObjectsIgnoringSyncContextLock.TryEnterSlow[cpu]QueryPerformanceCounter+Environment.TickCount64[cpu]LowLevelLifoSemaphore.MaybeWakeWaiterSlow[cpu]On .NET 10, idle workers park. On .NET 11 they spin, and the spinners also contend for the application's
Lock. That lock is on the scheduler loop's critical path, so throughput drops too, not only CPU.A standalone repro (no Quartz) is the shape above in about 60 lines. Its loop and work items share a lock with about 1 µs of work in it. Over 3 s runs it gives 1,382-1,392 ns and 8.9-9.0 µs CPU per dispatch on .NET 10, and 1,532-1,551 ns and 16.0-16.2 µs on .NET 11. Without the shared lock, .NET 11 costs more CPU per dispatch but no throughput. With
SpuriousDispatchNoSpinThreshold=0, the CPU per dispatch falls to 4.9-5.6 µs.Program.cs
Run as
TpRepro 3 800(3 s, 800 iterations of locked work), on .NET 10 and then withDOTNET_ROLL_FORWARD=LatestMajorfor the samenet10.0build on .NET 11.Since the threshold scales with
ProcessorCount, a workload with a fixed degree of concurrency is the worst case on a large machine, which is common for schedulers and bounded worker pools.The full Quartz.NET measurement, with the four-leg tables and the profile breakdown, is in quartznet/quartznet#4214 (comment).