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系统的平均负载的概念 有时候我们会觉得系统响应很慢,但是又找不到原因,这时就要查看平均负载了,看它是否有大量的进程在排队等待.特定时间间隔内运行队列中的平均进程数可以反映系统的繁忙程度, ...
随机推荐
- 异步 QQ 机器人框架_NoneBot
一.NoneBot使用 1) #监控发送的消息"群发"的事件@on_command('send_msg', aliases=('群发',))async def send_msg(s ...
- [软件工具使用记录] windows离线ollama部署本地模型并配置continue实现离线代码补全
qwen2.5coder发布之后,觉得差不多可以实现离线模型辅助编程了,所以尝试在公司内网部署模型,配合vsocde插件continue实现代码提示.聊天功能. 目前使用qwen2.5coder的32 ...
- Solution Set -「LOCAL」冲刺省选 Round X
\(\mathscr{Summary}\) 时间利用效率? 同学,你的效率呢? 我真不知道中途几个小时干了啥,我也不知道我实在划水.神游还是真的在自闭想题. 虽然真实考场肾上腺素不会允 ...
- 使用Emgu.CV开发视频播放器简述
OpenCV是大名鼎鼎的视觉处理库,其对应的c#版本为Emgu.CV.本人采用Emgu.CV开发了一款视频播放软件,可对本地视频文件和rstp在线视频流播放,还具有对视频局部区域放大功能.虽然功能比较 ...
- 加速 AI 训推:Lepton AI 如何构建多租户、低延迟云存储平台
Lepton AI 是一款面向开发者的 AI 平台,旨在提供易用.高效且可扩展的基础设施能力.该平台适用于各种训练.推理需求,GPU充足,在保证高性能的同时,能够灵活应对不断变化的工作负载.用户可以快 ...
- VAE模型简析和精要(原理和代码)
1. 前言 这篇博客主要用于记录VAE的原理部分. 一方面便于日后自己的温故学习,另一方面也便于大家的学习和交流. 如有不对之处,欢迎评论区指出错误,你我共同进步学习! 图均引用自4部分的博客!!!! ...
- [ARC 188A] ABC Symmetry
solution by XiangXunYi 思路推导 step 1 首先题目中操作二同时删掉 A,B,C 的条件相当于同时将三者数量减一,操作一删掉两个相同字符等同于将某一字符的数量减二,那么我们可 ...
- NPOI与excelcnv.exe
在使用NPOI解析一些比较古老的仪器生成的excel文件时,经常会这个错误:The supplied spreadsheet seems to be Excel 5.0/7.0 (BIFF5) for ...
- Kali 安装并配置 Nessus
Kali 安装并配置 Nessus 安装 Nessus 创建nessus文件夹 sudo mkdir /opt/nessus 下载 Nessus ( https://www.tenable.com/d ...
- 分合之道:最小生成树的 Kruskal 与 Prim 算法
最小生成树问题 想象你是一位城市规划师,面前摊开一张地图,标记着散落的村庄.你的任务是用最经济的成本,在村庄间铺设道路,让所有村庄互通.这个问题看似简单,却隐藏着一个经典的数学命题:如何在一张&quo ...