[转]理解Linux CPU 负载-什么时候该担心

转载 2011年01月11日 12:28:00

Understanding Linux CPU Load - when should you be worried?

You might be familiar with Linux load averages already. Load averages are the three numbers shown with the uptime and top commands - they look like this:

load average: 0.09, 0.05, 0.01

Most people have an inkling of what the load averages mean: the three numbers represent averages over progressively longer periods of time (one, five, and fifteen minute averages), and that lower numbers are better. Higher numbers represent a problem or an overloaded machine. But, what's the the threshold? What constitutes "good" and "bad" load average values? When should you be concerned over a load average value, and when should you scramble to fix it ASAP?

First, a little background on what the load average values mean. We'll start out with the simplest case: a machine with one single-core processor.

The traffic analogy

A single-core CPU is like a single lane of traffic. Imagine you are a bridge operator ... sometimes your bridge is so busy there are cars lined up to cross. You want to let folks know how traffic is moving on your bridge. A decent metric would be how many cars are waiting at a particular time. If no cars are waiting, incoming drivers know they can drive across right away. If cars are backed up, drivers know they're in for delays.

So, Bridge Operator, what numbering system are you going to use? How about:

  • 0.00 means there's no traffic on the bridge at all . In fact, between 0.00 and 1.00 means there's no backup, and an arriving car will just go right on.
  • 1.00 means the bridge is exactly at capacity. All is still good, but if traffic gets a little heavier, things are going to slow down.
  • over 1.00 means there's backup. How much? Well, 2.00 means that there are two lanes worth of cars total -- one lane's worth on the bridge, and one lane's worth waiting. 3.00 means there are three lane's worth total -- one lane's worth on the bridge, and two lanes' worth waiting. Etc.

= load of 1.00

= load of 0.50

= load of 1.70

 

This is basically what CPU load is. "Cars" are processes using a slice of CPU time ("crossing the bridge") or queued up to use the CPU. Unix refers to this as the run-queue length : the sum of the number of processes that are currently running plus the number that are waiting (queued) to run.

Like the bridge operator, you'd like your cars/processes to never be waiting. So, your CPU load should ideally stay below 1.00. Also like the bridge operator, you are still ok if you get some temporary spikes above 1.00 ... but when you're consistently above 1.00, you need to worry.

So you're saying the ideal load is 1.00?

Well, not exactly. The problem with a load of 1.00 is that you have no headroom. In practice, many sysadmins will draw a line at 0.70:

  • The "Need to Look into it" Rule of Thumb: 0.70 If your load average is staying above > 0.70, it's time to investigate before things get worse.

  • The "Fix this now" Rule of Thumb: 1.00 . If your load average stays above 1.00, find the problem and fix it now. Otherwise, you're going to get woken up in the middle of the night, and it's not going to be fun.

  • The "Arrgh, it's 3AM WTF?" Rule of Thumb: 5.0 . If your load average is above 5.00, you could be in serious trouble, your box is either hanging or slowing way down, and this will (inexplicably) happen in the worst possible time like in the middle of the night or when you're presenting at a conference. Don't let it get there.

What about Multi-processors? My load says 3.00, but things are running fine!

Got a quad-processor system? It's still healthy with a load of 3.00.

On multi-processor system, the load is relative to the number of processor cores available. The "100% utilization" mark is 1.00 on a single-core system, 2.00, on a dual-core, 4.00 on a quad-core, etc.

If we go back to the bridge analogy, the "1.00" really means "one lane's worth of traffic". On a one-lane bridge, that means it's filled up. On a two-late bridge, a load of 1.00 means its at 50% capacity -- only one lane is full, so there's another whole lane that can be filled.

= load of 2.00 on two-lane road

Same with CPUs: a load of 1.00 is 100% CPU utilization on single-core box. On a dual-core box, a load of 2.00 is 100% CPU utilization.

Multicore vs. multiprocessor

While we're on the topic, let's talk about multicore vs. multiprocessor. For performance purposes, is a machine with a single dual-core processor basically equivalent to a machine with two processors with one core each? Yes. Roughly. There are lots of subtleties here concerning amount of cache, frequency of process hand-offs between processors, etc. Despite those finer points, for the purposes of sizing up the CPU load value, the total number of cores is what matters, regardless of how many physical processors those cores are spread across.

Which leads us to a two new Rules of Thumb:

  • The "number of cores = max load" Rule of Thumb: on a multicore system, your load should not exceed the number of cores available.

  • The "cores is cores" Rule of Thumb: How the cores are spread out over CPUs doesn't matter. Two quad-cores == four dual-cores == eight single-cores. It's all eight cores for these purposes.

Bringing It Home

Let's take a look at the load averages output from uptime :

~ $ uptime
23:05 up 14 days, 6:08, 7 users, load averages: 0.65 0.42 0.36

This is on a dual-core CPU, so we've got lots of headroom. I won't even think about it until load gets and stays above 1.7 or so.

Now, what about those three numbers? 0.65 is the average over the last minute, 0.42 is the average over the last five minutes, and 0.36 is the average over the last 15 minutes. Which brings us to the question:

Which average should I be observing? One, five, or 15 minute?

For the numbers we've talked about (1.00 = fix it now, etc), you should be looking at the five or 15-minute averages. Frankly, if your box spikes above 1.0 on the one-minute average, you're still fine. It's when the 15-minute average goes north of 1.0 and stays there that you need to snap to. (obviously, as we've learned, adjust these numbers to the number of processor cores your system has).

So # of cores is important to interpreting load averages ... how do I know how many cores my system has?

cat /proc/cpuinfo to get info on each processor in your system. Note: not available on OSX, Google for alternatives . To get just a count, run it through grep and word count: grep 'model name' /proc/cpuinfo | wc -l

Monitoring Linux CPU Load with Scout

Scout provides 2 ways to modify the CPU load. Our original server load plugin and Jesse Newland's Load-Per-Processor plugin both report the CPU load and alert you when the load peaks and/or is trending in the wrong direction:

load alert

More Reading

Linux CPU 负载度量公式

一个top命令不就行了么?顶多再加一些管道什么的过滤一下。我一开始也是这么想得。其实还可以理解的更多。首先一个问题,是统计某个时间点的CPU负载,还是某个时间段的?为了画折线图报表,一般横坐标都是某个...
  • sheismylife
  • sheismylife
  • 2013年09月14日 19:02
  • 4816

Linux 下 CPU 使用率与机器负载的关系与区别

当我们使用top命令查看系统的资源使用情况时会看到 load average,如下图所示。它表示系统在1、5、15分钟的平均工作负载。那么什么是负载(load)呢?它和CPU的利用率又有什么关系呢? ...
  • andylauren
  • andylauren
  • 2016年09月17日 10:27
  • 2115

linux多CPU进程负载均衡解析

在linux中,支持对称smp的处理器模型,在多处理器的情况下,每个处理器都有自己的一个运行队列,这样就存在着分配不均的情况,有的cpu运行队列很多进程,导致一直很忙,有的cpu运行队列可能很少的进程...
  • wh8_2011
  • wh8_2011
  • 2016年09月20日 07:33
  • 1712

linux系统下查看CPU、内存负载情况

$ vmstat procs -----------memory---------- ---swap-- -----io---- --system-- -----cpu------ r b s...
  • tianruirui
  • tianruirui
  • 2014年10月13日 15:40
  • 3147

Linux查看机器负载

负载是linux机器的一个重要指标,
  • szchtx
  • szchtx
  • 2014年08月09日 13:27
  • 39619

理解 Linux CPU 负载 1分5分15分

http://bbs.chinaunix.net/thread-4070231-1-1.html 本帖最后由 ulovko 于 2013-03-06 15:18 编辑 ...
  • onlyForCloud
  • onlyForCloud
  • 2015年07月28日 13:48
  • 335

到底多高的负载才算高负载?

到底多高的负载才算高负载?
  • kobejayandy
  • kobejayandy
  • 2014年05月03日 00:06
  • 7996

Linux 系统CPU及系统负载监控脚本

配置邮件通知!【使用postfix,如若安装有sendmail,停用或卸载即可】# yum install -y postfix # yum install -y mailx # systemctl ...
  • zxf_668899
  • zxf_668899
  • 2017年01月06日 16:02
  • 326

理解Linux中的CPU负载

你可能对于 Linux 的负载均值(load averages)已有了充分的了解。负载均值在 uptime 或者 top 命令中可以看到,它们可能会显示成这个样子: load average: 0....
  • hm2462964492
  • hm2462964492
  • 2013年06月10日 21:24
  • 578

linux load 监控,负载监控 ,shell 监控cpu,memory,load average,记录到log

linux load 监控,负载监控 。shell 监控cpu,memory,load average,记录到log,当负载压力时,发电邮通知管理员。...
  • yonggeno1
  • yonggeno1
  • 2016年04月19日 14:45
  • 1672
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:[转]理解Linux CPU 负载-什么时候该担心
举报原因:
原因补充:

(最多只允许输入30个字)