-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Update copy logic to use dedicated threads. #11272
Conversation
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. |
Related to #11160 |
Also updated some checks to help avoid hitting the file system if possible.
d0500f7
to
868969a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks reasonable, please
- fix the test
- cleanup
parallelism
parameter - 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)
Is there an option to use TaskCreationOptions.LongRunning flag? This should avoid the thread starvation problem. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. Thank you.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PR Overview
This PR updates the file copy logic to use dedicated threads to handle synchronous file copying, aiming to reduce threadpool starvation. Key changes include:
- Adding a dedicated thread pool with static thread arrays and action queues for parallel copying.
- Changing the parallelism configuration from an integer value to a boolean flag indicating whether to copy in parallel.
- Updating unit tests to reflect the new boolean-based parallelism setting.
Reviewed Changes
File | Description |
---|---|
src/Tasks/Copy.cs | Introduces dedicated thread pool logic and revises parallel copy execution. |
src/Framework/NativeMethods.cs | Adjusts long path handling in GetFullPath using stack-allocated buffers. |
src/Tasks.UnitTests/Copy_Tests.cs | Updates tests to use the new boolean parallelism flag. |
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
Comments suppressed due to low confidence (1)
src/Tasks/Copy.cs:57
- Review the use of static thread pool fields to ensure they don't interfere when multiple Copy task instances run concurrently; consider using instance-based thread pools or more robust synchronization if needed.
lock (_copyActionQueue)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the contribution!
@AR-May , could you please measure the impact of the change ?
Hi! Numbers:
I believe the performance difference is below our ability to detect it. |
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