-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Poor Performance in Foreach -Parallel #10450
Copy link
Copy link
Closed
Labels
Issue-Questionideally support can be provided via other mechanisms, but sometimes folks do open an issue to get aideally support can be provided via other mechanisms, but sometimes folks do open an issue to get aWG-Engine-Performancecore PowerShell engine, interpreter, and runtime performancecore PowerShell engine, interpreter, and runtime performance
Metadata
Metadata
Assignees
Labels
Issue-Questionideally support can be provided via other mechanisms, but sometimes folks do open an issue to get aideally support can be provided via other mechanisms, but sometimes folks do open an issue to get aWG-Engine-Performancecore PowerShell engine, interpreter, and runtime performancecore PowerShell engine, interpreter, and runtime performance
It was reported here PowerShell/PowerShell-RFC#194 by @Ayanmullick
that
Thomas Lee put up this case where it was slower. https://twitter.com/doctordns/status/1164461929093566465
It is understood that parallelizing trivial code in will more overhead than the time saved
Using Start-Parallel from the PowerShell Gallery I ran this to ping every machine on my local subnet. 200 addresses are not used, so in sequence it would take 800-1000 seconds.
1..254 | Start-Parallel -Scriptblock {param ($P) ping "192.168.0.$p" -n 1 | where {$_ -match "ttl="}} -MaxThreads 300it took 9 seconds
The new equivalent is
1..254 | foreach -Parallel {ping "192.168.0.$_" -n 1 | where {$_ -match "ttl="}} -ThrottleLimit 300Which takes 31 seconds; I would expect broadly similar performance with the cmdlet slightly faster.
Using threadjob which ships with PS 6 and 7 I created this
Which runs in 11 seconds.
The cmdlet should be doing something very similar to this but not taking 3 times as long