云计算百科
云计算领域专业知识百科平台

stress-ng 服务器压力测试的工具学习

一、stress-ng (下一代压力测试) 介绍

项目地址:https://github.com/ColinIanKing/stress-ng

stress-ng 将以多种可选方式对计算机系统进行压力测试。它旨在锻炼计算机的各种物理子系统以及各种操作系统内核接口。stress-ng 的特点:

  • 360+ 压力测试
  • 100+ 针对 CPU 的压力测试,涵盖浮点数、整数、位操作和控制流
  • 60+ 虚拟内存压力测试
  • 80+ 文件系统压力测试
  • 50+ 内存/CPU 缓存压力测试
  • 便携性:支持在 Linux(Debian、Devuan、RHEL、Fedora、Centos、Slackware OpenSUSE、Ubuntu 等)、Solaris、FreeBSD、NetBSD、OpenBSD、DragonFlyBSD、Minix、Android、MacOS X、Serenity OS、GNU/Hurd、Haiku、Windows Subsystem for Linux、Cygwin 以及 SunOs/Dilos/Solaris 上构建,使用 gcc、musl-gcc、clang、icc、icx、tcc 和 pcc 编译器。
  • 在 alpha、armel、armhf、arm64、hppa、i386、loong64、m68k、mips32、mips64、power32、ppc64el、risc-v、sh4、s390x、sparc64、x86-64 架构上测试。

stress-ng 最初的设计目的是让机器高负荷运行,以触发硬件问题(如热过载)以及仅在系统被高强度使用时才会出现的操作系统错误。使用 stress-ng 需谨慎,因为某些测试可能导致设计不良的硬件系统过热,并可能引发难以停止的过度系统抖动。

stress-ng 还可以测量测试吞吐率;这有助于观察不同操作系统版本或不同硬件类型的性能变化。然而,它从未被设计为精确的基准测试套件,因此请勿以这种方式使用它。

以 root 权限运行 stress-ng 将调整 Linux 系统的内存不足设置,使压力测试工具在低内存情况下无法被杀死,因此请谨慎使用。在适当的权限下,stress-ng 可以允许调整 ionice 类和 ionice 级别,同样,这应该小心使用。

二、 stress-ng 安装

stress-ng 有多种安装方式,docker,源码,系统包。这里使用源码安装,源码安装比较通用,在ubunt22.04上进行安装

github项目无法拉去时时gitee地址:https://gitee.com/mirrors/stress-ng.git

  • 下载构建环境

    apt-get install gcc g++ libacl1-dev libaio-dev libapparmor-dev libatomic1 libattr1-dev libbsd-dev libcap-dev libeigen3-dev libgbm-dev libcrypt-dev libglvnd-dev libipsec-mb-dev libjpeg-dev libjudy-dev libkeyutils-dev libkmod-dev libmd-dev libmpfr-dev libsctp-dev libxxhash-dev zlib1g-dev -y

  • 克隆代码

    root@stress:~# git clone https://gitee.com/mirrors/stress-ng.git

  • 安装

    root@stress:~# cd stress-ng/
    root@stress:~/stress-ng# make clean
    root@stress:~/stress-ng# make -j
    root@stress:~/stress-ng# make install

  • 三、压力测试

  • 压满所有cpu,执行60秒,并生成报告

    root@stress:~# stress-ng –cpu 4 -t 60s –metrics
    stress-ng: info: [366611] setting to a 1 min run per stressor
    stress-ng: info: [366611] dispatching hogs: 4 matrix
    stress-ng: metrc: [366611] stressor bogo ops real time usr time sys time bogo ops/s bogo ops/s CPU used per RSS Max
    stress-ng: metrc: [366611] (secs) (secs) (secs) (real time) (usr+sys time) instance (%) (KB)
    stress-ng: metrc: [366611] matrix 1300112 60.00 238.44 0.67 21668.05 5437.21 99.63 3648
    stress-ng: metrc: [366611] miscellaneous metrics:
    stress-ng: metrc: [366611] matrix 333299.37 add matrix ops per sec (harmonic mean of 4 instances)
    stress-ng: metrc: [366611] matrix 660483.97 copy matrix ops per sec (harmonic mean of 4 instances)
    stress-ng: metrc: [366611] matrix 230069.98 div matrix ops per sec (harmonic mean of 4 instances)
    stress-ng: metrc: [366611] matrix 110125.18 frobenius matrix ops per sec (harmonic mean of 4 instances)
    stress-ng: metrc: [366611] matrix 655736.94 hadamard matrix ops per sec (harmonic mean of 4 instances)
    stress-ng: metrc: [366611] matrix 312893.74 identity matrix ops per sec (harmonic mean of 4 instances)
    stress-ng: metrc: [366611] matrix 528567.28 mean matrix ops per sec (harmonic mean of 4 instances)
    stress-ng: metrc: [366611] matrix 678433.17 mult matrix ops per sec (harmonic mean of 4 instances)
    stress-ng: metrc: [366611] matrix 635834.08 negate matrix ops per sec (harmonic mean of 4 instances)
    stress-ng: metrc: [366611] matrix 760.09 prod matrix ops per sec (harmonic mean of 4 instances)
    stress-ng: metrc: [366611] matrix 479447.95 sub matrix ops per sec (harmonic mean of 4 instances)
    stress-ng: metrc: [366611] matrix 814.18 square matrix ops per sec (harmonic mean of 4 instances)
    stress-ng: metrc: [366611] matrix 123778.71 trans matrix ops per sec (harmonic mean of 4 instances)
    stress-ng: metrc: [366611] matrix 880443.76 zero matrix ops per sec (harmonic mean of 4 instances)

    • –metrics :压力测试结束时输出一些伪性能指标,提供系统在测试过程中活动的概况,帮助用户了解系统在不同负载下的表现。
    • -t : 超时时间
    • –cpu 4 : 启用4个线程才执行cpu密集型任务
  • 内存测试

    root@stress:~# stress-ng –vm 4 –vm-byte 1G -t 60s –metrics
    stress-ng: info: [372717] setting to a 1 min run per stressor
    stress-ng: info: [372717] dispatching hogs: 4 vm
    stress-ng: metrc: [372717] stressor bogo ops real time usr time sys time bogo ops/s bogo ops/s CPU used per RSS Max
    stress-ng: metrc: [372717] (secs) (secs) (secs) (real time) (usr+sys time) instance (%) (KB)
    stress-ng: metrc: [372717] vm 5794318 60.01 226.55 12.77 96561.89 24211.64 99.71 298116
    stress-ng: info: [372717] skipped: 0`在这里插入代码片`
    stress-ng: info: [372717] passed: 4: vm (4)
    stress-ng: info: [372717] failed: 0
    stress-ng: info: [372717] metrics untrustworthy: 0
    stress-ng: info: [372717] successful run completed in 1 min

    • –vm 4: 启动 4 个虚拟内存工作线程
    • –vm-byte 1G: 每个虚拟现场分配1G内存
  • 磁盘及I/O测试

    stress-ng –io 6 –pseek 4 –hdd-bytes 1024M -t 60 –metrics

    • –io 6:启动 6 个磁盘 I/O 工作线程来执行同步操作
    • –pseek 4: 启动 4 个 worker 线程来执行磁盘随机读写操作。
    • –hdd-bytes 1024M : 为每个磁盘 I/O 工作线程和随机读写工作线程分配 1024MB 的磁盘空间。这表示每个线程会使用 1024MB 的磁盘空间来执行 I/O 操作。

    root@stress:~# stress-ng –io 6 –pseek 4 –hdd-bytes 1024M -t 60 –metrics
    stress-ng: info: [379354] setting to a 1 min run per stressor
    stress-ng: info: [379354] dispatching hogs: 6 io, 4 pseek
    stress-ng: info: [379355] io: this is a legacy I/O sync stressor, consider using iomix instead
    stress-ng: metrc: [379354] stressor bogo ops real time usr time sys time bogo ops/s bogo ops/s CPU used per RSS Max
    stress-ng: metrc: [379354] (secs) (secs) (secs) (real time) (usr+sys time) instance (%) (KB)
    stress-ng: metrc: [379354] io 9015 60.00 0.02 7.35 150.25 1223.66 2.05 3396
    stress-ng: metrc: [379354] pseek 12847931 60.00 50.60 105.33 214120.79 82392.79 64.97 4628
    stress-ng: metrc: [379354] miscellaneous metrics:
    stress-ng: metrc: [379354] pseek 1596.71 MB/sec write rate (harmonic mean of 4 instances)
    stress-ng: metrc: [379354] pseek 153.22 MB/sec read rate (harmonic mean of 4 instances)
    stress-ng: info: [379354] skipped: 0
    stress-ng: info: [379354] passed: 10: io (6) pseek (4)
    stress-ng: info: [379354] failed: 0
    stress-ng: info: [379354] metrics untrustworthy: 0
    stress-ng: info: [379354] successful run completed in 1 min

  • 赞(0)
    未经允许不得转载:网硕互联帮助中心 » stress-ng 服务器压力测试的工具学习
    分享到: 更多 (0)

    评论 抢沙发

    评论前必须登录!