Skip to content
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

Introduce cross-process resource management for tasks #5859

Merged
merged 118 commits into from
Mar 30, 2021

Conversation

rainersigwald
Copy link
Member

@rainersigwald rainersigwald commented Nov 5, 2020

Add RequestCores and ReleaseCores APIs to IBuildEngine8.

These APIs can advise a task that wishes to do work with its own internal parallelism. The task can request as many (abstracted) CPU cores as it desires, and the MSBuild engine will keep track of how many have been requested and prevent the machine from being completely overloaded.

Since this is advisory only, existing tasks will be unaffected. The Visual C++ tasks plan to opt into this.

See resource-management.md for more design and implementation details.

Fixes #74

benvillalobos and others added 30 commits February 25, 2020 12:54
Got straightforward unit tests working.
Added null check and cached the Semaphore.
This reverts commit f60c66a.
This should alleviate hangs that were happening as a result of leaks
that happened when MSBuild/CallTarget got a resource, then
we started building other projects.
Otherwise, we can deadlock: outer task gets a resource, (logically) yields to build other projects; they block on getting a resource.
@ladipro ladipro marked this pull request as ready for review March 26, 2021 21:30
Copy link
Member

@Forgind Forgind left a comment

Choose a reason for hiding this comment

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

Partial review

}
else
{
// Resource release is a one-way call, no response is expected. We release the cores as instructed
Copy link
Member

Choose a reason for hiding this comment

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

There could be an issue if the ReleaseCores call for a process that uses a lot of cores gets lost somehow. I'm wondering if, in addition to being able to release cores, there should be an auto-release after a certain amount of time. Perhaps the scheduler pings the task, and if it responds that it still needs cores, it resets it; otherwise, it reclaims them?

Copy link
Member

Choose a reason for hiding this comment

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

There are countless ways a task can hang the build. Yes, the new API needs to be used carefully. With great power comes great responsibility, as they say. What you are suggesting sounds too complicated and it would not prevent all hangs. I can imagine tasks would use a hard-coded "yes" when asked if they still need cores and pass int.MaxValue for timeout.

src/Build/BackEnd/Components/RequestBuilder/TaskHost.cs Outdated Show resolved Hide resolved
Copy link
Member

@Forgind Forgind left a comment

Choose a reason for hiding this comment

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

My only reservation is that there aren't a lot of features to prevent users from shooting themselves in the foot, especially in unusual circumstances with highly oversubscribed machines and/or low-priority builds, but I don't think that should hold you back. Thanks for picking this up and driving it through!

src/Build/BackEnd/Components/Scheduler/Scheduler.cs Outdated Show resolved Hide resolved
/// <summary>
/// Retrieves the <see cref="IBuildEngine9" /> version of the build engine interface provided by the host.
/// </summary>
public IBuildEngine9 BuildEngine9 => (IBuildEngine9)BuildEngine;
Copy link
Member

Choose a reason for hiding this comment

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

As I mentioned in the meeting, I slightly prefer reusing IBuildEngine8, but this is fine.

@Forgind Forgind added the merge-when-branch-open PRs that are approved, except that there is a problem that means we are not merging stuff right now. label Mar 29, 2021
@Forgind Forgind merged commit 1629921 into main Mar 30, 2021
@ladipro ladipro deleted the exp/resource-management branch October 25, 2021 11:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merge-when-branch-open PRs that are approved, except that there is a problem that means we are not merging stuff right now.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

use a global scheduler for parallel compilation
6 participants