转自:
from:
这本书介绍了非常多的调试手段和工具, 其中提到了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 hddstress: dbug: [9372] (243) using backoff sleep of 12000usstress: dbug: [9372] (262) setting timeout to 10sstress: dbug: [9372] (285) –> hogcpu worker 9373 forkedstress: dbug: [9372] (305) –> hogio worker 9374 forkedstress: dbug: [9372] (325) –> hogvm worker 9375 forkedstress: dbug: [9372] (243) using backoff sleep of 3000usstress: dbug: [9372] (262) setting timeout to 10sstress: dbug: [9372] (285) –> hogcpu worker 9376 forkedstress: dbug: [9375] (466) hogvm worker malloced 134217728 bytesstress: dbug: [9372] (382) <-- worker 9374 signalled normallystress: dbug: [9372] (382) <-- worker 9373 signalled normallystress: dbug: [9372] (382) <-- worker 9375 signalled normallystress: dbug: [9372] (382) <-- worker 9376 signalled normallystress: 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 |
pstree可以看到:
nmon可以看到:
具体使用可以参考man stress!