Powershell:最大是多少? Foreach-Object -Parallel 的 Throttlelimit 值?

发布于 2025-01-15 00:44:47 字数 1347 浏览 4 评论 0原文

我有 100 万个项目需要使用 Powershell 检查。为了提高性能,我想使用 ForEach-Object -Parallel。为此,我部署了一个非常强大的VM。

文档: https: //learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/foreach-object?view=powershell-7.2#description

运行空间池大小由 ThrottleLimit 参数指定。 默认运行空间池大小为 5。您仍然可以创建新的 使用 UseNewRunspace 开关为每次迭代提供运行空间。

我注意到无论我将限制设置多高,CPU 使用率都不会增加。该参数有技术上的最大限制吗?我的印象是,超过某个值,限制就会受到限制。

$oneMillionItems | ForEach-Object -Parallel {
        Do something ...
} -Throttlelimit 300

输入图片此处描述

PS > $PSVersionTable

Name                           Value
----                           -----
PSVersion                      7.2.1
PSEdition                      Core
GitCommitId                    7.2.1
OS                             Microsoft Windows 10.0.20348
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

I have 1 Million Items to check with Powershell. To improve the performance, I want to use ForEach-Object -Parallel. For this reason, I have deployed a very powerful VM.

Docs:
https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/foreach-object?view=powershell-7.2#description

The runspace pool size is specified by the ThrottleLimit parameter.
The default runspace pool size is 5. You can still create a new
runspace for each iteration using the UseNewRunspace switch.

I notice that no matter how high I set the limit, the CPU usage does not increase. Is there a technical maximum limit for this parameter? I have the impression that above a certain value the limit is simply capped.

$oneMillionItems | ForEach-Object -Parallel {
        Do something ...
} -Throttlelimit 300

enter image description here

PS > $PSVersionTable

Name                           Value
----                           -----
PSVersion                      7.2.1
PSEdition                      Core
GitCommitId                    7.2.1
OS                             Microsoft Windows 10.0.20348
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文