stress介紹
#stress
`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).
-? 顯示幫助信息
-v 顯示版本號
-q 不顯示運行信息
-n 顯示已完成的指令情況
-t --timeout N 指定運行N秒后停止
--backoff N 等待N微妙后開始運行
-c 產生n個進程 每個進程都反復不停的計算隨機數的平方根
-i 產生n個進程 每個進程反復調用sync(),sync()用於將內存上的內容寫到硬盤上
-m --vm n 產生n個進程,每個進程不斷調用內存分配malloc和內存釋放free函數
--vm-bytes B 指定malloc時內存的字節數 (默認256MB)
--vm-hang N 指定在free錢的秒數
-d --hadd n 產生n個執行write和unlink函數的進程
-hadd-bytes B 指定寫的字節數
--hadd-noclean 不unlink
時間單位可以為秒s,分m,小時h,天d,年y,文件大小單位可以為K,M,G
stress cpu 測試
stress測試cpu,是在用戶態將cpu 耗盡。
[root@jiangyi01.sqa.zmf /home/ahao.mah/ALIOS_QA/tools/stress-1.0.4]
#stress -c 1 -t 100
stress: info: [17223] dispatching hogs: 1 cpu, 0 io, 0 vm, 0 hdd
stress io 測試
使用stress測試IO,雖然可以創建任意數量的IO進程,但是,可以將 %sys 100%。因為,stress是通過循環執行sync(),使得內核態cpu 100%,但是,stress,沒有把w_await svctm 的比例打的很高。
[root@jiangyi01.sqa.zmf /home/ahao.mah/ALIOS_QA/tools/stress-1.0.4]
#stress --io 100 -t 100
stress: info: [130998] dispatching hogs: 0 cpu, 100 io, 0 vm, 0 hdd
[root@jiangyi01.sqa.zmf /home/ahao.mah/gotby/C/c4]
#ps axu | grep stress |grep -v grep | wc -l
101
stress mem測試
stress 測試內存的時候,--vm-bytes 1G --vm-hang 100 這里2個參數是關鍵!!!!
--vm-bytes 表示malloc分配多少內存
--vm-hang 表示malloc分配的內存多少時間后在free()釋放掉
--vm 指定進程數量
下面例子,就是說,10個進程,同時去malloc分配內存,並且保持100s后再釋放內存
[root@jiangyi01.sqa.zmf /home/ahao.mah/ALIOS_QA/tools/stress-1.0.4]
#stress --vm 10 --vm-bytes 1G --vm-hang 100 --timeout 100s
stress: info: [32286] dispatching hogs: 0 cpu, 0 io, 10 vm, 0 hdd
[root@jiangyi01.sqa.zmf /home/ahao.mah/ALIOS_QA/tools/stress-1.0.4]
#echo "63709272/1024/1024" |bc
60
[root@jiangyi01.sqa.zmf /home/ahao.mah/ALIOS_QA/tools/stress-1.0.4]
#stress --vm 30 --vm-bytes 1G --vm-hang 50 --timeout 50s
stress: info: [44047] dispatching hogs: 0 cpu, 0 io, 30 vm, 0 hdd
stress 磁盤IO測試
注意: 我是在/data 目錄,這個目錄掛載的是raid,總大小:17T
-d forks
--hdd forks 產生多個執行write()函數的進程
--hdd-bytes bytes 指定寫的Bytes數,默認是1GB
--hdd-noclean 不要將寫入隨機ASCII數據的文件Unlink
eg:stress -d 1 --hdd-bytes 3G
解釋:-d 1:一個寫進程。寫入固定大小通過mkstemp()函數寫入當前目錄;你也可以指定向磁盤中寫入固定大小的文件
這個文件通過調用mkstemp()產生並保存在當前目錄下,默認是文件產生后就被執行unlink(清除)操作,
但是你可以使用“--hdd-bytes”選項將產生的文件全部保存在當前目錄下,這會將你的磁盤空間逐步耗盡。
0
當只有一個進程在寫:
[root@jiangyi01.sqa.zmf /data]
#stress --hdd 1 --hdd-bytes 1024G
stress: info: [130229] dispatching hogs: 0 cpu, 0 io, 0 vm, 1 hdd
測試,提高進程數量為5:
[root@jiangyi01.sqa.zmf /data]
#stress --hdd 5 --hdd-bytes 1024G
stress: info: [26847] dispatching hogs: 0 cpu, 0 io, 0 vm, 5 hdd
[root@jiangyi01.sqa.zmf /data]
#stress --hdd 10 --hdd-bytes 1024G
stress: info: [31912] dispatching hogs: 0 cpu, 0 io, 0 vm, 10 hdd
[root@jiangyi01.sqa.zmf /home/ahao.mah]
#ps axu | grep stress | grep -v grep
root 31912 0.0 0.0 7264 652 pts/0 S+ 13:13 0:00 stress --hdd 10 --hdd-bytes 1024G
root 31913 13.9 0.0 8164 1120 pts/0 D+ 13:13 0:06 stress --hdd 10 --hdd-bytes 1024G
root 31914 14.5 0.0 8164 1120 pts/0 D+ 13:13 0:07 stress --hdd 10 --hdd-bytes 1024G
root 31915 14.5 0.0 8164 1120 pts/0 D+ 13:13 0:07 stress --hdd 10 --hdd-bytes 1024G
root 31916 14.1 0.0 8164 1120 pts/0 D+ 13:13 0:07 stress --hdd 10 --hdd-bytes 1024G
root 31917 13.9 0.0 8164 1120 pts/0 D+ 13:13 0:06 stress --hdd 10 --hdd-bytes 1024G
root 31918 14.0 0.0 8164 1120 pts/0 D+ 13:13 0:07 stress --hdd 10 --hdd-bytes 1024G
root 31919 13.8 0.0 8164 1120 pts/0 D+ 13:13 0:06 stress --hdd 10 --hdd-bytes 1024G
root 31920 13.9 0.0 8164 1120 pts/0 D+ 13:13 0:06 stress --hdd 10 --hdd-bytes 1024G
root 31921 13.9 0.0 8164 1120 pts/0 D+ 13:13 0:06 stress --hdd 10 --hdd-bytes 1024G
root 31922 14.0 0.0 8164 1120 pts/0 D+ 13:13 0:07 stress --hdd 10 --hdd-bytes 1024G
結論:
- 可見,--hdd 進程數量,並不是一個干擾因素,這個stress對寫磁盤的速度並沒有一個控制,直接用最大的壓力測試出瓶頸,當瓶頸到達了,進程多幾個也是沒有什么用,這個估計也是stress的不足之處。
- w_await 和svctm 基本一致,說明等待時間和服務時間基本相等。