使用 stress 命令對cpu進行壓力測試

1.安裝 stress

apt-get install stress

2.使用幫助

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

3.後臺運行 stress

stress --cpu 4 --io 4 --vm 2 --vm-bytes 128M --timeout 60s &

3.top 命令 查看cpu 使用率

在這裏插入圖片描述
0.0 id:表示0.0% 空閒,即cpu使用率 達100%。

4.uptime 命令查看cpu 負載
在這裏插入圖片描述
load average: 三個數值分別表示 最近 1 ,5,15 分鐘的負載平均值。正常三個值應該小於1。負載滿時大於cpu個數。有的機器上使用 top 命令也能看到這三個值、

理解CPU負載和 CPU使用率

CPU負載和 CPU使用率
這兩個從一定程度上都可以反映一臺機器的繁忙程度.

cpu使用率反映的是當前cpu的繁忙程度,忽高忽低的原因在於佔用cpu處理時間的進程可能處於io等待狀態但卻還未釋放進入wait。
平均負載(load average)是指某段時間內佔用cpu時間的進程和等待cpu時間的進程數,這裏等待cpu時間的進程是指等待被喚醒的進程,不包括處於wait狀態進程。

以上引用自 理解Linux CPU負載和 CPU使用率 - timer_go - 博客園

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章