平均负载的理解

一般系统变慢时,我们会使用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性能分析-平均负载的更多相关文章

  1. Linux性能优化-平均负载

    Linux性能优化-平均负载 目录 Linux性能优化-平均负载 平均负载的含义 平均负载为多少时合理 平均负载与 CPU 使用率 平均负载案例分析 场景一:CPU 密集型进程 场景二:I/O 密集型 ...

  2. Linux 性能分析工具汇总合集

    出于对Linux操作系统的兴趣,以及对底层知识的强烈欲望,因此整理了这篇文章.本文也可以作为检验基础知识的指标,另外文章涵盖了一个系统的方方面面.如果没有完善的计算机系统知识,网络知识和操作系统知识, ...

  3. Linux性能分析的前60000毫秒【转】

    Linux性能分析的前60000毫秒 为了解决性能问题,你登入了一台Linux服务器,在最开始的一分钟内需要查看什么? 在Netflix我们有一个庞大的EC2 Linux集群,还有非常多的性能分析工具 ...

  4. [转]Linux性能分析工具汇总合集

    出于对Linux操作系统的兴趣,以及对底层知识的强烈欲望,因此整理了这篇文章.本文也可以作为检验基础知识的指标,另外文章涵盖了一个系统的方方面面.如果没有完善的计算机系统知识,网络知识和操作系统知识, ...

  5. 超全整理!Linux性能分析工具汇总合集

    转自:http://rdc.hundsun.com/portal/article/731.html?ref=myread 出于对Linux操作系统的兴趣,以及对底层知识的强烈欲望,因此整理了这篇文章. ...

  6. (转)超全整理!Linux性能分析工具汇总合集

    超全整理!Linux性能分析工具汇总合集 原文:http://rdc.hundsun.com/portal/article/731.html 出于对Linux操作系统的兴趣,以及对底层知识的强烈欲望, ...

  7. Linux性能分析——分析系统性能相关的命令

    Linux性能分析——分析系统性能相关的命令 摘要:本文主要学习了Linux系统中分析性能相关的命令. ps命令 ps命令用来显示系统中进程的运行情况,显示的是当前系统的快照. 基本语法 ps [选项 ...

  8. Linux性能分析命令工具汇总

    转自:http://rdc.hundsun.com/portal/article/731.html?ref=myread 出于对Linux操作系统的兴趣,以及对底层知识的强烈欲望,因此整理了这篇文章. ...

  9. Linux 性能分析 工具命令

    背景知识:具备背景知识是分析性能问题时需要了解的.比如硬件 cache:再比如操作系统内核.应用程序的行为细节往往是和这些东西互相牵扯的,这些底层的东西会以意想不到的方式影响应用程序的性能,比如某些程 ...

  10. 查看Linux系统的平均负载

    1.Linux系统的平均负载的概念 有时候我们会觉得系统响应很慢,但是又找不到原因,这时就要查看平均负载了,看它是否有大量的进程在排队等待.特定时间间隔内运行队列中的平均进程数可以反映系统的繁忙程度, ...

随机推荐

  1. WSL设置中文、修改默认Root登陆、添加右键菜单

    1.设置中文 首先安装 aptitude 管理工具 #apt-get install aptitude 然后安装语言环境并进入语言环境设置. #aptitude install locales #dp ...

  2. Cursor 收费太贵?3分钟教你接入超低价 DeepSeek-V3,代码质量逼近 Claude 3.5

    DeepSeek-V3 实在是太便宜了,就跟不要钱似的:每百万输入 tokens 0.1 元 (缓存命中)/ 1 元 (缓存未命中),每百万输出 tokens 2 元 跟其他模型相比,DeepSeek ...

  3. nginx平台初探-3

    过滤模块简介 (90%) 执行时间和内容 (90%) 过滤(filter)模块是过滤响应头和内容的模块,可以对回复的头和内容进行处理.它的处理时间在获取回复内容之后,向用户发送响应之前.它的处理过程分 ...

  4. Cuckoo Hash

    最近在看APSI中,涉及到了一些hash技术(朴素hash,置换hash,布谷鸟hash),Hash 技术是 PSI 协议中优化通信复杂度和计算杂度的重要工具之一,现在系统的认识一下! 更多关于哈希函 ...

  5. 2025春秋杯DAY2DAY3部分wp

    2025春秋杯DAY2DAY3部分wp DAY2 WEB easy_ser 源码如下 <?php //error_reporting(0); function PassWAF1($data){ ...

  6. 魔乐开发者社区正式上线,AI开发者快来撩!

    近日,由天翼云与华为联合打造的魔乐(Modelers)开发者社区,在天翼云中国行·贵州站活动现场上线发布.依托全场景开源模型资源.易用的模型开发套件,以及强大的共建共享生态系统等优势,社区将使能开发者 ...

  7. 首个“全4K”运动会,上云!

    采用"全4K"超高清制作标准的世-界级赛事--成都世界大学生运动会,可以用手机看.用电视看,甚至用VR沉浸式观看,并且既高清又流畅--在"2023数字科技生态大会&quo ...

  8. Maven 打包的几种常用方式

    一.maven-jar-plugin 默认的打包插件,用来打普通的jar 包,需建立lib目录里来存放需要的依赖包 二.maven-shade-plugin (推荐) 将依赖的jar包打包到当前jar ...

  9. 问题-ifconfig

    在运行centos7 运行ifconfig命令时出现: [root@kvm1 ~]# ifconfig -bash: ifconfig: command not found 原来是这样: 1.ifco ...

  10. 打工人最强福音上线!AOne终端全面接入DeepSeek大模型!

    DeepSeek深度融合国产AI生态,国云连放大招! 继天翼云多款产品上线DeepSeek后, 见证企业级智能办公的时刻来了! 天翼云AOne联合国产大模型王者DeepSeek 带着671B满血版.7 ...