查找系统平均负载,能够经过top或者uptime命令查看ui
$ uptime 14:12:35 up 289 days, 18:50, 2 users, load average: 0.12, 0.09, 0.07
最后的三个数字,一次是过去 1 分钟、5 分钟、15 分钟的平均负载(Load Average)。code
咱们常常会看,但你不必定正确的理解了平均负载的真正含义。orm
平均负载是单位时间内CPU的使用率吗?0.12表明CPU使用率为12%?有可能不少人是这么理解的,这么理解就错了。three
若是你想看官方的解析,能够经过命令 man uptime 查看,进程
英文原文以下:
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.
下面详细的解析下什么是平均负载,平均负载是指系统处于可运行状态和不可中断状态的平均进程数,也就是平均活跃进程数,它和CPU使用率没有什么必然关系的。it
那什么是可运行状态进程和不可中断状态进程呢?可运行状态进程是指正在使用CPU或者正在你等待CPU的进程,咱们在ps命令下看到的处于Running和Runnable的进程就是可运行状态进程。不可中断状态进程是指正处于内核态关键流程中的进程,而且这些流程是不可中断的,好比最多见的是等待硬件设备的I/O响应,咱们在ps命令下看到的处于Uninterruptible Sleep的进程就是不可中断状态进程。table
平均负载能够简单的理解为单位时间内系统给的活跃进程数。model
怎样的平均负载时合理的?硬件
最理想的状况是平均负载等于CPU个数。平均负载高于CPU个数,说明系统已通过载。grep
查询系统CPU个数:
grep 'model name' /proc/cpuinfo | wc -l
当一段是时间内系统的平均负载高于CPU个数的70%时,就要开始注意排查系统负载高的问题了,系统负载高了,进程的响应速度就会变慢,可能影响到系统提供的服务的正常运行。
平均负载和CPU使用率的区别
不少人在现实工做中,常常把平均负载和CPU使用率混为一谈,平均负载高了,说明活跃进程数多,并不必定CPU使用率高,
下面给你们作下总结:
平均负载是指系统处于可运行状态和不可中断状态的平均进程数,包括正在使用CPU的进程和等待CPU和等待IO的进程。
CPU使用率是指在一段时间内使用CPU状况的统计,
当系统大部分是CPU密集型进程时,二者基本时一致的;
当系统大部分是IO密集型进程时,平均负载高,但CPU使用率不必定高;
当系统有不少等待CPU进度调度的进程时,平均负载高,CPU使用率也会高。
by kocor