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 theuptimeandtopcommands - they look like this:51Testing软件测试网q} D'|Rn/Z3X8hK

load average: 0.09, 0.05, 0.01

51Testing软件测试网FVI-F9h _

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?

xO'hJ2OM051Testing软件测试网ov ["JU*/ w'h

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.51Testing软件测试网&h#GFY*o%KU

The traffic analogy

51Testing软件测试网/ur(BKt Hc[

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 behow many cars are waitingat 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.

,D Me9o0E:F:}-N/U8A H051Testing软件测试网[zVj9|:i%A*k

So, Bridge Operator, what numbering system are you going to use? How about:51Testing软件测试网N%WK&cW,@

  • 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 isexactlyat 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.

51Testing软件测试网wW]-J.x$p7NJ L6T

= load of 1.0051Testing软件测试网TM8j:[p.I;D

P&Y0l*@b h u7qi4y0= load of 0.5051Testing软件测试网3X4c;Q~Y"k%e

nKol XQ.| ZZ0= load of 1.7051Testing软件测试网:fs{ u5f

r1i'ar4Mm0
f(Di(yTI051Testing软件测试网J U q~(@.Yc
51Testing软件测试网4x1Hr%M#Bk g9{

51Testing软件测试网z"N`)U$s)p"d

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 therun-queue length: the sum of the number of processes that are currently running plus the number that are waiting (queued) to run.51Testing软件测试网2umd.f xmj m T?

51Testing软件测试网t%e^ rC8@ s}

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.

n*Wq j x[0

So you're saying the ideal load is 1.00?

3Kt+BBw4r5/6e cp0Well, 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:

3wP/}(wDLh O0

  • :f&C5f%T)^(p9d0The"Need to Look into it"Rule of Thumb:0.70If your load average is staying above > 0.70, it's time to investigate before things get worse.

    2s;nK.?o$upAIy0
  • 2q,j+n#L$j!ym C0The"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.

    0VAo/pG"z2a0
  • zw%[/yvx0The"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.

    x Ec7SY-tW0

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

51Testing软件测试网.Z7?LLQtX

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

!~n0TG4{G!q:h0

~O7/;u#F k$K0On 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.51Testing软件测试网-m/TZz6MY#z4[

(mv;Y$mI]~ `c7B0If 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.

!V}I s7rO0L0

-p%U b:Y/{0fc0= load of 2.00 on two-lane road51Testing软件测试网J"ecig tz

51Testing软件测试网#n*G2m-la r([

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.51Testing软件测试网Rv {Fr#fZe&p

Multicore vs. multiprocessor

L{/b#Q3t$R u b0While 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, thetotal number of coresis what matters, regardless of how many physical processors those cores are spread across.51Testing软件测试网dXn v1dr.Qs K(C

+v!k@;Y(}-Q U0Which leads us to a two new Rules of Thumb:51Testing软件测试网+fZ"xV/B#d[

  • .W+?0?%Jm?/M0The "number of cores = max load"Rule of Thumb: on a multicore system, your load should not exceed the number of cores available.

    S*b@+UA0
  • 51Testing软件测试网[-vD+H WS%Sr)?#u4D

    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.

    H0ncPY s4{s D0

Bringing It Home

51Testing软件测试网/*D$hRz4x#i

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

-z2tH3H YV@D;P@2/0

~ $ uptime
KK ez+v K TOc023:05 up 14 days, 6:08, 7 users, load averages: 0.65 0.42 0.36

YC1X%LX9]0This 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.

BX;u@-V6S0

0}H{2gA4z0Now, 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:

iyK"n1o}R!]-U051Testing软件测试网3BEW$RN3db

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

;r] `oo051Testing软件测试网A/G!a@6f{C

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).51Testing软件测试网OwQ.TKSI9u ?,mr

51Testing软件测试网]PF%ZtdT

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

EXw7p)Q051Testing软件测试网 a)}9//nUzrfo

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值