-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Detect and correct worker node over-provisioning #13220
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Copilot
wants to merge
5
commits into
main
Choose a base branch
from
copilot/detect-correct-over-provisioning
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+371
−7
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
dda7440
Reap nodes of the same type when overprovisioned
Copilot 1fc9844
Light up server node reaping as well.
baronfel 7a70db1
use existent changewave
baronfel c3038be
Update src/Shared/ProcessExtensions.cs
baronfel 1ba80f4
Update src/Utilities.UnitTests/ProcessExtensions_Tests.cs
baronfel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
169 changes: 169 additions & 0 deletions
169
src/Build.UnitTests/BackEnd/NodeProviderOutOfProc_Tests.cs
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,169 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using System; | ||
| using Microsoft.Build.BackEnd; | ||
| using Microsoft.Build.Shared; | ||
| using Shouldly; | ||
| using Xunit; | ||
|
|
||
| #nullable disable | ||
|
|
||
| namespace Microsoft.Build.UnitTests.BackEnd | ||
| { | ||
| /// <summary> | ||
| /// Tests for NodeProviderOutOfProc, specifically the node over-provisioning detection feature. | ||
| /// </summary> | ||
| public class NodeProviderOutOfProc_Tests | ||
| { | ||
| /// <summary> | ||
| /// Test helper class to expose protected methods for testing. | ||
| /// Uses configurable overrides for testing. | ||
| /// </summary> | ||
| private sealed class TestableNodeProviderOutOfProcBase : NodeProviderOutOfProcBase | ||
| { | ||
| private readonly int _systemWideNodeCount; | ||
| private readonly int? _thresholdOverride; | ||
|
|
||
| public TestableNodeProviderOutOfProcBase(int systemWideNodeCount, int? thresholdOverride = null) | ||
| { | ||
| _systemWideNodeCount = systemWideNodeCount; | ||
| _thresholdOverride = thresholdOverride; | ||
| } | ||
|
|
||
| protected override int GetNodeReuseThreshold() | ||
| { | ||
| // If threshold is overridden, use it; otherwise use base implementation | ||
| return _thresholdOverride ?? base.GetNodeReuseThreshold(); | ||
| } | ||
|
|
||
| protected override int CountSystemWideActiveNodes() | ||
| { | ||
| return _systemWideNodeCount; | ||
| } | ||
|
|
||
| public bool[] TestDetermineNodesForReuse(int nodeCount, bool enableReuse) | ||
| { | ||
| return DetermineNodesForReuse(nodeCount, enableReuse); | ||
| } | ||
|
|
||
| public int TestGetNodeReuseThreshold() | ||
| { | ||
| return GetNodeReuseThreshold(); | ||
| } | ||
| } | ||
|
|
||
| [Fact] | ||
| public void DetermineNodesForReuse_WhenReuseDisabled_AllNodesShouldTerminate() | ||
| { | ||
| var provider = new TestableNodeProviderOutOfProcBase(systemWideNodeCount: 10, thresholdOverride: 4); | ||
|
|
||
| bool[] result = provider.TestDetermineNodesForReuse(nodeCount: 3, enableReuse: false); | ||
|
|
||
| result.Length.ShouldBe(3); | ||
| result.ShouldAllBe(shouldReuse => shouldReuse == false); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void DetermineNodesForReuse_WhenThresholdIsZero_AllNodesShouldTerminate() | ||
| { | ||
| var provider = new TestableNodeProviderOutOfProcBase(systemWideNodeCount: 10, thresholdOverride: 0); | ||
|
|
||
| bool[] result = provider.TestDetermineNodesForReuse(nodeCount: 3, enableReuse: true); | ||
|
|
||
| result.Length.ShouldBe(3); | ||
| result.ShouldAllBe(shouldReuse => shouldReuse == false); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void DetermineNodesForReuse_WhenUnderThreshold_AllNodesShouldBeReused() | ||
| { | ||
| // System has 3 nodes total, threshold is 4, so we're under the limit | ||
| var provider = new TestableNodeProviderOutOfProcBase(systemWideNodeCount: 3, thresholdOverride: 4); | ||
|
|
||
| bool[] result = provider.TestDetermineNodesForReuse(nodeCount: 3, enableReuse: true); | ||
|
|
||
| result.Length.ShouldBe(3); | ||
| result.ShouldAllBe(shouldReuse => shouldReuse == true); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void DetermineNodesForReuse_WhenAtThreshold_AllNodesShouldBeReused() | ||
| { | ||
| // System has 4 nodes total, threshold is 4, so we're at the limit | ||
| var provider = new TestableNodeProviderOutOfProcBase(systemWideNodeCount: 4, thresholdOverride: 4); | ||
|
|
||
| bool[] result = provider.TestDetermineNodesForReuse(nodeCount: 4, enableReuse: true); | ||
|
|
||
| result.Length.ShouldBe(4); | ||
| result.ShouldAllBe(shouldReuse => shouldReuse == true); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void DetermineNodesForReuse_WhenOverThreshold_ExcessNodesShouldTerminate() | ||
| { | ||
| // System has 10 nodes total, threshold is 4 | ||
| // This instance has 3 nodes | ||
| // We should keep 0 nodes from this instance (since 10 - 3 = 7, which is already > threshold) | ||
| var provider = new TestableNodeProviderOutOfProcBase(systemWideNodeCount: 10, thresholdOverride: 4); | ||
|
|
||
| bool[] result = provider.TestDetermineNodesForReuse(nodeCount: 3, enableReuse: true); | ||
|
|
||
| result.Length.ShouldBe(3); | ||
| result.ShouldAllBe(shouldReuse => shouldReuse == false); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void DetermineNodesForReuse_WhenSlightlyOverThreshold_SomeNodesShouldBeReused() | ||
| { | ||
| // System has 6 nodes total, threshold is 4 | ||
| // This instance has 3 nodes | ||
| // Other instances have 6 - 3 = 3 nodes | ||
| // We need to reduce by 2 nodes to reach threshold | ||
| // So we should keep 1 node from this instance | ||
| var provider = new TestableNodeProviderOutOfProcBase(systemWideNodeCount: 6, thresholdOverride: 4); | ||
|
|
||
| bool[] result = provider.TestDetermineNodesForReuse(nodeCount: 3, enableReuse: true); | ||
|
|
||
| result.Length.ShouldBe(3); | ||
| // First node should be reused, others should terminate | ||
| result[0].ShouldBeTrue(); | ||
| result[1].ShouldBeFalse(); | ||
| result[2].ShouldBeFalse(); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void DetermineNodesForReuse_WithSingleNode_BehavesCorrectly() | ||
| { | ||
| // System has 5 nodes total, threshold is 4 | ||
| // This instance has 1 node | ||
| // We're over threshold, but only by 1 | ||
| // We should terminate this node since others already meet threshold | ||
| var provider = new TestableNodeProviderOutOfProcBase(systemWideNodeCount: 5, thresholdOverride: 4); | ||
|
|
||
| bool[] result = provider.TestDetermineNodesForReuse(nodeCount: 1, enableReuse: true); | ||
|
|
||
| result.Length.ShouldBe(1); | ||
| result[0].ShouldBeFalse(); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void GetNodeReuseThreshold_DefaultImplementation_ReturnsHalfOfCoreCount() | ||
| { | ||
| // Test the default implementation by not providing a threshold override | ||
| // Note: This test uses the actual system core count, so results vary by machine, | ||
| // but the mathematical relationship (threshold = max(1, cores/2)) should hold on all systems | ||
| int coreCount = NativeMethodsShared.GetLogicalCoreCount(); | ||
| int expectedThreshold = Math.Max(1, coreCount / 2); | ||
|
|
||
| // Create a provider WITHOUT threshold override to test the base class implementation | ||
| var provider = new TestableNodeProviderOutOfProcBase(systemWideNodeCount: 0, thresholdOverride: null); | ||
|
|
||
| // The threshold from the provider should match our expected calculation | ||
| int actualThreshold = provider.TestGetNodeReuseThreshold(); | ||
| actualThreshold.ShouldBe(expectedThreshold); | ||
| actualThreshold.ShouldBeGreaterThanOrEqualTo(1); | ||
| actualThreshold.ShouldBeLessThanOrEqualTo(coreCount); | ||
| } | ||
| } | ||
| } |
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.