Powershell 3.0 - 工作流 - 限制并行执行的数量 [英] Powershell 3.0 - Workflows - Limit number of parallel execution
问题描述
我正在从模板克隆 ESX 服务器上的虚拟机.简化代码如下所示:
I am cloning VMs on ESX server from template. Simplified code looks like this:
Workflow Create-VM {
$List = 1..500
foreach -parallel ($Elem in $List)
{
# Create VM ...
# Configure created VM ..
}
}
Create-VM
并行执行真的很有帮助.不幸的是,在这种情况下效果不佳.生成了太多的并行请求.我需要将并行执行的数量限制为较小的数量(例如 4).
Parallel execution is really helpful. Unfortunately in this case doesn't work pretty well. Too many parallel request are generated. I need to limit number of parallel execution to smaller number (for example 4).
我试图更改本地会话配置(SessionThrottleLimit、MaxSessionsPerWorkflow、MaxRunningWorkflows)http://technet.microsoft.com/en-us/library/hh849862.aspx.
I was trying to change local Session Configuration (SessionThrottleLimit, MaxSessionsPerWorkflow, MaxRunningWorkflows) http://technet.microsoft.com/en-us/library/hh849862.aspx.
$WWE = New-PSWorkflowExecutionOption -SessionThrottleLimit 4
Set-PSSessionConfiguration -Name microsoft.powershell.workflow `
-SessionTypeOption $WWE
Get-PSSessionConfiguration microsoft.powershell.workflow |
fl SessionThrottleLimit
问题
- 我应该更改会话配置的哪个参数(或组合),以将并行执行的数量限制为 4?
- 是否还有其他方法可以实现这一点(例如:执行工作流的不同方式...)?
推荐答案
有一个选项可以使用 -throttlelimit N
来限制 foreach-parallel 循环中并行进程的数量.这对于减少并行度非常有用,但是如果您尝试大量的数量,系统可能仍会将您限制为 5,具体取决于您的所有软件版本(是的!Microsoft 一致性).我知道这个问题很老,但由于它在谷歌上出现而没有一个像样的答案,我想我会插话.
There is an option to limit the number of parallel processes in a foreach-parallel loop using -throttlelimit N
. It's great for reducing the parallelism, but if you try a high number the system may still limit you to 5, depending on all your software versions (YAY! Microsoft consistency). I know the question is old, but since it came up on Google without a decent answer, I thought I'd chime in.
Workflow Create-VM {
$List = 1..500
foreach -parallel -throttlelimit 4 ($Elem in $List)
{
# Create VM ...
# Configure created VM ..
}
}
Create-VM
这篇关于Powershell 3.0 - 工作流 - 限制并行执行的数量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!