-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Fix for ForEach-Object -Parallel perf problem with many runspaces #10455
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
Fix for ForEach-Object -Parallel perf problem with many runspaces #10455
Conversation
|
The change is causing a lot memory allocations as compared to before. Scenario: Before change: 105 MB in 2.6 minutes |
Dismiss Aditya's review given his new finding regarding the PR.
|
@adityapatwardhan As long as the CLR eventually collects the memory, I think we are Ok. I have run tests that loop for hours, detecting handle and working set usage. So far I see the usage plateau after a while so there seems to be no resource leak. However, the CLR and GC is getting a lot of exercise! |
|
Speed is awesome, but I don't think most folks will agree that... what, 10 gigabytes(?) of RAM usage for a task that is literally doing no work is something they'll want to work with regularly if at all. Are currently available alternatives this excessive in terms of memory usage? (e.g., PoshRSJobs?) |
The code is useless and is essentially creating 100s of thousands of managed objects and releasing them as fast as possible. It is no surprise that memory usage peaks until GC can deal with it. This is more about managed code and the CLR than about PowerShell. You can do the same thing by writing silly C# code. |
|
🎉 Handy links: |
PR Summary
This is a fix for the ForEach-Object perf Issue: #10450.
PR Context
The problem was that the number of concurrent runspaces was being limited to around 40-50, even though the ThrottleLimit was set to 300. It turns out it was the Cmdlet input processing thread that was causing the bottleneck. I don't know what the conflict is while spinning up runspaces, but the fix is to now do this on a dedicated thread similar to how it currently works for -AsJob.
PR Checklist
.h,.cpp,.cs,.ps1and.psm1files have the correct copyright headerWIP:or[ WIP ]to the beginning of the title (theWIPbot will keep its status check atPendingwhile the prefix is present) and remove the prefix when the PR is ready.