内存压力测试:
-
uptime 命令介绍
uptime 命令告诉你系统启动up了(运行了)多长时间
uptime会在一行中显示下列信息:当前时间、系统运行了多久时间、当前登录的用户有多少,以及前 1、5 和 15 分钟系统的平均负载。
$ uptime
20:23:35 up 4 days, 5:20, 2 users, load average: 0.30, 0.14, 0.04
你也可以指定 uptme 显示系统开始运行的时间和日期。方法是使用 -s 命令项。
uptime -s
$ uptime -s
2021-01-11 15:03:13
-V 获取版本信息,-h 获取帮助信息。
$ uptime -V
uptime from procps-ng 3.3.10
$ uptime -h
Usage:
uptime [options]
Options:
-p, --pretty show uptime in pretty format
-h, --help display this help and exit
-s, --since system up since
-V, --version output version information and exit
For more details see uptime(1).
# watch uptime
每隔2秒显示
-
stress
sudo yum install stress
sudo apt-get install stress
stress [OPTION]
## Stress using CPU-bound task
stress -c 4
## Stress using IO-bound task
stress -i 2
$ stress -c 12
stress: info: [19484] dispatching hogs: 12 cpu, 0 io, 0 vm, 0 hdd
$ uptime
20:58:45 up 4 days, 5:55, 3 users, load average: 12.43, 8.41, 3.81
# top, 1 enter
# stress -c 2 -i 1 -m 1 --vm-bytes 128M -t 10s
- -c 2 : Spawn two workers spinning on sqrt()
- -i 1 : Spawn one worker spinning on sync()
- -m 1 : Spawn one worker spinning on malloc()/free()
- --vm-bytes 128M : Malloc 128MB per vm worker (default is 256MB)
- -t 10s : Timeout after ten seconds
- -v : Be verbose
$ stress -c 2 -i 1 -m 1 --vm-bytes 128M -t 10s
stress: info: [13958] dispatching hogs: 2 cpu, 1 io, 1 vm, 0 hdd
stress: info: [13958] successful run completed in 10s
stress -m N
会让stress生成N个工作进程来占用内存。每个进程默认占用256M内存,但可以通过 --vm-bytes
来进行设置