环境搭建

使用docker快速搭建环境.

dockerhub地址:https://hub.docker.com/r/joedval/stress

拉取镜像

# docker pull joedval/stress

# Examples:

Stress only on the first core: docker run -it --rm --cpuset=0 stress --cpu 1

Stress only on the first two cores: docker run -it --rm --cpuset=0,1 stress --cpu 2

Stress Memory to the same capacity allowed with swap docker run -it --rm -m 128m stress --vm 1 --vm-bytes 256M --vm-hang 0

工具使用

# 进入容器

docker exec -it container-id bash

# 查看官方提供的参数说明文档

[root@95c62b1e1ee2 /]# 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 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

Note: Numbers may be suffixed with s,m,h,d,y (time) or B,K,M,G (size).

中文释义:

-? 显示帮助信息

-v 显示版本号

-q 不显示运行信息

-n 显示已完成的指令情况

-t --timeout N 指定运行N秒后停止

--backoff N 等待N微妙后开始运行

-c 产生n个进程 每个进程都反复不停的计算随机数的平方根

-i 产生n个进程 每个进程反复调用sync(),sync()用于将内存上的内容写到硬盘上

-m --vm n 产生n个进程,每个进程不断调用内存分配malloc和内存释放free函数

--vm-bytes B 指定malloc时内存的字节数 (默认256MB)

--vm-hang N 指定在free前的秒数

-d --hadd n 产生n个执行write和unlink函数的进程

-hadd-bytes B 指定写的字节数

--hadd-noclean 不unlink

时间单位可以为秒s,分m,小时h,天d,年y,文件大小单位可以为K,M,G

启动容器

# 使用两个cpu

docker run -it --rm joedval/stress --cpu 2

查看机器状态

查看容器运行状态 查看计算机CPU使用率 可以看出两个cpu使用率一直都接近100%,目标已经达成。

精彩文章

评论可见,请评论后查看内容,谢谢!!!评论后请刷新页面。