給你的Linux系統上點stress【轉】
轉自:https://blog.csdn.net/sunvince/article/details/7187768
from: http://blog.yufeng.info/archives/2023
這本書介紹了非常多的除錯手段和工具, 其中提到了stress這個簡單的工具,在我們的日常工作中很有用。利用它可以給我們的系統施加CPU,記憶體,IO和磁碟的壓力,在模擬極端場景給應用系統造成的壓力方面很有幫助。
主頁見這裡:http://weather.ou.edu/~apw/projects/stress/
stress is a deliberately simple workload generator for POSIX systems. It imposes a configurable amount of CPU, memory, I/O, and disk stress on the system. It is written in C, and is free software licensed under the GPLv2.
這個stress實現非常的簡單,所有的功能在一個.c檔案裡面實現, 系統執行的時候會fork多個子程序,分別進行CPU,記憶體,IO方面的折磨。
因為簡單所以穩定。參考例子:
$ stress –cpu 2 –io 1 –vm 1 –vm-bytes 128M –timeout 10s –verbose
stress: info: [9372] dispatching hogs: 2 cpu, 1 io, 1 vm, 0 hdd
stress: dbug: [9372] (243) using backoff sleep of 12000us
stress: dbug: [9372] (262) setting timeout to 10s
stress: dbug: [9372] (285) –> hogcpu worker 9373 forked
stress: dbug: [9372] (305) –> hogio worker 9374 forked
stress: dbug: [9372] (325) –> hogvm worker 9375 forked
stress: dbug: [9372] (243) using backoff sleep of 3000us
stress: dbug: [9372] (262) setting timeout to 10s
stress: dbug: [9372] (285) –> hogcpu worker 9376 forked
stress: dbug: [9375] (466) hogvm worker malloced 134217728 bytes
stress: dbug: [9372] (382) <-- worker 9374 signalled normally
stress: dbug: [9372] (382) <-- worker 9373 signalled normally
stress: dbug: [9372] (382) <-- worker 9375 signalled normally
stress: dbug: [9372] (382) <-- worker 9376 signalled normally
stress: info: [9372] successful run completed in 10s
由於stress支援posix平臺,簡單的下載,編譯和安裝就好了, 很順利!
按照文件預設的執行引數,讓系統來點體驗:
$stress --cpu 8 --io 4 --vm 2 --vm-bytes 128M --timeout 10d |
stress: info: [23176] dispatching hogs: 8 cpu, 4 io, 2 vm, 0 hdd |
具體使用可以參考man stress!