Stress安装
CentOS 7
# 启用三方源
$ rpm -ivh http://apt.sw.be/redhat/el7/en/x86_64/rpmforge/RPMS/rpmforge-release-0.5.3-1.el7.rf.x86_64.rpm
# 安装Stress
$ yum install stress
CentOS 6
# 启用三方源
$ yum install epel-release
# 安装Stress
$ yum install stress
Stress参数说明
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 is 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)
--hdd-noclean do not unlink files created by hdd workers
Example: stress --cpu 8 --io 4 --vm 2 --vm-bytes 128M --timeout 10s
-? 显示帮助信息
-v 显示版本号
-q 不显示运行信息
-n,--dry-run 显示已经完成的指令执行情况
-t --timeout N 指定运行N秒后停止
--backoff N 等待N微妙后开始运行
-c --cpu 产生n个进程 每个进程都反复不停的计算随机数的平方根
-i --io 产生n个进程 每个进程反复调用sync(),sync()用于将内存上的内容写到硬盘上
-m --vm n 产生n个进程,每个进程不断调用内存分配malloc和内存释放free函数
--vm-bytes B 指定malloc时内存的字节数 (默认256MB)
--vm-hang N 指示每个消耗内存的进程在分配到内存后转入休眠状态,与正常的无限分配和释放内存的处理相反,这有利于模拟只有少量内存的机器
-d --hadd n 产生n个执行write和unlink函数的进程
--hadd-bytes B 指定写的字节数,默认是1GB
--hadd-noclean 不要将写入随机ASCII数据的文件Unlink
时间单位可以为秒s,分m,小时h,天d,年y,文件大小单位可以为K,M,G
Stress使用实例
$ stress -c 13 -i 4 --verbose --timeout 1m
$ stress --cpu 3 --io 3 --vm 2 --vm-bytes 10000000 --vm-keep --verbose
$ stress -d 1 --hdd-noclean --hdd-bytes 800k
$ stress -c 13
$ stress --quiet --cpu 1k
$ stress -i 4
# 生成小文件
$ stress -d 1 --hdd-noclean --hdd-bytes 13
# 生成大文件
$ stress -d 1 --hdd-noclean --hdd-bytes 3G