Linux macOS系统 压力测试工具stress

Linux和macOS系统都支持在线安装。下面拿macOS做个举例

<code>➜  brew search stress
==> Formulae
stress                                    stress-ng
➜  brew install stress
Updating Homebrew...
==> Downloading https://homebrew.bintray.com/bottles/stress-1.0.4.catalina.bottle.t
######################################################################## 100.0%
==> Pouring stress-1.0.4.catalina.bottle.tar.gz
  /usr/local/Cellar/stress/1.0.4: 11 files, 76.9KB
安装完成之后可以直接help
➜  stress --help
`stress' imposes certain types of compute stress on your system
Usage: stress [OPTION [ARG]] ...
 -?, --help         show this help statement
     --version      show version statement
 -v, --verbose      be verbose
 -q, --quiet        be quiet
 -n, --dry-run      show what would have been done
 -t, --timeout N    timeout after N seconds
     --backoff N    wait factor of N microseconds before work starts
 -c, --cpu N        spawn N workers spinning on sqrt()
 -i, --io N         spawn N workers spinning on sync()
 -m, --vm N         spawn N workers spinning on malloc()/free()
     --vm-bytes B   malloc B bytes per vm worker (default is 256MB)
     --vm-stride B  touch a byte every B bytes (default is 4096)
     --vm-hang N    sleep N secs before free (default none, 0 is inf)
     --vm-keep      redirty memory instead of freeing and reallocating
 -d, --hdd N        spawn N workers spinning on write()/unlink()
     --hdd-bytes B  write B bytes per hdd worker (default is 1GB)

Example: stress --cpu 8 --io 4 --vm 2 --vm-bytes 128M --timeout 10s
Note: Numbers may be suffixed with s,m,h,d,y (time) or B,K,M,G (size)./<code>

安装之后简单测试如下

测试CPU负荷

<code>stress -c 4 -t 10
stress: info: [37897] dispatching hogs: 4 cpu, 0 io, 0 vm, 0 hdd
stress: info: [37897] successful run completed in 10s/<code>


Linux  macOS系统 压力测试工具stress

内存测试

新增4个io进程,10个内存分配进程,每次分配大小1G,分配后不释放,测试100S

<code>stress -i 4 --vm 10 --vm-bytes 1G --vm-hang 100 --timeout 100s
stress: info: [38110] dispatching hogs: 0 cpu, 4 io, 10 vm, 0 hdd
stress: info: [38110] successful run completed in 101s/<code>


Linux  macOS系统 压力测试工具stress

磁盘I/O测试

输入命令:stress -d 1 –hdd-bytes 3G

新增1个写进程,每次写3G文件块


Linux  macOS系统 压力测试工具stress

硬盘测试(不删除)这个要谨慎测试

输入命令:stress -i 1 -d 10 –hdd-bytes 3G -hdd-noclean

新增1个IO进程,10个写进程,每次写入3G文件块,且不清除,会逐步将硬盘耗尽

<code>➜  ~ brew search stress
==> Formulae
stress ✔                                  stress-ng/<code>

这里可以看到还有一个stress-ng基本都差不多,简单列举下

  1. To run 8 CPU stressors with a timeout of 60 seconds and a summary at the end of operations.

<code>sudo stress-ng --cpu 8 --timeout 60 --metrics-brief
sudo stress-ng --cpu 8 --timeout 60 --metrics-brief/<code>

2. To run 4 FFT CPU stressors with a timeout of 2 minutes.

<code>sudo stress-ng --cpu 4 --cpu-method fft --timeout 2m/<code>

3. To run 5 hdd stressors and stop after 100000 bogo operations, run this command.

<code>sudo stress-ng --hdd 5 --hdd-ops 100000/<code>

4. To run 8 CPU stressors, 4 I/O stressors and 1 virtual memory stressor using 1GB of virtual memory for one minute, run this command below.

<code>sudo stress-ng --cpu 4 --io 4 --vm 1 --vm-bytes 1G --timeout 60s --metrics-brief/<code>


分享到:


相關文章: