使用 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状态进程。

扫描二维码关注公众号,回复: 10211196 查看本文章

以上引用自 理解Linux CPU负载和 CPU使用率 - timer_go - 博客园

发布了63 篇原创文章 · 获赞 20 · 访问量 7万+

猜你喜欢

转载自blog.csdn.net/agave7/article/details/91387859