有诸多方式监测系统平均负载,如 uptime
,它会展示系统运行时间、用户数量及平均负载:
$ uptime07:13:53 up 8 days, 19 min, 1 user, load average: 1.98, 2.15, 2.21
平均负载的数字从左到右的含义依次为:
高平均负载意味着系统是过载的:许多进程在等待 CPU 时间。
下一节将介绍平均负载和 CPU 核数的关系。此外,常用的工具 top 和 glances 可以实时显示 Linux 系统的运行状态:
$ top
显示运行中的Linux进程:
top - 12:51:42 up 2:11, 1 user, load average: 1.22, 1.12, 1.26Tasks: 243 total, 1 running, 242 sleeping, 0 stopped, 0 zombie%Cpu(s): 17.4 us, 2.9 sy, 0.3 ni, 74.8 id, 4.6 wa, 0.0 hi, 0.0 si, 0.0 stKiB Mem : 8069036 total, 388060 free, 4381184 used, 3299792 buff/cacheKiB Swap: 3906556 total, 3901876 free, 4680 used. 2807464 avail Mem PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 6265 tecmint 20 0 1244348 170680 83616 S 13.3 2.1 6:47.72 Headset 2301 tecmint 9 -11 640332 13344 9932 S 6.7 0.2 2:18.96 pulseaudio 2459 tecmint 20 0 1707692 315628 62992 S 6.7 3.9 6:55.45 cinnamon 2957 tecmint 20 0 2644644 1.035g 137968 S 6.7 13.5 50:11.13 firefox 3208 tecmint 20 0 507060 52136 33152 S 6.7 0.6 0:04.34 gnome-terminal- 3272 tecmint 20 0 1521380 391324 178348 S 6.7 4.8 6:21.01 chrome 6220 tecmint 20 0 1595392 106964 76836 S 6.7 1.3 3:31.94 Headset 1 root 20 0 120056 6204 3964 S 0.0 0.1 0:01.83 systemd 2 root 20 0 0 0 0 S 0.0 0.0 0:00.00 kthreadd 3 root 20 0 0 0 0 S 0.0 0.0 0:00.10 ksoftirqd/0 5 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 kworker/0:0H ....
$ glances
Glances – Linux系统监测工具:
TecMint (LinuxMint 18 64bit / Linux 4.4.0-21-generic) Uptime: 2:16:06CPU 16.4% nice: 0.1% LOAD 4-core MEM 60.5% active: 4.90G SWAP 0.1%user: 10.2% irq: 0.0% 1 min: 1.20 total: 7.70G inactive: 2.07G total: 3.73Gsystem: 3.4% iowait: 2.7% 5 min: 1.16 used: 4.66G buffers: 242M used: 4.57Midle: 83.6% steal: 0.0% 15 min: 1.24 free: 3.04G cached: 2.58G free: 3.72GNETWORK Rx/s Tx/s TASKS 253 (883 thr), 1 run, 252 slp, 0 oth sorted automatically by cpu_percent, flat viewenp1s0 525Kb 31Kblo 2Kb 2Kb CPU% MEM% VIRT RES PID USER NI S TIME+ IOR/s IOW/s Command wlp2s0 0b 0b 14.6 13.3 2.53G 1.03G 2957 tecmint 0 S 51:49.10 0 40K /usr/lib/firefox/firefox 7.4 2.2 1.16G 176M 6265 tecmint 0 S 7:08.18 0 0 /usr/lib/Headset/Headset --type=renderer --no-sandbox --primordial-pipe-token=879B36514C6BEDB183D3E4142774D1DF --lanDISK I/O R/s W/s 4.9 3.9 1.63G 310M 2459 tecmint 0 R 7:12.18 0 0 cinnamon --replaceram0 0 0 4.2 0.2 625M 13.0M 2301 tecmint -11 S 2:29.72 0 0 /usr/bin/pulseaudio --start --log-target=syslogram1 0 0 4.2 1.3 1.52G 105M 6220 tecmint 0 S 3:42.64 0 0 /usr/lib/Headset/Headset ram10 0 0 2.9 0.8 409M 66.7M 6240 tecmint 0 S 2:40.44 0 0 /usr/lib/Headset/Headset --type=gpu-process --no-sandbox --supports-dual-gpus=false --gpu-driver-bug-workarounds=7,2ram11 0 0 2.9 1.8 531M 142M 1690 root 0 S 6:03.79 0 0 /usr/lib/xorg/Xorg :0 -audit 0 -auth /var/lib/mdm/:0.Xauth -nolisten tcp vt8ram12 0 0 2.6 0.3 79.3M 23.8M 9651 tecmint 0 R 0:00.71 0 0 /usr/bin/python3 /usr/bin/glancesram13 0 0 1.6 4.8 1.45G 382M 3272 tecmint 0 S 6:25.30 0 4K /opt/google/chrome/chrome ...
这些工具中的平均负载是从 /proc/loadavg
文件中读取的,也可以直接使用 cat 命令查看:
$ cat /proc/loadavg2.48 1.69 1.42 5/889 10570
想要图形样式监测平均负载,请戳:ttyload – 终端中颜色编码图形显示 Linux 平均负载。
在桌面计算机中,可以使用图形用户接口工具查看系统平均负载。
考虑了 CPU 核心数的影响,才能解释系统负载。
此外,Intel 引入了超线程技术用来提高并行计算能力。
通过超线程技术,在操作系统中,单个物理 CPU 表现的和两个逻辑 CPU 一样。(实际在硬件上只有一个 CPU)。
注意,单个 CPU 核同一时间只能执行一个任务,于是产生了多 CPU/处理器、多核 CPU,以及多线程技术。
多 CPU 时,多个程序可以同时执行。如今的 Intel CPU 使用了多核心和超线程技术。
可以使用 nproc 或 lscpu 命令查看系统中的处理器单元数量。
$ nproc4# 或者lscpu
也可以使用 grep 命令:
$ grep 'model name' /proc/cpuinfo | wc -l4
为了进一步理解系统负载,需要做一些假设。假设系统负载如下:
23:16:49 up 10:49, 5 user, load average: 1.00, 0.40, 3.35
在单核系统中意味着:
在双核系统中意味着:
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。