8000 Jobs dynamically change AllocatedRunspaceCount · Issue #25539 · PowerShell/PowerShell · GitHub
[go: up one dir, main page]

Skip to content

Jobs dynamically change AllocatedRunspaceCount #25539

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

Open

agowa opened this issue May 11, 2025 · 1 comment
Open

Jobs dynamically change AllocatedRunspaceCount #25539

agowa opened this issue May 11, 2025 · 1 comment
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

Comments

@agowa
Copy link
agowa commented May 11, 2025

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.

@agowa agowa added 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. labels May 11, 2025
@iSazonov iSazonov added the WG-Engine core PowerShell engine, interpreter, and runtime label May 12, 2025
@kasini3000
Copy link

PowerShell is the best engine, and I use it to make the best cars.

Welcome to the "Kasini3000 Project", Open source, free, cross platform, based on PowerShell rather than Ansible over YAML
tech:
https://www.cnblogs.com/piapia/p/16534765.html

It has multi-process concurrency and multi-threaded concurrency.
It is based on the SQLite database and implements:
Thread task timeout, thread retry, priority over multiple-powershell-processes , executing multiple-threads within multiple-processes, task process rotation.

You can dynamically set the EACH load job number of multiple processes/threads from sqlite db by PowerShell global variable

$global:kcommit每次执行任务数 = 100 # To-be-run records read from the database each time
$global:kcommitrs每次执行任务数 = 60 # To-be-run records read from the database each 10 second.

Keep total concurrency by PowerShell global variable

$global:kcommit最大并发进程数 = 99 #max count limit for run simultaneously job by k-commit.ps1
$global:kcommitrs最大并发线程数_进程数_乘以_线程数_总和 = 300 # max count for run simultaneously job by k-commit-rs.ps1 in all process.

Only adjust batch tasks with specific comments

Each task has a comment field on SQLite, and as long as you define comments when submitting a batch of tasks at the kasini3000 command line,
you can adjust them using your own PowerShell script after submitting the tasks.
SQL statements on PS1, such as select, update when comments field = xxx.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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
Projects
None yet
Development

No branches or pull requests

3 participants
0