Repository navigation
Grow the logging queue instead of blocking producers when memory allows - #15281
Conversation
The logging service queue holds at most 200,000 events. When a slow logger such as the binary logger falls behind, the queue fills and every thread that logs blocks, which stalls ResolveAssemblyReference and other chatty tasks in -mt builds (#15224). On .NET, a producer that finds the queue full now doubles its capacity instead of blocking when GC.GetGCMemoryInfo reports enough headroom below the high memory load threshold for the added events, priced at an assumed 2 KB per event. Otherwise it waits as before and the memory is evaluated again after a second. Setting MSBUILDLOGGINGQUEUECAPACITY or disabling change wave 18.13 keeps the fixed capacity, and .NET Framework is unchanged. Co-authored-by: Copilot App <[email protected]>
Co-authored-by: Copilot App <[email protected]>
There was a problem hiding this comment.
🟡 Changes recommended
Timed re-evaluation, concurrent probing, and stale GC memory accounting leave correctness and memory-pressure risks.
2 open findings
What changed in this PR
Adds adaptive growth to the asynchronous logging queue to reduce producer contention while respecting memory pressure.
Changes:
- Doubles queue capacity when GC-reported headroom permits.
- Adds Change Wave and environment-variable opt-outs.
- Adds focused tests and documentation.
| File | Description |
|---|---|
LoggingService.cs |
Implements adaptive queue growth and memory checks. |
LoggingQueueCapacity_Tests.cs |
Tests growth, refusal, and opt-outs. |
Logging-Internals.md |
Documents adaptive capacity behavior. |
ChangeWaves.md |
Registers the 18.13 behavior change. |
🧠 Review effort: Balanced
There was a problem hiding this comment.
The adaptive-capacity path can strand producers that were already waiting on the dequeue signal; with a logger callback that depends on those logging calls, this forms a deadlock. The retry coordination also permits a concurrent GC-memory-query herd, and the new tests/docs do not currently prove or describe the actual retry behavior deterministically.
| # | Dimension | Verdict |
|---|---|---|
| 3 | Performance & Allocation Awareness | 🟡 1 MAJOR |
| 4 | Test Coverage & Completeness | 🟡 1 MAJOR |
| 13 | Concurrency & Thread Safety | 🔴 1 BLOCKING |
| 18 | Documentation Accuracy | 🟡 1 MODERATE |
✅ 20/24 dimensions clean.
- Concurrency — wake producers when capacity growth creates queue space
- Performance — serialize the once-per-second memory evaluation
- Tests — prove the producer reached the no-headroom path
- Documentation — align retry wording with implemented wake/retry semantics
Warning
Firewall blocked 3 domains
The following domains were blocked by the firewall during workflow execution:
api.github.comgithub.comraw.githubusercontent.com
[!TIP]
api.github.com is blocked because GitHub API access uses the built-in GitHub tools by default. Instead of adding api.github.com to network.allowed, use tools.github.mode: gh-proxy for direct pre-authenticated GitHub CLI access without requiring network access to api.github.com:
tools:
github:
mode: gh-proxySee GitHub Tools for more information on gh-proxy mode.
To allow these domains, add them to the network.allowed list in your workflow frontmatter:
network:
allowed:
- defaults
- "api.github.com"
- "github.com"
- "raw.githubusercontent.com"See Network Configuration for more information.
Generated by Expert Code Review (on open) for #15281 · copilot · gpt56 · 907 AIC · ⌖ 0.527 AIC · ⊞ 24.9K
A producer that found the queue full and could not grow it waited for a dequeue without a time limit. While the logger is stuck, nothing is dequeued, so memory that became available again or growth done by another producer went unnoticed. With a growing queue, producers now wake up after the retry interval of one second and look at the capacity and the memory again. A queue with a fixed capacity still waits without a limit, and so does .NET Framework, where the memory cannot be measured and the behavior stays as it was. Producers that find the queue full together now share one memory evaluation: the decision is taken under a lock, and the producers that waited for it see the result instead of querying the GC again. The test of the refusal path now waits until the producer has reached the full queue. New tests cover the retry while nothing is dequeued, the shared evaluation and the missing memory provider. Co-authored-by: Copilot App <[email protected]>
The memory load and the high-memory-load threshold that the GC reports are computed from the physical memory of the machine and ignore a GC heap hard limit (DOTNET_GCHeapHardLimit, or the default limit of a container), so with a low limit on a large machine the queue could be approved to grow far beyond what the heap can hold. Take the room left below the hard limit (TotalAvailableMemoryBytes - TotalCommittedBytes) into account as well. The GC reports all of these values as of its last collection, so correct the documentation: growth that was refused is allowed again once a GC has measured that memory is available, not as soon as it becomes available. Co-authored-by: Copilot App <[email protected]>


Related issue(s): #15224
Context
In short: when the logging queue is full, it now grows if the machine has the memory, instead of blocking every thread that logs.
All threads of a build log into one
LoggingService. Events wait in a queue of at most 200,000 entries until a single thread has handed them to the loggers. When a logger is slow, typically the binary logger on a large solution, the queue fills up and every thread that logs blocks until the consumer catches up.ResolveAssemblyReferencelogs a lot of messages, so with-mtand a binlog it spends much of its time waiting for queue space: in an incremental OrchardCore build its summed task time is about 75 s instead of about 20 s (#15224).Changes Made
When a producer finds the queue full, it doubles the capacity (200K → 400K → 800K …) instead of waiting, as long as the process has the memory for the added events. If it does not, the producer waits for the logger as before, but wakes up every second to look at the capacity and the memory again, so the queue grows once the GC reports that the memory is available.
GC.GetGCMemoryInfo()reportsHighMemoryLoadThresholdBytes - MemoryLoadBytes, the memory the process can still use before the GC considers the machine to be under high memory load, andTotalAvailableMemoryBytes - TotalCommittedBytes, the room left below the GC heap hard limit (DOTNET_GCHeapHardLimit, which containers get by default). The smaller of the two is used. The GC measures them when it last ran, so a change shows after the next GC. Events that were already queued then are part of what it measured, so only the added capacity is priced against it.The decision is made in
TryGrowQueueCapacity, called from the producer loop ofLoggingService.ProcessLoggingEvent. Producers that find the queue full together take it one at a time (under a lock), so only one of them looks at the memory and the others see its result.Compatibility
msbuild.exe) keeps the fixed capacity, because it has no API for the memory load, and its producers keep waiting without a time limit, exactly as before.MSBUILDLOGGINGQUEUECAPACITYkeeps the capacity fixed at that value, as today, andMSBUILDDISABLEFEATURESFROMVERSION=18.13turns the feature off (change wave 18.13, listed inChangeWaves.md).MSBUILDDEBUGCOMM=1the communication trace showsThe logging queue grew from 200000 to 400000 events.Testing
Unit tests. 19 test cases in
LoggingQueueCapacity_Testscover growth when the headroom allows it, the exact headroom boundary, refusal, waiting producers noticing that memory recovered while nothing is dequeued, producers that find the queue full together sharing one memory evaluation, a second producer adopting the growth of the first, the headroom being capped by the GC heap hard limit, and the opt-outs. They pass on net11.0 and net472, as does the wholeMicrosoft.Build.UnitTests.Loggingnamespace (185 tests; one skip on net11.0 that was there before). WithDOTNET_GCHeapHardLimit=0x40000000on a machine with 64 GiB the real provider reports 0.96 GiB of headroom instead of 28 GiB (checked once with a scratch test that is not part of the PR).PerfStar (binlog runs, Orchard Core incremental build with
-mt; main is the median of the last six scheduled main builds, this PR is one run of this branch):The binlog overhead (the build with a binlog compared with the same build without one) drops from 64.5% to 27.5% on Linux and from 57.8% to 22.3% on Windows. The other scenarios of the run (Orchard Core rebuild with
-mt, the non-MT incremental build on Linux, net8 console) change by 3% or less, and builds without a binlog are flat. An earlier experiment with a fixed 2,000,000 events (perf/janpro/binlog-queue-attermpt2) gave the same speedup (Linux 39.4 → 30.3 s, Windows 30.6 → 26.9 s).The comparison on the dashboard (Binlog overhead → Comparison; candidate: this branch's run
20261014.12.s, reference: the scheduled main run20261010.2.s, which is close to the median of the six):The dashboard's default reference is the mean of 30 days of main, which is noisy, so the links pin one main run.
Local OrchardCore (
ea88aa0e,-mtwith a binlog, warm incremental build, one Windows machine, 5 runs per column, 4 with the GC limit; same binary, onlyMSBUILDLOGGINGQUEUECAPACITYdiffers):ResolveAssemblyReferencetimeThe PerfStar and local numbers were measured before the review fixes, which only change what happens when the queue is full and how the headroom is computed (at most once a second); the lines that run for every event are unchanged. A micro-benchmark of the producer path (16 producers, Debug build) before and after the fixes shows no measurable difference: +1% when the queue never fills (noise), −2% to 0% while it grows under contention, +0.3% to +0.7% in the memory-refusal state.