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>
內存測試
新增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>
磁盤I/O測試
輸入命令:stress -d 1 –hdd-bytes 3G
新增1個寫進程,每次寫3G文件塊
硬盤測試(不刪除)這個要謹慎測試
輸入命令: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基本都差不多,簡單列舉下
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>