一,安装stress:

说明:el8的源里面还没有,先用el7的rpm包

[root@centos8 source]# wget https://download-ib01.fedoraproject.org/pub/epel/7/x86_64/Packages/s/stress-1.0.4-16.el7.x86_64.rpm
[root@centos8 source]# rpm -ivh stress-1.0.4-16.el7.x86_64.rpm

说明:刘宏缔的架构森林是一个专注架构的博客,地址:https://www.cnblogs.com/architectforest

对应的源码可以访问这里获取: https://github.com/liuhongdi/

说明:作者:刘宏缔 邮箱: 371125307@qq.com

二,stress的用途:

stress 命令主要用来模拟系统负载较高时的场景,

可以对cpu、memory、IO以及磁盘进行压力测试

三,查看stress的版本和帮助

1,查看版本

[root@centos8 source]# stress --version
stress 1.0.4

2,查看帮助:

[root@centos8 source]# 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 Note: Numbers may be suffixed with s,m,h,d,y (time) or B,K,M,G (size)

四,stress命令的参数说明:

-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

-t, --timeout N    持续指定的N秒后退出

五,stress的使用例子:cpu

1,在容器内执行stress,创建四个消耗 CPU 资源的进程

[root@centos8 ~]# stress -c 4 --timeout 600
stress: info: [3868] dispatching hogs: 4 cpu, 0 io, 0 vm, 0 hdd

2,用pidstat查看cpu的使用数据

# 显示所有CPU的指标,并在间隔5秒输出一组数据

[root@centos8 ~]# pidstat -p ALL 5
平均时间: UID PID %usr %system %guest %wait %CPU CPU Command
平均时间: 0 3869 48.76 0.00 0.00 50.65 48.76 - stress
平均时间: 0 3870 46.87 0.10 0.00 52.54 46.97 - stress
平均时间: 0 3871 47.36 0.00 0.00 51.84 47.36 - stress
平均时间: 0 3872 48.16 0.00 0.00 51.44 48.16 - stress

说明:可以明显看到,stress 进程的 CPU 使用率很高

六,stress的使用例子:内存

1,启动2个消耗内存的进程,每个进程占用200M内存

[root@centos8 ~]# stress -m 2 --vm-bytes 200M
stress: info: [4364] dispatching hogs: 0 cpu, 0 io, 2 vm, 0 hdd

2,用pidstat 查看内存的占用情况

[root@centos8 ~]# pidstat -r | grep stress
13时32分48秒 UID PID minflt/s majflt/s VSZ RSS %MEM Command
13时33分38秒 0 4364 0.04 0.00 7948 1044 0.03 stress
13时33分38秒 0 4365 8748.16 0.00 212752 56072 1.46 stress
13时33分38秒 0 4366 9156.42 0.00 212752 91712 2.38 stress

七,stress的使用例子:硬盘

1, stress -d N 会产生N个进程:

每个进程往当前目录中写入固定大小的临时文件,然后执行unlink操作删除该临时文件。

临时文件的大小默认为1G,但可以通过 --hdd-bytes 设置临时文件的大小。

[root@centos8 ~]# stress -d 2
stress: info: [4523] dispatching hogs: 0 cpu, 0 io, 0 vm, 2 hdd

2,用pidstat监控磁盘,可以看到两个stress进程在做大量的写入

[root@centos8 ~]# pidstat -d
Linux 4.18.0-147.5.1.el8_1.x86_64 (centos8) 2020年04月03日 _x86_64_ (2 CPU)

13时43分47秒 UID PID kB_rd/s kB_wr/s kB_ccwr/s iodelay Command
13时43分47秒 0 4524 0.00 166.98 0.00 0 stress
13时43分47秒 0 4525 0.00 165.31 0.00 0 stress

3,用iostat查看,也可以看到 kB_wrtn/s 的数值增长

[root@centos8 ~]# iostat
Linux 4.18.0-147.5.1.el8_1.x86_64 (centos8) 2020年04月03日 _x86_64_ (2 CPU) avg-cpu: %user %nice %system %iowait %steal %idle
6.40 0.02 3.14 1.25 0.00 89.19 Device tps kB_read/s kB_wrtn/s kB_read kB_wrtn
sda 11.34 273.05 5296.74 863387 16748451
scd0 0.01 0.34 0.00 1060 0
dm-0 11.14 252.57 5296.85 798627 16748789
dm-1 0.17 0.75 0.51 2376 1616
dm-2 0.24 7.82 1.71 24714 5422

八,stress的使用例子:io

1,使用4个进程生成大量io, 即执行:sync()操作

[root@centos8 source]# stress -i 4

2,使用top可以看到stress的4个进程占用了大量的cpu资源

[root@centos8 conf]# top
...
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
9143 root 20 0 7948 96 0 R 54.5 0.0 0:20.52 stress
9142 root 20 0 7948 96 0 R 53.8 0.0 0:20.88 stress
9141 root 20 0 7948 96 0 R 52.5 0.0 0:20.31 stress
9144 root 20 0 7948 96 0 R 52.2 0.0 0:20.65 stress

3,用pidstat查看进程,能看到stress的4个进程产生的大量的wait类的cpu使用

pidstat参数:间隔5秒后输出一组数据,-u表示CPU指标

[root@centos8 conf]# pidstat -u 5 1
Linux 4.18.0-147.5.1.el8_1.x86_64 (centos8) 2020年04月01日 _x86_64_ (2 CPU) 15时36分37秒 UID PID %usr %system %guest %wait %CPU CPU Command
15时36分42秒 0 1064 0.20 0.00 0.00 6.72 0.20 1 vmtoolsd
15时36分42秒 1000 2704 1.19 0.00 0.00 0.99 1.19 0 gnome-shell
15时36分42秒 0 2889 0.20 0.00 0.00 0.20 0.20 0 sssd_kcm
15时36分42秒 1000 3279 0.20 0.00 0.00 1.98 0.20 0 gnome-terminal-
15时36分42秒 0 8992 0.00 0.20 0.00 2.57 0.20 0 kworker/0:0-events
15时36分42秒 0 9033 0.59 48.81 0.00 50.59 49.41 0 stress
15时36分42秒 0 9034 0.59 48.42 0.00 50.00 49.01 1 stress
15时36分42秒 0 9035 0.59 48.02 0.00 50.59 48.62 0 stress
15时36分42秒 0 9036 0.59 48.62 0.00 50.20 49.21 1 stress
15时36分42秒 0 9074 0.20 0.40 0.00 0.99 0.59 0 pidstat 平均时间: UID PID %usr %system %guest %wait %CPU CPU Command
平均时间: 0 1064 0.20 0.00 0.00 6.72 0.20 - vmtoolsd
平均时间: 1000 2704 1.19 0.00 0.00 0.99 1.19 - gnome-shell
平均时间: 0 2889 0.20 0.00 0.00 0.20 0.20 - sssd_kcm
平均时间: 1000 3279 0.20 0.00 0.00 1.98 0.20 - gnome-terminal-
平均时间: 0 8992 0.00 0.20 0.00 2.57 0.20 - kworker/0:0-events
平均时间: 0 9033 0.59 48.81 0.00 50.59 49.41 - stress
平均时间: 0 9034 0.59 48.42 0.00 50.00 49.01 - stress
平均时间: 0 9035 0.59 48.02 0.00 50.59 48.62 - stress
平均时间: 0 9036 0.59 48.62 0.00 50.20 49.21 - stress
平均时间: 0 9074 0.20 0.40 0.00 0.99 0.59 - pidstat

可以看到stress占用了cpu大量的wait类时间

九,查看centos的版本

[root@centos8 ~]# cat /etc/redhat-release
CentOS Linux release 8.1.1911 (Core)

centos8平台使用stress做压力测试的更多相关文章

  1. centos8平台使用ab做压力测试

    一,安装ab [root@blog ~]# yum install httpd-tools 说明:刘宏缔的架构森林是一个专注架构的博客,地址:https://www.cnblogs.com/archi ...

  2. Webbench、ab命令:做压力测试的工具和性能的监控工具

    DDOS攻击:???DDOS概述:分布式拒绝服务(DDoS:Distributed Denial of Service)攻击,指借助于客户/服务器技术,将多个计算机联合起来作为攻击平台,对一个或多个目 ...

  3. (转)学习使用Jmeter做压力测试(三)--数据库测试

    数据库测试 JMeter可以做为Web服务器与浏览器之间的代理网关,以捕获浏览器的请求和Web服务器的响应,这样就可很容易的生成性能测试脚本. 根据脚本,JMeter可通过线程组来模拟真实用户对Web ...

  4. 使用JMeter做压力测试

    使用JMeter做压力测试 1.下载Jmeter 地址:http://jmeter.apache.org/download_jmeter.cgi 2.启动jmeter 运行bin/jmeter.bat ...

  5. jmeter教程--简单的做压力测试

    Jmeter是一个非常好用的压力测试工具.  Jmeter用来做轻量级的压力测试,非常合适,只需要十几分钟,就能把压力测试需要的脚本写好. 什么是压力测试 顾名思义:压力测试,就是  被测试的系统,在 ...

  6. Linux学习13-CentOS安装ab做压力测试

    前言 网站性能压力测试是服务器网站性能调优过程中必不可缺少的一,测试环境准备好了后,如何对网站做压力测试? 压力测试的工具很多,如:ab.http_load.webbench.siege.jmeter ...

  7. 使用Application Center Test (ACT)来做压力测试 【转】

    在我们完成了基于SPS2003的开发,实现了我们的具体应用以后,我们是不是就可以直接请用户来使用了呢?如果我这么做,那么有经验的开发人员一定会对此嗤之以鼻:居然连压力测试也不做!真是不想活了…… 呵呵 ...

  8. 在linux中给你的应用做压力测试

    在linux中给你的应用做压力测试 作者: 立地 邮箱: jarvin_g@126.com QQ: 511363759 一.webbench 1.在Ubuntu中安装webbench —支持get,h ...

  9. loadrunner之做压力测试要做的准备

    前提B/S架构 1.要有个备库和主库保存一致 到时候做压力测试的时候,要断开主库连接到备库.进行测试.以免主库出现垃圾数据.2.节点 判断单节点能承受多大的压力,如200万的用户账号,10万的在线用户 ...

随机推荐

  1. 【源码讲解】Spring事务是如何应用到你的业务场景中的?

    初衷 日常开发中经常用到@Transaction注解,那你知道它是怎么应用到你的业务代码中的吗?本篇文章将从以下两个方面阐述Spring事务实现原理: 解析并加载事务配置:本质上是解析xml文件将标签 ...

  2. 吴恩达《深度学习》-课后测验-第三门课 结构化机器学习项目(Structuring Machine Learning Projects)-Week1 Bird recognition in the city of Peacetopia (case study)( 和平之城中的鸟类识别(案例研究))

    Week1 Bird recognition in the city of Peacetopia (case study)( 和平之城中的鸟类识别(案例研究)) 1.Problem Statement ...

  3. openstack核心组件——glance— 镜像服务(6)

    云计算openstack核心组件——glance— 镜像服务(6)   一.glance介绍:              Glance是Openstack项目中负责镜像管理的模块,其功能包括虚拟机镜像 ...

  4. 面试题总结:可能是全网最好的MySQL重要知识点

    标题有点标题党的意思,但希望你在看了文章之后不会有这个想法--这篇文章是作者对之前总结的 MySQL 知识点做了完善后的产物,可以用来回顾MySQL基础知识以及备战MySQL常见面试问题. 什么是My ...

  5. 并发编程(六)Object类中线程相关的方法详解

    一.notify() 作用:唤醒一个正在等待该线程的锁的线程 PS : 唤醒的线程不会立即执行,它会与其他线程一起,争夺资源 /** * Object类的notify()和notifyAll()方法详 ...

  6. 搜索引擎学习(三)Lucene查询索引

    一.查询理论 创建查询:构建一个包含了文档域和语汇单元的文档查询对象.(例:fileName:lucene) 查询过程:根据查询对象的条件,在索引中找出相应的term,然后根据term找到对应的文档i ...

  7. python的全局函数

    1.Python的全局函数 import builtins dir(builtins)  abs  # 返回参数的绝对值 可以写成函数:def absnum): if num >=0: retu ...

  8. 2020 CiGA Game Jam活动总结

    CiGA Game Jam 总结 今年8月14.15.16号,48小时游戏开发--Game Jam开始了.蠢新第一次参加Game Jam,今年还是线上开展,情绪复杂= = 还有一个坏消息,晓航旅游缺席 ...

  9. .NETCore在析构函数(Finalize)在Linux下引起程序异常退出现象

    目       录 1.      现象概述... 1 2.      操作数据库的代码... 2 3.      引起的异常... 2 4.      异常信息分析... 3 5.      分析结 ...

  10. Linux MMC 驱动子系统简述(源码剖析)

    1. Linux MMC 驱动子系统 块设备是Linux系统中的基础外设之一,而 MMC/SD 存储设备是一种典型的块设备.Linux内核设计了 MMC子系统,用于管理 MMC/SD 设备. MMC ...