给你的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

pstree可以看到:

nmon可以看到:

具体使用可以参考man stress!

posted @ 2018-11-12 17:05  Sky&Zhang  阅读(430)  评论(0编辑  收藏  举报