Jobs dynamically change AllocatedRunspaceCount #25539
Labels
Issue-Enhancement
the issue is more of a feature request than a bug
Needs-Triage
The issue is new and needs to be triaged by a work group.
WG-Engine
core PowerShell engine, interpreter, and runtime
Summary of the new feature / enhancement
For better adaption to dynamic load it would be great if jobs could be dynamically updated with the amount of parallel childjobs it processes.
Such a feature is especially desirable when the limit in question does not arise from local resources like cpu, or memory but from something remote and where an API as it is way more difficult to impossible to get a good limit without dialing it in (aka slowly increasing the load)
E.g. all jobs get scheduled via:
$bgJobs = ... | ForEach-Object -ThrottleLimit 32 -AsJob -Parallel {Do-Some -LongRunningBackgroundJob}
. Then something at runtime happens and the limit needs to be updated (or alternatively simply because the system is either under or over utilized by this task).Proposed technical implementation details (optional)
Add an "UpdateThrottleLimit" method to System.Management.Automation.PSTasks.PSTaskJob that when called will influence how many pending jobs get scheduled moving forward
$bgJobs.UpdateThrottleLimit(20)
.Or the
AllocatedRunspaceCount
property is extended with an additional setter$bgJobs.AllocatedRunspaceCount = 20
E.g. there are 2000 jobs in the queue the current limit is 32 and therefore 32 are currently running. When the limit is lowered (
$bgJobs.UpdateThrottleLimit(5)
) no additional job is started until the number of currently running jobs falls below it. If the limit is increased ($bgJobs.UpdateThrottleLimit(64)
) additional child jobs are started until it is reached.The text was updated successfully, but these errors were encountered: