【问题标题】:Limit the number of CPU cores used by an Windows service running from net start command限制从 net start 命令运行的 Windows 服务使用的 CPU 内核数
【发布时间】:2020-04-30 18:38:19
【问题描述】:

我正在 Windows 10 上运行 PostgreSQL 12 基准测试。我想限制 PostgreSQL 服务使用的 CPU 内核数量,以测试 CPU 性能如何影响 TPU。

现在我正在使用以下命令启动 PostgreSQL 服务:

 net start postgresql-x64-12

我知道如何限制普通 Windows 应用程序的 CPU 内核数量,例如:

 start /affinity 1 "" "C:\Windows\System32\calc.exe"

如何限制从 net start 命令运行的 Windows 服务使用的 CPU 内核数? net start 命令中是否有等效的 /affinity 选项?

【问题讨论】:

    标签: windows command-line windows-services


    【解决方案1】:

    我找到了解决方案。首先,您不能将 CPU 关联性设置为 Windows 系统进程或服务(请参阅https://www.atmarkit.co.jp/ait/articles/0703/16/news151.html(日语))。

    在我的情况下,我可以从 cmd.exe 的 pg_ctl 命令运行 PostgreSQL 进程,并使用 /affinity 选项,例如:

    cmd.exe /c "start /affinity 1F /B c:\path\to\PostgreSQL\12\bin\pg_ctl.exe start -w -s -D C:\path\to\PostgreSQL\12\data"
    

    请注意,您不能像这样使用 Start-Process cmdlet 和 ProcessorAffinity 属性:

    $app = Start-Process 'c:\path\to\PostgreSQL\12\bin\pg_ctl.exe' 'start -D C:\path\to\PostgreSQL\12\data' -PassThru -NoNewWindow
    $app.ProcessorAffinity = 0x3
    

    这会导致SetValueInvocationException,因为pg_ctl.exe 在启动PostgreSQL 实例后立即退出。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-04-06
      • 1970-01-01
      • 1970-01-01
      • 2022-09-18
      • 1970-01-01
      • 1970-01-01
      • 2019-10-05
      相关资源
      最近更新 更多