windows - 限制通过net start命令运行的Windows服务使用的CPU内核数

标签 windows command-line windows-services

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

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

 net start postgresql-x64-12

而且我知道如何限制普通Windows应用程序的CPU内核数量,例如:
 start /affinity 1 "" "C:\Windows\System32\calc.exe"

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

最佳答案

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

在我的情况下,我可以使用cmd.exe中的pg_ctl选项通过/affinity命令运行PostgreSQL进程:

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实例后立即退出。

关于windows - 限制通过net start命令运行的Windows服务使用的CPU内核数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61530480/

相关文章:

mysql - 为什么sqlite中显示 "no such column"却有 `pragma`?

linux - 为什么位置参数 $1 具有不同的值?

c - 在 c 中使用带有命令行参数的 if 语句

windows - Git: 无法推送 {n/a (unpacker error)}

windows - Windows 7 CoreAudio Media Foundation-IID_IAudioStreamVolume的用法

windows-services - MSDeploy安装windows服务?

mysql - 发生系统错误 5。访问被拒绝。 (MySQL)

mysql - 错误 1067 : The process terminated unexpectedly MYSQL, Windows Server 2008 R2

c# - Windows 上任何单个进程可以处理的最大内存量

windows - shutdown.exe 参数是破折号还是斜线?