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

Update copy logic to use dedicated threads. #11272

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Erarndt
Copy link

@Erarndt Erarndt commented Jan 13, 2025

Also updated some checks to help avoid hitting the file system if possible.

Fixes #

Context

The existing implementation does synchronous file copying on threadpool threads which can lead to starvation. Switching to dedicated threads to do synchronous copying helps keep the threadpool threads available for other tasks.

Changes Made

Testing

Notes

@rainersigwald
Copy link
Member

Just kinda generally, I'm surprised to hear about threadpool starvation in our worker nodes which aren't threadpool heavy. Have you observed this in practice?

@Erarndt
Copy link
Author

Erarndt commented Jan 13, 2025

Just kinda generally, I'm surprised to hear about threadpool starvation in our worker nodes which aren't threadpool heavy. Have you observed this in practice?

There is some sneaky utilization of the threadpool that ends up blocking enough to see the "hill climbing" algorithm start spinning up new threads. I've seen between 40 and 50 threadpool threads per MSBuild processes which is over 3x what I would expect. This change (#11275) has a larger impact than the copy code, but this contributes as well. There's also additional benefit to reducing the mix of I/O bound work and CPU bound work on the threadpool.

@JanKrivanek
Copy link
Member

Related to #11160

@Erarndt Erarndt marked this pull request as ready for review January 15, 2025 16:41
@JanProvaznik JanProvaznik self-requested a review January 16, 2025 10:28
Also updated some checks to help avoid hitting the file system if possible.
@JanProvaznik JanProvaznik force-pushed the dev/erarndt/updateCopyParallelism branch from d0500f7 to 868969a Compare January 16, 2025 10:29
Copy link
Member

@JanProvaznik JanProvaznik left a comment

Choose a reason for hiding this comment

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

Looks reasonable, please

  1. fix the test
  2. cleanup parallelism parameter
  3. if possible share some evidence of perf impact, I could not see it from looking at some local OrchardCore builds (albeit I did not achieve statistical significance)

@@ -288,6 +319,7 @@ private void LogAlwaysRetryDiagnosticFromResources(string messageResourceName, p
}

if (!Traits.Instance.EscapeHatches.CopyWithoutDelete &&
(UseHardlinksIfPossible || UseSymboliclinksIfPossible) &&
Copy link
Member

Choose a reason for hiding this comment

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

This seems to break tests. Why is it beneficial?

@@ -559,77 +607,23 @@ private bool CopyParallel(

// Lockless flags updated from each thread - each needs to be a processor word for atomicity.
var successFlags = new IntPtr[DestinationFiles.Length];
var actionBlockOptions = new ExecutionDataflowBlockOptions
{
MaxDegreeOfParallelism = parallelism,
Copy link
Member

Choose a reason for hiding this comment

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

the PR lost the logic for parallelism variable values, this should be cleaned up to be transparent that it does nothing apart from deciding if execution is synchronous or parallel (with the default values).

@yuehuang010
Copy link
Contributor

Is there an option to use TaskCreationOptions.LongRunning flag? This should avoid the thread starvation problem.

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.

5 participants