Linux性能分析-平均负载
平均负载的理解
一般系统变慢时,我们会使用top或uptime命令来查看下系统的负载情况
[root@localhost shell]# uptime
13:51:08 up 5 days, 21:50, 3 users, load average: 0.00, 0.02, 0.05
load average:0.00,0.02,0.05 分别代表了1min/5min/15min的平均负载,那么平均负载到底是什么意思呢?
使用man uptime查看下详细的说明
man uptime
其中关于load average的解释如下:
System load averages is the average number of processes that are either in a runnable or uninterruptable state. A process in a runnable state is either using the CPU or waiting to use the CPU. A process in uninterruptable state is waiting for some I/O access, eg waiting for disk.
The averages are taken over the three time intervals. Load averages are not normalized for the number of CPUs in a system, so a load average of 1 means a single CPU system is loaded all the time while on a 4 CPU system it means it was idle 75% of the time.
可以看到,平均负载统计的是 处于runnable or uninterruptable状态的进程数量,并且这个数据需要和系统的cpu数量进行比较才有意义。
场景模拟
平均负载,计算的是进程对系统资源的需求程度,包括CPU和IO,所以平均负载高,CPU使用率不一定高。
下面模拟三种场景,这三种场景的平均负载都很高,但是分别对应的CPU密集型进程、IO密集型进程、大量等待CPU调度的进程组。
首先安装stress,stress是一个压力测试工具。
yum install -y epel-release
yum install -y stress
第一种:CPU密集型
用stress执行下面的命令,模拟占用一个核
stress --cpu 1 --timeout 600
在新开的终端中查看不同核的占用情况,5代表等待5秒,20代表一共打印20次数据
可以看到第三个核的CPU占用率是100%
[root@localhost shell]# mpstat -P ALL 5 20
Linux 3.10.0-1062.el7.x86_64 (localhost.localdomain) 2020年07月07日 _x86_64_(4 CPU)
14时11分49秒 CPU %usr %nice %sys %iowait %irq %soft %steal %guest %gnice %idle
14时11分54秒 all 25.29 0.00 0.05 0.00 0.00 0.00 0.00 0.00 0.00 74.66
14时11分54秒 0 0.60 0.00 0.20 0.00 0.00 0.00 0.00 0.00 0.00 99.20
14时11分54秒 1 14.00 0.00 0.20 0.00 0.00 0.00 0.00 0.00 0.00 85.80
14时11分54秒 2 0.20 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 99.80
14时11分54秒 3 86.23 0.00 0.20 0.00 0.00 0.00 0.00 0.00 0.00 13.57
14时11分54秒 CPU %usr %nice %sys %iowait %irq %soft %steal %guest %gnice %idle
14时11分59秒 all 25.23 0.00 0.05 0.00 0.00 0.00 0.00 0.00 0.00 74.72
14时11分59秒 0 0.20 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 99.80
14时11分59秒 1 0.20 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 99.80
14时11分59秒 2 0.40 0.00 0.20 0.00 0.00 0.00 0.00 0.00 0.00 99.40
14时11分59秒 3 100.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
在另一个终端中,打印进程对CPU的占用情。可以看到pid为6325的stress的进程占用cpu达到100%
[root@localhost shell]# pidstat -u 5 10
Linux 3.10.0-1062.el7.x86_64 (localhost.localdomain) 2020年07月07日 _x86_64_ (4 CPU)
14时13分11秒 UID PID %usr %system %guest %CPU CPU Command
14时13分16秒 0 1891 0.40 0.00 0.00 0.40 3 X
14时13分16秒 0 2581 0.60 0.20 0.00 0.79 3 gnome-shell
14时13分16秒 0 2604 0.00 0.20 0.00 0.20 0 ibus-daemon
14时13分16秒 0 2668 0.00 0.20 0.00 0.20 0 goa-identity-se
14时13分16秒 0 2847 0.20 0.00 0.00 0.20 3 vmtoolsd
14时13分16秒 0 6325 99.40 0.00 0.00 99.40 1 stress
14时13分16秒 0 6487 0.00 0.20 0.00 0.20 3 pidstat
14时13分16秒 UID PID %usr %system %guest %CPU CPU Command
14时13分21秒 0 1891 0.40 0.00 0.00 0.40 3 X
14时13分21秒 0 2581 0.80 0.00 0.00 0.80 3 gnome-shell
14时13分21秒 0 6325 100.00 0.00 0.00 100.00 1 stress
14时13分21秒 0 6487 0.20 0.20 0.00 0.40 3 pidstat
14时13分21秒 UID PID %usr %system %guest %CPU CPU Command
14时13分26秒 0 500 0.00 0.20 0.00 0.20 0 xfsaild/dm-0
14时13分26秒 0 1891 0.60 0.40 0.00 1.00 1 X
14时13分26秒 0 2581 1.00 0.40 0.00 1.40 1 gnome-shell
14时13分26秒 0 6206 0.20 0.20 0.00 0.40 1 gnome-terminal-
14时13分26秒 0 6325 100.00 0.00 0.00 100.00 2 stress
14时13分26秒 0 6487 0.00 0.20 0.00 0.20 3 pidstat
第二种IO密集型
安装stress-ng
yum install stress-ng
执行下面的命令,模拟IO密集
stress-ng -i 1 --hdd 1 --timeout 600
查看mpstat,可以看到iowait%明显提高
[root@localhost shell]# mpstat -P ALL 5 20
Linux 3.10.0-1062.el7.x86_64 (localhost.localdomain) 2020年07月07日 _x86_64_ (4 CPU)
14时30分20秒 CPU %usr %nice %sys %iowait %irq %soft %steal %guest %gnice %idle
14时30分25秒 all 0.81 0.00 12.68 37.67 0.00 1.83 0.00 0.00 0.00 47.02
14时30分25秒 0 0.22 0.00 15.08 32.59 0.00 1.11 0.00 0.00 0.00 51.00
14时30分25秒 1 1.65 0.00 22.63 37.65 0.00 0.41 0.00 0.00 0.00 37.65
14时30分25秒 2 0.88 0.00 8.10 43.98 0.00 3.06 0.00 0.00 0.00 43.98
14时30分25秒 3 0.00 0.00 4.75 36.29 0.00 2.81 0.00 0.00 0.00 56.16
查看哪个应用的IO占比较高,可以看到stress的应用,对磁盘的写入很大
[root@localhost shell]# pidstat -d 5 10 | grep "stress"
UID PID kB_rd/s kB_wr/s kB_ccwr/s Command
14时32分34秒 0 6730 0.00 549011.95 143466.14 stress-ng-hdd
14时32分34秒 0 6731 0.00 0.00 13406.37 stress-ng-io
第三种大量进程场景
执行下面命令,模拟16个进程执行
stress -c 16 --timeout 600
查看uptime,可以看到最近一分钟的平均负载显著升高
[root@localhost shell]# uptime
14:38:53 up 5 days, 22:38, 4 users, load average: 12.05, 5.38, 2.74
查看进程的cpu占用,可以看到stress的进程占用cpu为20左右,大量的stress进程在竞争cpu
[root@localhost shell]# pidstat -u 5 5
Linux 3.10.0-1062.el7.x86_64 (localhost.localdomain) 2020年07月07日 _x86_64_ (4 CPU)
14时38分26秒 UID PID %usr %system %guest %CPU CPU Command
14时38分31秒 0 1891 0.00 0.18 0.00 0.18 2 X
14时38分31秒 0 2581 0.18 0.18 0.00 0.37 1 gnome-shell
14时38分31秒 0 7225 23.29 0.00 0.00 23.29 3 stress
14时38分31秒 0 7226 23.48 0.00 0.00 23.48 0 stress
14时38分31秒 0 7227 23.11 0.00 0.00 23.11 3 stress
14时38分31秒 0 7228 23.29 0.00 0.00 23.29 0 stress
14时38分31秒 0 7229 23.29 0.00 0.00 23.29 3 stress
14时38分31秒 0 7230 23.11 0.00 0.00 23.11 2 stress
14时38分31秒 0 7231 23.11 0.00 0.00 23.11 1 stress
14时38分31秒 0 7232 23.11 0.00 0.00 23.11 0 stress
14时38分31秒 0 7233 23.29 0.00 0.00 23.29 1 stress
14时38分31秒 0 7234 23.11 0.00 0.00 23.11 2 stress
14时38分31秒 0 7235 23.29 0.00 0.00 23.29 1 stress
14时38分31秒 0 7236 23.48 0.00 0.00 23.48 2 stress
14时38分31秒 0 7237 23.29 0.00 0.00 23.29 0 stress
14时38分31秒 0 7238 23.29 0.00 0.00 23.29 3 stress
14时38分31秒 0 7239 23.11 0.00 0.00 23.11 1 stress
14时38分31秒 0 7240 22.92 0.00 0.00 22.92 2 stress
Linux性能分析-平均负载的更多相关文章
- Linux性能优化-平均负载
Linux性能优化-平均负载 目录 Linux性能优化-平均负载 平均负载的含义 平均负载为多少时合理 平均负载与 CPU 使用率 平均负载案例分析 场景一:CPU 密集型进程 场景二:I/O 密集型 ...
- Linux 性能分析工具汇总合集
出于对Linux操作系统的兴趣,以及对底层知识的强烈欲望,因此整理了这篇文章.本文也可以作为检验基础知识的指标,另外文章涵盖了一个系统的方方面面.如果没有完善的计算机系统知识,网络知识和操作系统知识, ...
- Linux性能分析的前60000毫秒【转】
Linux性能分析的前60000毫秒 为了解决性能问题,你登入了一台Linux服务器,在最开始的一分钟内需要查看什么? 在Netflix我们有一个庞大的EC2 Linux集群,还有非常多的性能分析工具 ...
- [转]Linux性能分析工具汇总合集
出于对Linux操作系统的兴趣,以及对底层知识的强烈欲望,因此整理了这篇文章.本文也可以作为检验基础知识的指标,另外文章涵盖了一个系统的方方面面.如果没有完善的计算机系统知识,网络知识和操作系统知识, ...
- 超全整理!Linux性能分析工具汇总合集
转自:http://rdc.hundsun.com/portal/article/731.html?ref=myread 出于对Linux操作系统的兴趣,以及对底层知识的强烈欲望,因此整理了这篇文章. ...
- (转)超全整理!Linux性能分析工具汇总合集
超全整理!Linux性能分析工具汇总合集 原文:http://rdc.hundsun.com/portal/article/731.html 出于对Linux操作系统的兴趣,以及对底层知识的强烈欲望, ...
- Linux性能分析——分析系统性能相关的命令
Linux性能分析——分析系统性能相关的命令 摘要:本文主要学习了Linux系统中分析性能相关的命令. ps命令 ps命令用来显示系统中进程的运行情况,显示的是当前系统的快照. 基本语法 ps [选项 ...
- Linux性能分析命令工具汇总
转自:http://rdc.hundsun.com/portal/article/731.html?ref=myread 出于对Linux操作系统的兴趣,以及对底层知识的强烈欲望,因此整理了这篇文章. ...
- Linux 性能分析 工具命令
背景知识:具备背景知识是分析性能问题时需要了解的.比如硬件 cache:再比如操作系统内核.应用程序的行为细节往往是和这些东西互相牵扯的,这些底层的东西会以意想不到的方式影响应用程序的性能,比如某些程 ...
- 查看Linux系统的平均负载
1.Linux系统的平均负载的概念 有时候我们会觉得系统响应很慢,但是又找不到原因,这时就要查看平均负载了,看它是否有大量的进程在排队等待.特定时间间隔内运行队列中的平均进程数可以反映系统的繁忙程度, ...
随机推荐
- # 个人认为windows下最好用的一批软件 #
个人认为windows下最好用的一批软件 chrome 为什么是chrome而不是edge2? 这当然不是因为我是谷歌吹什么的.其实当得知edge2比chrome更省内存,运行更快,而且不跨越城墙就能 ...
- Windows Server 2008R2服务器 IIS7.0 安装SSL证书并绑定https
本例以阿里云服务器来解说,本服务器为Winodws Server 2008 R2(一般现在至少是2012版本了)默认IIS为7.0 第一步: 在阿里云上申请好证书并下载IIS版本,下载后上传到服务器中 ...
- vue实现自定义音乐播放器
项目中遇到了,让实现一个音乐播放器的功能.修改其样式要求自定义,切需要有,进度条,时间,开关,应用于H5需要兼容ios与android.简单看一下如图播放器 完成代码 audioCom.vue < ...
- neo4j存储数据-图数据库
1. 简介 本文主要介绍neo4j是如何将图数据保存在磁盘上的,采用的是什么存储方式.分析这种存储方式对进行图查询/遍历的影响. 2. 图数据库简介 生产环境中使用的图数据库主要有2种,分别是带标签的 ...
- Golang-结构体6
http://c.biancheng.net/golang/struct/ Go语言结构体定义 Go语言可以通过自定义的方式形成新的类型,结构体就是这些类型中的一种复合类型,结构体是由零个或多个任意类 ...
- 项目PMP之五项目范围管理
项目PMP之五--项目范围管理 一.定义:确保项目做且只做所需的工作:范围包括产品范围(特性和功能)和项目范围(交付产品所需完成的工作) 适应型生命周期:相关方持续参与,应对大量变更(敏捷),实时 ...
- 使用_begin{thebibliography}__bibitem 如何参考文献
本人是tex新手,如果各位大佬有更好的方法欢迎分享,不胜感激. 适用情况 本文适用于使用\begin{thebibliography}和\bibitem排序的情况,如果使用bibtex排序那么网上很多 ...
- Java中的Scanner、BufferedReader 和 StreamTokenizer
1. Scanner 的使用与分析 简介: Scanner 是 Java 中一个用于解析原始类型(如 int.double 等)和字符串的类.它通常从输入流中逐个读取数据并进行解析,支持多种分隔符的使 ...
- 解读 DeepSeek-R1 论文 - 通俗易懂版
引言:让 AI 学会"思考"的新突破 在近年来的人工智能浪潮中,大型语言模型(LLM)如 ChatGPT 已经能回答各种问题,但它们在复杂推理方面仍有不足.所谓复杂推理,比如解决奥 ...
- 动手学深度学习-python基础知识介绍part1
基础详解-part1 import torch x=torch.arange(12) x x.shape x.numel() #数组中元素的总数 # 修改形状 x.reshape(3,4) torch ...