Skip to content

Add priority-aware scheduling to the MSBuild Coordinator - #14241

Closed
emaf wants to merge 7 commits into
dotnet:dev/dustinca/fix-issue-14170from
emaf:coordinator-priorities
Closed

emaf wants to merge 7 commits into
dotnet:dev/dustinca/fix-issue-14170from
emaf:coordinator-priorities

Conversation

@emaf

@emaf emaf commented Jul 1, 2026 •

Copy link
Copy Markdown
Contributor

Summary

The MSBuild Coordinator enforces a global node budget across concurrent builds, but the current allocator does not distinguish latency-sensitive work from regular or background work. An initial build can consume the full budget, leaving later work queued until capacity is released.

This change adds generalized Low, Normal, and High priority for root Coordinator requests. The Coordinator does not inspect DesignTimeBuild or any other project property: a client maps its own intent to a priority. For example, a UI-blocking design-time build can request High without adding design-time-build-specific behavior to the Coordinator.

This PR also adds computed allocation defaults that preserve capacity for High work while avoiding a permanent four-node limit when the Coordinator is otherwise idle.

Behavior

The resolved defaults depend on the total Coordinator node budget:

Total node budget Nodes reserved from Low/Normal for High Regular maximum per root build Maximum for the first eligible idle build
1-7 0 0 (uncapped) 0
8+ 4 4 8

The idle maximum applies only when no root grants are active and no requests are waiting:

  • The first Normal or High request may receive up to 8 nodes if it requests and can use 8.
  • Low requests always use the regular maximum.
  • Queued requests always use the regular capped or fair-share calculation, including when a queued request later becomes the only remaining build.
  • Existing grants are immutable. An 8-node grant is not reduced if contention arrives later.
  • Low and Normal cannot consume the four nodes reserved for High.
  • Within the same effective priority and capacity pool, requests remain FIFO.
  • A queued request moves up one effective priority level after every three higher-priority bypasses, preventing starvation.

On a 16-node budget, three full-budget Normal requests therefore produce 8, 4, queued; when the 8-node build releases, the queued request receives 4 rather than another idle 8-node grant. If a High request arrives while the initial 8-node Normal build is active, it can receive the four reserved nodes immediately.

Configuration semantics

  • Missing, empty, negative, or non-integer reservation/maximum values use the computed defaults above.
  • 0 disables that individual setting.
  • A positive MSBUILDCOORDINATORHIGHPRIORITYRESERVEDNODES value is an explicit reservation, clamped to leave at least one non-High node.
  • A positive MSBUILDCOORDINATORMAXNODESPERBUILD value is always a hard maximum, clamped to the total budget, and disables the idle 8-node exception.
  • Setting both values to 0 restores the current uncapped, no-reservation allocation behavior.

Clients select a request priority with MSBUILDCOORDINATORBUILDREQUESTPRIORITY=Low|Normal|High. The setting should be scoped to the build process whose request is being prioritized.

Protocol and compatibility

Priority is an optional extended field on the existing RequestNodesMessage:

  • Clients send it only when the server advertises the exact priority capability.
  • A missing field is Normal, including requests from older clients.
  • Clients do not send the field to older servers.
  • Unknown extended-field bits are rejected rather than silently misread.
  • Nested builds continue to join their root grant and do not make an independent prioritized root request.

There is no new public API in this change. The Coordinator remains opt-in through MSBUILDUSECOORDINATOR, and explicit 0/0 provides the previous allocator behavior, so this is not gated by a ChangeWave.

Why 4 reserved / 4 regular / 8 while idle?

The current Coordinator may grant all 16 nodes to the first build and queue everything that arrives afterward. Reserving four nodes lets a later High request start without preempting or resizing the first grant.

A permanent four-node maximum performed well under heavy contention, but it imposed a substantial isolated-build cost. Clean node-count calibration showed that four nodes took 34.4% longer than eight for Roslyn and 19.8% longer for Aspire. The idle 8-node maximum avoids imposing that permanent limit on a single build.

For large full-solution builds, eight rather than sixteen is a throughput/resource compromise. In the same calibration, eight nodes took 6.2% longer than sixteen for Roslyn and 15.2% longer for Aspire, while reducing measured process-tree memory:

Workload Eight-node wall time versus sixteen Committed memory Descendant working set Descendant private memory
Roslyn 6.2% longer 23.4% lower 30.1% lower 24.3% lower
Aspire 15.2% longer 23.7% lower 25.5% lower 18.6% lower

These are node-count calibration results without the Coordinator; they explain the selected grant sizes rather than claiming end-to-end Coordinator overhead. The direct isolated-project comparison below did not reproduce this full-solution timing cost.

An independent idle-grant setting is intentionally not added. A caller that specifies a positive per-build maximum gets that literal hard maximum, while callers using the computed four-node maximum get the documented idle exception.

Performance evidence

The portable reports, source/binary identities, exact scripts, raw summaries, launch records, and checksums are available in the PR #14241 benchmark evidence package. Each report identifies its exact baseline and candidate; the newest isolated and sustained campaigns directly compare the latest-main baseline used for this rebase with the final scheduling implementation.

Campaigns used pinned Roslyn and Aspire worktrees on a Windows 11 VM exposing 8 cores / 16 logical AMD EPYC 7763 processors, approximately 64 GiB RAM, and the High performance power plan. The earlier contention campaigns used Compilers.slnf and Aspire-Core.slnf; the direct isolated campaign used the representative projects named below. Conditions used balanced within-block ordering. Effects below are paired within-block log-ratio estimates rather than ratios of independent medians.

Isolated current-versus-final comparison

A direct matched comparison used current Coordinator commit ff5b281f0c and final scheduling commit 9aa319701c. Subsequent PR-head commits change tests, documentation, and diagnostic wording only; the measured allocator and protocol behavior is unchanged. One excluded warm-up and six measured paired blocks per repository used a complete Williams design with exact 0/0 position and carryover imbalance. Grant replay confirmed that the current Coordinator granted 16 nodes and the final computed defaults granted 8:

Representative project Current Coordinator Final defaults Difference Descriptive 95% interval
Roslyn C# compiler 90.236 s 90.224 s effectively equal 1.7% faster to 2.5% slower
Aspire.Hosting 36.257 s 36.687 s 1.2% slower 7.1% faster to 8.5% slower

The 8-node final defaults therefore had effectively the same duration as the current 16-node Coordinator for both representative isolated projects. Memory differences were small and inconsistent between repositories, and median descendant process counts were unchanged, so this campaign does not support a generalized memory benefit.

The same direct campaign exercised the final implementation in explicit 0/0 compatibility mode. It was 1.2% faster for Roslyn and 0.7% slower for Aspire than the current Coordinator; both descriptive intervals crossed zero. Full details are in the isolated validated report.

Concurrent compatibility control

An earlier propagated-solution campaign also compared the pre-priority Coordinator directly with the priority implementation configured as explicit 0/0. Ten paired measured blocks per repository found no meaningful implementation/protocol overhead:

Workload Delayed build Average Normal Total wall
Roslyn 2.9% sooner 0.1% later 0.1% later
Aspire 3.8% sooner 3.0% sooner 2.6% sooner

Every descriptive interval crossed zero.

Bounded contention and priority

The final-default behavior was measured with four initial Normal builds plus one build injected after 15 seconds. Comparing an injected High request with the otherwise-identical all-Normal condition:

Workload Injected High completion Average initial Normal completion Total wall
Roslyn 43.8% sooner 6.3% later 1.0% sooner
Aspire 23.8% sooner 6.8% later 4.5% sooner

This shows the intended transfer: the selected request completes materially sooner, while the initial Normal builds absorb a measurable cost.

The same campaign compared the computed idle-8 behavior with an explicit fixed 4/4 all-Normal condition:

Workload Total wall Average Normal completion Measured memory pressure
Roslyn 12.2% later 15.3% later 18-26% lower
Aspire 1.7% later 7.3% later 4-6% lower

The immutable first 8-node grant is therefore not free when several Normal builds arrive immediately afterward. This regression is the explicit tradeoff for avoiding a permanent four-node limit on isolated builds.

The idle/default matrix had four measured paired blocks per repository. Its results are descriptive and directional: with n=4, the minimum attainable two-sided exact sign-flip p-value is .125.

Sustained contention

A direct current-versus-final campaign used eight closed-loop Normal workers for a fixed eight-minute measured window, with an additional request injected after four minutes. The queue was nonempty for 94-95% of current-Coordinator samples and 100% of final-candidate samples. Three complete paired blocks per repository were accepted.

With all requests Normal, the final defaults kept approximately 12 of 16 nodes allocated, leaving the four-node High reservation unused. This reduced sustained Normal throughput while also reducing machine pressure:

Workload Normal throughput versus current Average system CPU Peak descendant working set Average allocated nodes
Roslyn 16.7% lower (1.75 → 1.46 builds/min) 30.8% lower 52.7% lower 12.0
Aspire 25.5% lower (5.08 → 3.79 builds/min) 29.4% lower 49.3% lower 12.0

Changing only the injected request from Normal to High made its reserved-capacity grant nearly immediate:

Workload Injected grant wait: Normal → High Injected completion Normal throughput versus final all-Normal Normal throughput versus current
Roslyn 223.7 s → 0.9 s 59.8% sooner 8.6% lower 23.9% lower
Aspire 81.8 s → 1.5 s 59.0% sooner 3.2% higher 23.1% lower

Compared directly with the current Coordinator, the final High request completed 60.3% sooner for Roslyn and 56.8% sooner for Aspire. The result demonstrates the intended tradeoff: reserving capacity substantially improves latency-sensitive work and lowers resource pressure, but reduces throughput when a continuously backlogged workload consists only of Normal requests.

These sustained estimates are directional (n=3; minimum attainable two-sided exact sign-flip p-value .25). One host-suspended partial attempt was excluded after telemetry gaps exceeded the predeclared limits; no partial scenario was reused. Full details are in the sustained contention report.

Grant validation

Across 200 successful measured binlogs and 72,231,961 replayed events:

  • Every computed-default scenario issued exactly one 8-node grant followed by four 4-node grants.
  • Explicit fixed-4 scenarios issued only 4-node grants.
  • No queued or queue-drained request received 8.
  • Every delayed High request received 4 while the initial 8-node Normal build was still active.

Validation

  • .\build.cmd -verbosity q
  • MSBuild.Coordinator.UnitTests on net11.0: 176 passed
  • BuildManagerPassesEnvironmentBuildRequestPriorityToCoordinator on net11.0: passed
  • Functional coverage includes immediate and queued grants, FIFO ordering, all three priorities, reservation boundaries, explicit caps, computed defaults, aging, immutable grants, idle eligibility, queue draining, legacy wire shapes, and capability negotiation.

Out of scope

  • No automatic design-time-build detection.
  • No public BuildParameters priority API.
  • No preemption, grant reduction, or runtime expansion.
  • No separate idle-maximum configuration variable.
  • No change to nested-grant budgeting.

emaf and others added 4 commits July 1, 2026 16:13
Add internal priority-aware coordinator requests, scheduling, and strict priority-cap settings without adding public BuildParameters API.

Co-authored-by: Copilot App <[email protected]>
Cover env-driven priority negotiation, priority-aware queueing, reservations, caps, and telemetry.

Co-authored-by: Copilot App <[email protected]>
Describe priority requests, reservation/cap behavior, and the environment-variable-based request path.

Co-authored-by: Copilot App <[email protected]>
Add repeatable scripts and instructions for CDK project-data and Roslyn mixed-workload coordinator benchmarking.

Co-authored-by: Copilot App <[email protected]>

@DustinCampbell DustinCampbell left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I spent some time trying to read through the changes in MSBuild-Coordinator.md and have provided some feedback. I'll take a look at the code later on, but I wanted to provide some general feedback that the documentation feels pretty laden with jargon and undefined concepts. To my eye, it's much more difficult to read and understand.

Comment thread documentation/MSBuild-Coordinator.md Resolved
Comment thread documentation/MSBuild-Coordinator.md Resolved
Comment thread documentation/MSBuild-Coordinator.md Outdated
5. **Auto-shutting down** after a timeout period
2. **Capping individual grants** so one build does not assume it owns the whole machine
3. **Prioritizing queued builds** when hosts identify latency-sensitive work
4. **Reserving high-priority capacity** so interactive builds can start predictably

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are "interactive builds"? That's a new concept and reads to me as jargon.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. I was using “interactive builds” as shorthand for builds that block a user-facing interaction, like IDE-requested design-time builds. But that introduces a new concept here and makes the priority behavior sound narrower than it is. I changed this to say high-priority builds instead.

Comment thread documentation/MSBuild-Coordinator.md Outdated
```

Wait-queue drain path (`DrainWaitQueue`):
`same_effective_priority_waiting_builds` includes the build currently being evaluated for a grant. Effective priority includes deterministic aging, so a lower-priority request can eventually participate in a higher-priority fair-share group after higher-priority work has bypassed it enough times. By default, a queued request ages upward by one effective priority level after 3 bypasses. Set `MSBUILDCOORDINATORPRIORITYAGINGTHRESHOLD` to a positive integer to tune that threshold.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we decide on terminology for the priority "groups"? I've seen "slices" used in this document as well. Are these different concepts? Or are they used as synonyms? Should they be defined somewhere above?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. These were not meant to be synonyms, but the wording made that unclear. I updated the docs to avoid “priority groups” and use “effective priority” for queue ordering. I also changed the “slice” wording to “per-build cap” / “grant” where possible, so “slice” doesn’t sound like a separate priority concept.

Comment thread documentation/MSBuild-Coordinator.md Outdated
New requests that arrive while same- or higher-priority builds are already queued are placed in the wait queue in both capped and uncapped modes.

Initial request path (`TryGrant`):
When `MSBUILDCOORDINATORMAXNODESPERBUILD` is `0`, there is no per-build cap. During wait-queue draining, this preserves the previous fair-share behavior:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't quite accurate. I believe this is also true if 'MSBUILDCOORDINATORMAXNODESPERBUILD' is not set at all, right?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question. I changed this to describe the resolved per-build cap instead of the raw env-var value. Setting MSBUILDCOORDINATORMAXNODESPERBUILD=0 always disables the per-build cap. Leaving it unset uses the computed default: uncapped for total node budgets below 8, but 4 for total node budgets 8 and above. I also added an earlier sentence summarizing those defaults before the fair-share/capped behavior is described.

Comment thread documentation/MSBuild-Coordinator.md Resolved
Comment thread documentation/MSBuild-Coordinator.md Resolved
Comment thread documentation/MSBuild-Coordinator.md Resolved
Comment thread documentation/MSBuild-Coordinator.md Outdated
Comment on lines +329 to +430
1. Client sends `ReleaseNodesMessage` with its grant ID
1. Client sends `ReleaseNodesMessage` for its connection

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How is the text improved by this change?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good callout. I looked at this again and ReleaseNodesMessage does not carry a grant ID; the server associates the release with the connection. I updated this to say the message releases the grant associated with the client connection.

Comment thread documentation/MSBuild-Coordinator.md Resolved
@DustinCampbell
DustinCampbell deleted the branch dotnet:dev/dustinca/fix-issue-14170 July 23, 2026 16:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants