Bug Start-ThreadJob not pooling and hidden global constant #13549
Labels
Issue-Question
ideally support can be provided via other mechanisms, but sometimes folks do open an issue to get a
WG-Engine
core PowerShell engine, interpreter, and runtime
Steps to reproduce
Expected behavior
ThrottleLimit should either only apply for the one line it was specified with e.g. the one that fills $b and the other one for those that fill $c.
But that may be hard to impossible, as it would require the command within the scriptblock of the foreach knowing about the piping and even than it would break in countless of other cases.
The better fix may be adding a "ThreadPool" parameter that allows "ThrottleLimit" to just apply to that pool of threads, as well as documenting within the Get-Help pages that ThrottleLimit changes a global constant and that it influences already scheduled tasks.
A third possible fix would be to store the ThreadLimit with the ThreadJob id and compare the amount of currently running threads against the limit of the next one in the list (basically if 4 tasks already run and task 5 should be started, it simply could be checked what the ThreadLimit of task 5 is and if lesser Threads are currently running). This would introduce an implicit synchronization, as all tasks of b would complete before any of the ones within $c will start, but as the tasks are currently also processed using FIFO this may be the best fix. Using this approach all tasks within $b will be started using a ThreadLimit of 2, except the last one, that will be started using the ThreadLimit of $c. E.g. it will run together with the first 9 tasks of $c. This however is not an issue, as 9 is below the expected limit of 10. And also for the tasks in $b 1 is also below the there defined limit of 2. If the limit of a later task is smaller, it simply will not start until enough of the previous tasks have completed.
And the implementation of ThreadPools for Start-ThreadJob could be put into the backlog for being implemented with the next version.
When dealing with different APIs, the current behaviour could lead to unexpectedly running into rate limitations.
E.g. if $b contains threads to the API of e.g.
https://example.com/
with a strict rate limit of 2 and $c contains threads querying the api ofhttps://contoso.com/
with a less strict rate limit of 10Actual behavior
The ThrottleLimit apparently changes a global constant which influences how many threads within $b are started, even though it was specified for $c.
Environment data
The text was updated successfully, but these errors were encountered: