第 1 章 SPEC CPU 2017 测试
1.1、测试简介
官方文档:https://www.spec.org/cpu2017/Docs/
SPEC 成立于 1988 年,是由斯坦福大学、清华大学、微软、等全球几十所知名大学、研究机构、IT 企业组成,是一个全球性的、权威的第三方应用性能测试组织,它旨在确立、修改以及认定一系列应用性能评估的标准。
SPEC CPU 2017 是一套 CPU 子系统测试工具,包括 4 大种类共 43 个测试,包括在测试整型速度、浮点运算速度的性能测试 SPECspeed 2017、SPECspeed 2017 Floating Point 以及测试整型并发速率和浮点并发速率 SPECrate 2017 Integer 和 SPECrate 2017 Floating Point 。借助于 OpenMP 多线程 API,SPEC CPU 2017 还可以在测试过程中监控功耗。
1.1.1、套件和指标介绍
简称 | 套件名 | 内容 | 指标 | 备注 |
---|---|---|---|---|
Intspeed | SPECspeed2017Integer | 10 integer benchmarks | SPECspeed2017_int_base SPECspeed2017_int_peak |
SPECspeed套件为每个基准运行一个副本; 得分高的意味着花费的时间越少。 |
Fpspeed | SPECspeed2017 Floating Point | 10 floating point benchmark | SPECspeed2017_fp_base SPECspeed2017_fp_peak |
SPECspeed套件为每个基准运行一个副本; 得分高的意味着花费的时间越少。 |
Intrate | SPECrate2017Integer | 10 integer benchmarks | SPECrate2017_int_base SPECrate2017_int_peak |
SPECrate套件为每个基准运行多个并发的副本; 由测试人员选择多少个副本; 得分高的意味着有更高的吞吐量。 |
fprate | SPECrate2017Floating Point | 13 floating point benchmark | SPECrate2017_fp_base SPECrate2017_fp_peak |
SPECrate套件为每个基准运行多个并发的副本; 由测试人员选择多少个副本; 得分高的意味着有更高的吞吐量。 |
- 可以根据自己的需要选择相应的套件运行(无需全部运行),并且选择会影响硬件的要求,SPECspeed 和 SPECrate 对内存和磁盘空间的要求都不相同;
- 如果使用 SPEC 公开的测试结果,则必须运行套件中的所有基准并至少产生基本度量;峰值指标是可选的,如果同时产生基础和峰值,则需要更多的磁盘空间;
1.1.2、SPECspeed 指标和 SPECrate 指标
有许多方法可以衡量计算机性能。其中最常见的是:
- 时间 —— 例如,完成工作量所需的秒数。
- 吞吐量 —— 每单位时间完成的工作,例如每小时的工作。
SPECspeed 是基于时间的指标;SPECrate 是吞吐量指标。
SPECspeed 指标 | SPECrate 指标 |
---|---|
套件中每个基准测试运行一个副本 | 测试人员自己定义运行的并发副本数 |
测试人员可以选择使用多少个 OpenMP 线程 | 禁用 OpenMP |
对于每个基准,性能比计算如下: 参考机器所用时间/SUT上的时间 |
对于每个基准,性能比计算如下: 副本数(参考机器所用的时间/SUT上的时间) |
所用时间越少,分数越高 | 每单位时间做的工作越多,分数越高 |
- 对于 SPECspeed 和 SPECrate,所选比率均使用 "几何平均值" 进行平均,该几何平均值被报告为总体度量。
- 参考计算机是一台历史悠久的 Sun Microsystems 服务器,即具有 2100 MHz UltraSPARC-IV + 芯片的 Sun Fire V490。UltraSPARC-IV + 于 2006 年推出,比 CPU 2000 和 CPU 2006 参考计算机(300 MHz 1997 UltraSPARC II)中使用的芯片更新。
1.2、前置条件
1.2.1、CPU 要求
SPEC 提供了用于 ARM,Power ISA,SPARC 或 X86 的工具集;支持物理 CPU、虚拟 CPU、SMP、OpenMP,可以使用 SPEC CPU 2017 来测量具有物理或虚拟 CPU/处理器 的系统的计算性能;可以选择测量系统或子集中的所有处理器;
通常,SPEC CPU 用于测量带所有物理 CPU 芯片的整个系统,不过也可以使用 SPEC CPU 2017 来测量系统上 CPU 资源的一个子集,例如使用虚拟机(VM),分区,区域,域,容器,处理器集,核心,硬件线程或其他子集;如果使用子集(例如 VM),则子集必须具有足够的内存和磁盘;
可以使用 SPEC CPU 2017 来评估任意数量的处理器的性能。通常,如果您的操作系统可以处理它,则 SPEC CPU工具集也可以处理它。
SPECrate 套件可同时运行多个相同的作业。通常,操作系统使用称为 SMP(对称多处理)的功能将它们分布在 CPU 上。
SPECspeed 套件一次运行一项工作。有些作业可以通过 OpenMP 或编译器自动并行化使用多个 CPU 。
以上几点总结在下表中:
注意事项 | SPECspeed | SPECrate |
---|---|---|
副本数 | 每个基准一次只能运行一个副本。 | 每个基准的多个副本同时运行。 |
编译器并行 | 可以使用 OpenMP 或编译器自动并行性进行编译。 | 禁止使用 OpenMP 和编译器 autopar。 |
如何使用? | 在构建时,启用 OpenMP。 使用 runcpu --threads = N 或相应的配置文件功能。 | 使用 runcpu --copies 或相应的配置文件功能。 |
1.2.2、内存需求
物理内存:
测试项 | 说明 |
---|---|
SPECrate | 每个副本 1GB(如果针对 32 位地址空间进行编译) 每个副本 2GB(如果为针对 64 位地址空间进行编译) |
SPECspeed | 16GB 最小系统主内存 |
虚拟内存:
测试项 | 说明 |
---|---|
SPECrate | -m32 你可以选择 32 位或 64 位编译器,这取决于你的系统、编译器和库 -m64 检查你的编译器文档切换 -m64 和 -m32 |
SPECspeed | -m64 这个 SPECspeed 基准不适合运行在 32 位;编译它们需要 64 位;进程限制必须允许最大堆栈 |
1.2.3、磁盘需求
下面的磁盘空间仅仅是估算,不同的环境需求会不一样:
安装方式 | 预期用途 | 详细信息 |
---|---|---|
开发 250GB+1.2GB/副本 | 在单个系统上安装、编译和运行 做调试运行; 测试编译器选项保留 2 到 4 套构建和运行; 最后还是需要清理磁盘空间。 |
2.5GB 安装 SPEC CPU 2017; 26GB 为所有 4 件套打造基础+高峰; 34GB 可报告的目录,基本+峰值,4 个套件,1 个副本; 0.6 GB 将另一个副本添加到 intrate 和 fprate(基本+峰值)。 |
基本可报告的 40GB+0.8GB/副本 | 安装在其他位置构建的二进制文件; 对一套构建使用 --reportable(intrate,fprate,intspeed 或 fpspeed)需要在套件之间进行清理; 无法使用一个 runcpu 命令选择多个套件。 |
2.5 GB 安装 SPEC CPU 2017 5 GB 为所有 4 个套件安装基准二进制文件(基准+峰值); 10 GB 可报告的目录,基本+峰值,1个套件,1个副本; 0.4 GB 添加另一个副本,基本+峰值,1套套件。 |
最小10GB+0.2GB/副本 | 无法执行可报告的运行。 无法建立完整套件(intrate,fprate,intspeed,fpspeed) 可以建立并运行1个基准测试(例如 500.perlbench_r)必须使用minimal_builddirs。必须经常运行 cpu --action = clobber。 |
2.5 GB 安装SPEC CPU 2017 2.5 GB 建立并运行最大的单一基准,minimum_builddirs,仅基于基准 0.1 GB 添加另一个副本,仅基于基准,最大的单个基准。 |
1.2.4、操作系统
SPEC CPU 2017 V1.0 支持的工具集:
工具集 | 描述 |
---|---|
AIX | 运行 AIX V7.1 或更高版本的 64 位 PowerPC 系统。 |
linux-aarch64 | 运行 Linux 的 64 位 AArch64 系统 |
linux-armv7l | 具有 ARM Cortex-A7 兼容 CPU 的 Linux 系统。 |
linux-ppc | 运行 Linux 的 32 位 PowerPC 系统 |
linux-ppc64 | 64 位大端 PowerPC Linux 系统 |
linux-ppc64le | 64 位 Little-endian PowerPC Linux 系统 |
linux-sparc | SPARC 硬件上的 64 位 Linux 系统 |
linux-x86_64 | x86_64 Linux 系统 |
macosx-x86 | 英特尔系统上的 MacOS X 10.6+ |
solaris-sparc | 运行 Solaris 10 08/11 或更高版本(包括 Solaris 11 和更高版本)的 64 位 SPARC 系统 |
solaris-x86 | 运行 Solaris 10 08/11 或更高版本(包括 Solaris 11 和更高版本)的 x86 系统 |
Windows x64 | 运行 Windows 7 或更高版本的 Windows 系统 |
1.2.5、编译器或二进制文件
SPEC 以源代码形式提供基准。因此,您将需要:一组编译器。这三个都是必需的:C99、C ++ 2003、Fortran 2003;或者,一组预编译的基准二进制文件(可执行文件),由同一版本的 SPEC CPU 2017 的另一个用户提供给您。
- 请注意,SPEC 不提供二进制文件。如上所述,SPEC 提供了源代码。
- 由不同版本的 SPEC CPU 2017 生成的二进制文件将不起作用。
- 您可能还需要针对这些可执行文件的一组运行时库。
- 请注意,即使别人编译基准测试中,测试人员负责遵守的规则:不要不接受来自不受信任来源的二进制文件。
- 整数套件是 CPU 2017 的新增功能,其中包括 Fortran 基准测试。
- 所有套件的可报告运行都需要所有三种语言(C,C ++,Fortran)的编译。
1.3、测试环境说明
1.3.1、硬件准备
配置 | x86 | arm64-single | arm64-double |
---|---|---|---|
CPU | X86(Gold 6138) | arm64-64core | arm64-128core |
MEM | 256G | 256G | 256G |
DISK | 480G(SSD) | 480G(SSD) | 480G(SSD) |
1.3.2、配置 spec cpu 2017
- 安装 spec cpu 2017
[root@arm64v8 mnt]# mount -o loop cpu2017-1_0_5.iso /mnt
[root@arm64v8 mnt]# cd /mnt
[root@arm64v8 mnt]# ./install.sh -d /opt/spec2017
......
Installation successful. Source the shrc or cshrc in
/opt/spec2017
to set up your environment for the benchmark.
[root@arm64v8 mnt]# cd /opt/spec2017/
[root@arm64v8 spec2017]# ls
benchspec cshrc install.sh PTDaemon Revisions tmp uninstall.sh
bin Docs LICENSE.txt README.txt shrc tools version.txt
config install.bat MANIFEST result shrc.bat TOOLS.sha512
[root@arm64v8 spec2017]#
[root@arm64v8 spec2017]# source shrc
-
配置 runspec 运行测试的环境配置文件
[root@arm64v8 ~]# yum install gcc gcc-c++ gcc-gfortran -y [root@arm64v8 ~]# which gcc g++ gfortran /usr/bin/gcc /usr/bin/g++ /usr/bin/gfortran [root@arm64v8 ~]# cd /opt/spec2017/ [root@arm64v8 spec2017]# cp config/Example-gcc-linux-aarch64.cfg config/brinnatt.cfg [root@arm64v8 spec2017]# vim config/brinnatt.cfg # Use: % define gcc_dir /opt/rh/devtoolset-6/root/usr # Use: % define gcc_dir /disk1/mybuild/gcc-8.1.0 # Use: % define gcc_dir /usr 这里要指向刚查看的 gcc g++ gfortran 的路径
- 编译器 gcc g++ gfortran 三者缺一不可。
- 配置文件我们就借鉴官方的 Example-gcc-linux-aarch64.cfg 文件,取名为 brinnatt.cfg。
- 把 brinnatt.cfg 稍作修改,特别是 define gcc_dir 同时定义的是 gcc,g++ 和 gfortran 路径,若三者路径不一致需各自定义。
-
配置编译器参数描述文件,不然生成的报告会出现 invalid 水印
[root@arm64v8 spec2017]# cp config/flags/gcc.xml config/flags/brinnatt.xml
-
直接借用官方 gcc.xml 描述文件,取名为 brinnatt.xml。
-
注意,如果不手动指定描述文件也是可以的,但必须在环境配置文件中提前指定,以手动指定优先级最高,比如,brinnatt.cfg 配置文件中已指定如下。
flagsurl = $[top]/config/flags/gcc.xml
-
-
查看 runcpu 测试命令的用法
[root@arm64v8 spec2017]# runcpu --help ...... --config file | -c file: 用于指定本次运行的配置文件 --size | -i: 规模选择,分为test(简单规模模式,测试时间最短)、train(中级规模模式,测试时间居中)、ref(高级规模模式,测试时间最长); --tune | -T: 测试基准,分为base(基准值)和peak(峰值),all表示SPEC CPU2017将运行基准测试程序中的所有测试项目; --iterations=3 | -n: 测试次数,官方建议为3次,设置3次可自动计算分数,设置1次需要手算分数; --copies | -C: 测试核数,如-C 64; --reportable | -s: 生成可报告的结果 --threads: 测试speed则需添加。如果选择speed度量方式,其核数固定为1,不可更改。 --flagsurl | -F gcc.xml: 去除pdf报告水印。
- 这里只给出了我常用的几个选项,可以自行查看帮助信息。
- runcpu --update 可连接外网更新 benchmark 套件,example flag files 和 config files。目前手上 speccpu2017 安装包版本为 V1.0.5,连外网可升级到最新版本 V1.1.0。
1.4、运行 runcpu 测试
[root@arm64v8 spec2017]# runcpu --config /opt/spec2017/config/brinnatt.cfg --flags /opt/spec2017/config/flags/brinnatt.xml --reportable --tune base --iterations=3 intrate
[root@arm64v8 spec2017]# runcpu --config /opt/spec2017/config/brinnatt.cfg --flags /opt/spec2017/config/flags/brinnatt.xml --reportable --tune base --iterations=3 intspeed
[root@arm64v8 spec2017]# runcpu --config /opt/spec2017/config/brinnatt.cfg --flags /opt/spec2017/config/flags/brinnatt.xml --reportable --tune base --iterations=3 fprate
[root@arm64v8 spec2017]# runcpu --config /opt/spec2017/config/brinnatt.cfg --flags /opt/spec2017/config/flags/brinnatt.xml --reportable --tune base --iterations=3 fpspeed
-
在测试 fpspeed 时,627.cam4_s 对堆栈使用过大,默认的 120M 不能满足需求,需改为 1G 或更大;
[root@arm64v8 spec2017]# vim config/brinnatt.cfg fpspeed: # # 627.cam4 needs a big stack; the preENV will apply it to all # benchmarks in the set, as required by the rules. # preENV_OMP_STACKSIZE = 120M --> 改成 1G
-
还需要调整操作系统的内核堆栈大小;
# 查看一下当前系统的一些限制 [root@arm64v8 spec2017]# ulimit -a core file size (blocks, -c) unlimited data seg size (kbytes, -d) unlimited scheduling priority (-e) 0 file size (blocks, -f) unlimited pending signals (-i) 1036505 max locked memory (kbytes, -l) 64 max memory size (kbytes, -m) unlimited open files (-n) 1024 pipe size (512 bytes, -p) 8 POSIX message queues (bytes, -q) 819200 real-time priority (-r) 0 stack size (kbytes, -s) 8192 cpu time (seconds, -t) unlimited max user processes (-u) 1036505 virtual memory (kbytes, -v) unlimited file locks (-x) unlimited [root@arm64v8 spec2017]# # 解开 stack size 的限制 [root@arm64v8 spec2017]# ulimit -s unlimited [root@arm64v8 spec2017]# ulimit -a core file size (blocks, -c) unlimited data seg size (kbytes, -d) unlimited scheduling priority (-e) 0 file size (blocks, -f) unlimited pending signals (-i) 1036505 max locked memory (kbytes, -l) 64 max memory size (kbytes, -m) unlimited open files (-n) 1024 pipe size (512 bytes, -p) 8 POSIX message queues (bytes, -q) 819200 real-time priority (-r) 0 stack size (kbytes, -s) unlimited cpu time (seconds, -t) unlimited max user processes (-u) 1036505 virtual memory (kbytes, -v) unlimited file locks (-x) unlimited [root@arm64v8 spec2017]#
- 为了方便,我这里是直接改成了 unlimited,注意这个设置只在当前 shell 生效,想要永久生效,写在 /etc/security/limits.conf 配置文件中。
1.5、测试结果
1.5.1、物理服务器满核测试结果
1.5.2、物理服务器运行 64 个副本并发的测试结果
A、附录
A1、PerformanceTEST 测试
SPEC CPU 2017 虽说是业内比较权威的 CPU 测试方案,但是使用起来没有那么便捷。相比较而言,PerformanceTEST 这个工具使用起来就非常简单,这个工具同样是一款商业软件,在 windows 上应用比较广泛,类似 "鲁大师跑分",针对 Linux、MAC 和 Android 免费。
官方地址:https://www.passmark.com/products/performancetest/
在 4c8g 的 arm64 台式机上测试:
root@arm64v8:~# wget wget https://www.passmark.com/downloads/pt_linux_arm64.zip
root@arm64v8:~# ls
pt_linux_arm64.zip
root@arm64v8:~# unzip pt_linux_arm64.zip
存档文件: pt_linux_arm64.zip
creating: PerformanceTest/
inflating: PerformanceTest/pt_linux_arm64
inflating: PerformanceTest/readme.txt
root@arm64v8:~# cd PerformanceTest/
root@arm64v8:~/PerformanceTest# ./pt_linux_arm64
PassMark PerformanceTest Linux
Phytium,FT-2000/4 (aarch64)
4 cores @ 2600 MHz | 7.7 GiB RAM
Number of Processes: 4 | Test Iterations: 1 | Test Duration: Medium
--------------------------------------------------------------------------
CPU Mark: 1685
Integer Math 17435 Million Operations/s
Floating Point Math 6058 Million Operations/s
Prime Numbers 16.8 Million Primes/s
Sorting 7362 Thousand Strings/s
Encryption 343 MB/s
Compression 12827 KB/s
CPU Single Threaded 680 Million Operations/s
Physics 222 Frames/s
Extended Instructions (NEON) 1128 Million Matrices/s
Memory Mark: 1130
Database Operations 1536 Thousand Operations/s
Memory Read Cached 9472 MB/s
Memory Read Uncached 6558 MB/s
Memory Write 7239 MB/s
Available RAM 5277 Megabytes
Memory Latency 107 Nanoseconds
Memory Threaded 14138 MB/s
--------------------------------------------------------------------------
Results not submitted
Upload results to cpubenchmark.net? [Y/n]:
Use ESC or CTRL-C to exit
A: Run All Tests C: Run CPU Tests M: Run Memory Tests U: Upload Test Results
A2、stress-ng 测试
stress-ng 以各种可选择的方式对计算机系统进行压力测试。它被设计用来测试计算机的各种物理子系统以及各种操作系统内核接口。stress-ng 特点:
- 超过 260 种压力测试
- 85 种以上的 CPU 特定的压力测试,用来测试浮点、整数、位操作和控制流
- 超过 20 个虚拟内存压力测试
- 可移植性强,支持 Linux、Solaris、BSD、Android、MacOS X 以及 windows 等操作系统;同时支持 x86-64、i386、s390x、ppc64el、armhf、arm64、sparc64、risc-v、m68k 以及 mips64 等硬件架构。
stress-ng 设计的初衷是让操作系统在苛刻的环境下运行,把硬件的极限表达出来,在一些硬件或操作系统有漏洞的情况下,可能发生意想不到的热运行,导致无法停止,甚至使操作系统受到重创。所以要做好提前预防。
在 root 权限下运行 stress-ng 将调整 Linux 系统上的内存设置,以使压力源在内存不足的情况下不被杀死,因此要谨慎使用这种方法。使用适当的特权,stress-ng 可以允许调整 ionice 类和 ionice 级别,同样,要谨慎使用。
另外 stress-ng 不是一个专业的性能测试套件,也无法像 spec cpu 2017 那样得到专业的数据分析报告。因此,使用 stress-ng 只是对你的硬件和操作系统进行一次压力测试,让你对即将使用的这套设备有足够的了解。
下面我们使用 rpm 自带的安装源进行 stress-ng 安装,做一些初级测试;如果想使用 stress-ng 源码编译安装,不防参考 https://github.com/ColinIanKing/stress-ng。
-
运行 8 个 workers 虚拟内存压力源,填充可用内存的 80%,运行 1 个小时;因此每个压力源占据可用内存的 10%。
stress-ng --vm 8 --vm-bytes 80% -t 1h
-
运行 4 个 cpu workers 压力源;运行 2 个 io workers 压力源;运行 1 个虚拟内存 work 压力源,映射虚拟内存 1G;运行 60 秒。
stress-ng --cpu 4 --io 2 --vm 1 --vm-bytes 1G --timeout 60s
-
运行 2 个 mixed I/O 实例,占据可用文件系统空间的 10%,运行 10 分钟;也就是每一个压力源占据可用文件系统空间的 5%。
stress-ng --iomix 2 --iomix-bytes 10% -t 10m
-
通过 hdd 压力源测量 real time 调度延迟,它使用高分辨率纳秒时钟来测量 10000 纳秒睡眠期间的延迟。1 分钟的压力测试之后,将显示间隔为 2500 ns 的时延分布。
stress-ng --cyclic 1 --cyclic-dist 2500 --cyclic-method clock_ns --cyclic-prio 100 --cyclic-sleep 10000 --hdd 0 -t 1m
- 注意:必须与 CAP_SYS_NICE 功能一起运行,以启用实时调度以获得精确的测量。
-
运行 8 个 cpu 压力源,经过 800000 bogo 操作后停止
stress-ng --cpu 8 --cpu-ops 800000
-
Bogo Ops:stress -ng 使用 "bogus operations per second" 也就是每秒伪操作来度量压力测试的 "吞吐量"。
root@arm64v8:~# stress-ng --cpu 4 --cpu-ops 8000 stress-ng: info: [9175] defaulting to a 86400 second run per stressor stress-ng: info: [9175] dispatching hogs: 4 cpu stress-ng: info: [9175] cache allocate: using built-in defaults as unable to determine cache details stress-ng: info: [9175] cache allocate: default cache size: 2048K stress-ng: info: [9175] successful run completed in 24.11s root@arm64v8:~# root@arm64v8:~# stress-ng --cpu 4 --cpu-ops 8000 --metrics-brief stress-ng: info: [9206] defaulting to a 86400 second run per stressor stress-ng: info: [9206] dispatching hogs: 4 cpu stress-ng: info: [9206] cache allocate: using built-in defaults as unable to determine cache details stress-ng: info: [9206] cache allocate: default cache size: 2048K stress-ng: info: [9206] successful run completed in 23.62s stress-ng: info: [9206] stressor bogo ops real time usr time sys time bogo ops/s bogo ops/s stress-ng: info: [9206] (secs) (secs) (secs) (real time) (usr+sys time) stress-ng: info: [9206] cpu 8000 23.56 93.66 0.00 339.50 85.42 root@arm64v8:~#
- 使用 --metrics-brief 选项显示 bogo ops。
-
-
其它示例
# run 2 simultaneous instances of all the stressors sequentially one by one, each for 2 minutes and summarise with performance metrics at the end. stress-ng --sequential 2 --timeout 2m --metrics # run 4 FFT cpu stressors, stop after 10000 bogo operations and produce a summary just for the FFT results. stress-ng --cpu 4 --cpu-method fft --cpu-ops 10000 --metrics-brief # run cpu stressors on all online CPUs working through all the available CPU stressors for 1 hour, loading the CPUs at 90% load capacity. stress-ng --cpu -1 --cpu-method all -t 1h --cpu-load 90 # run cpu stressors on all configured CPUs working through all the available CPU stressors for 20 minutes stress-ng --cpu 0 --cpu-method all -t 20m # run 4 instances of all the stressors for 5 minutes. stress-ng --all 4 --timeout 5m # run 64 stressors that are randomly chosen from all the available stressors. stress-ng --random 64 # run 64 instances of all the different cpu stressors and verify that the computations are correct for 10 minutes with a bogo operations summary at the end. stress-ng --cpu 64 --cpu-method all --verify -t 10m --metrics-brief # run all the stressors one by one for 10 minutes, with the number of instances of each stressor matching the number of online CPUs. stress-ng --sequential -1 -t 10m # run all the stressors in the io class one by one for 5 minutes each, with 8 instances of each stressor running concurrently and show overall time utilisation statistics at the end of the run. stress-ng --sequential 8 --class io -t 5m --times # run all the stressors (1 instance of each per online CPU) simultaneously, maximize the settings (memory sizes, file allocations, etc.) and select the most demanding/aggressive options. stress-ng --all -1 --maximize --aggressive # run 32 randomly selected stressors and exclude the numa, hdd and key stressors stress-ng --random 32 -x numa,hdd,key # run 4 instances of the VM stressors one after each other, excluding the bigheap, brk and stack stressors stress-ng --sequential 4 --class vm --exclude bigheap,brk,stack # run 3 instances of the CPU stressor and pin them to CPUs 0, 2 and 3. stress-ng --taskset 0,2-3 --cpu 3
以下为 deepseek 科谱,请以实际测试为准
场景 1:稳定占用资源(可控压测)
适用于测试环境,精确控制 CPU、内存、磁盘、网络占用,不导致系统崩溃。
1、CPU 压测(稳定占用 4 个核心 100%)
stress-ng --cpu 4 --cpu-load 100 --timeout 60s
--cpu 4
:使用 4 个 CPU 核心(按需调整)。--cpu-load 100
:每个核心负载 100%(可调 50-100)。--timeout 60s
:运行 60 秒(不设则持续运行)。
2、内存压测(稳定占用 2GB,避免被缓存)
stress-ng --vm 1 --vm-bytes 2G --vm-keep --vm-method all --vm-hang 0 --timeout 60s
--vm 1
:1 个内存压测进程。--vm-bytes 2G
:占用 2GB 内存(按需调整)。--vm-keep
:保持占用,不释放。--vm-method all
:多种内存操作方式,确保used
上升。--vm-hang 0
:无延迟,持续施压。
3、磁盘 IO 压测(写入 1GB 文件,4 线程)
stress-ng --io 4 --hdd 1 --hdd-bytes 1G --timeout 60s
--io 4
:4 个 IO 线程。--hdd 1
:1 个磁盘写入进程。--hdd-bytes 1G
:写入 1GB 数据(避免占满磁盘)。--timeout 60s
:运行 60 秒。
4、网络压测(TCP/UDP 流量,需 root)
stress-ng --sock 2 --sock-type tcp --sock-port 8080 --timeout 60s
--sock 2
:2 个 socket 压测进程。--sock-type tcp
:使用 TCP(可选udp
)。--sock-port 8080
:绑定端口(避免冲突)。--timeout 60s
:运行 60 秒。
场景 2:生产环境极限压测(耗尽资源)
模拟高并发场景,彻底耗尽 CPU、内存、磁盘、网络资源,测试系统极限。
1、CPU 极限压测(所有核心 100%,无超时)
stress-ng --cpu $(nproc) --cpu-load 100
$(nproc)
:使用全部 CPU 核心。- 无
--timeout
:持续运行,直到手动终止(Ctrl+C
)。
2、内存极限压测(占用 90% 物理内存)
stress-ng --vm $(nproc) --vm-bytes $(free -m | awk '/Mem:/ {print int($2*0.9)}')M --vm-keep --vm-method all
$(nproc)
:每个 CPU 核心一个内存压测进程。free -m | awk ...
:计算 90% 总内存(避免 OOM Killer 直接杀进程)。- 无
--timeout
:持续占用,直到手动终止。
3、磁盘 IO 极限压测(多线程写入临时文件)
stress-ng --io 16 --hdd $(nproc) --hdd-bytes 10G --hdd-noclean
--io 16
:16 个 IO 线程。--hdd $(nproc)
:每个 CPU 核心一个磁盘写入进程。--hdd-bytes 10G
:每次写入 10GB(根据磁盘空间调整)。--hdd-noclean
:不清理临时文件,持续堆积 IO 压力。
4、网络极限压测(大量 TCP 连接 + 带宽占用)
stress-ng --sock $(nproc) --sock-type tcp --sock-ops 1000000
--sock $(nproc)
:每个 CPU 核心一个 socket 压测进程。--sock-ops 1000000
:每个进程执行 100 万次网络操作(模拟高并发)。