Linux - 需要将 16 核系统限制为 4 个以测试性能 运行 多个程序

Linux - Need to limit a 16 core system to 4 to test performance running multiple programs

我有几个程序将放在核心有限的系统上。 我想在我当前的系统上测试这些程序的性能,该系统比将要使用的系统强大得多。

完全限制适当资源的唯一方法是通过我系统上的虚拟机,还是我可以限制我的系统以满足与我的程序 运行 上的其他系统相同的核心限制?

taskset 可能对您有帮助。

按如下方式启动您的应用程序your_command

taskset -ac 0-3 your_command
# -c 0-3: your_command might run on cores 0 to 3
#  a    : all of the 4 cores may be used

如果申请已经是运行:

taskset -acp 0-3 PID
# PID = process ID

有关详细信息,请参阅 this answer to 'Limit process to one cpu core' at Unix & Linux