诚招英才(长期):高级测试开发工程师、测试架构师,C++,java,ops; 联系方式:linhan@taobao.com msn: niuxvampire@hotmail.com

不错的文章,帮助理解load average

上一篇 / 下一篇  2010-02-08 14:55:13 / 个人分类:linux

Understanding Linux CPU Load - when should you be worried?

51Testing软件测试网'`2Y#WQ.n'xd

翻译:http://www.gracecode.com/archives/2973/

t3Lg p*T` M*p s0

P\w7y.F5^:v!f0

+LR(F;A4O2Y0You might be familiar with Linux load averages already. Load averages are the three numbers shown with theuptimeandtopcommands - they look like this:51Testing软件测试网!y#|v mg9IO'k3L@

load average: 0.09, 0.05, 0.01

4{ G&~xoyQ(B'X,W0Most 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?

qe$a]Sx7K0U051Testing软件测试网.|O(d2k/SSQ ?(B?Q

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软件测试网4t9] I{w7K"F}

The traffic analogy

.b7R^4w q0A 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.51Testing软件测试网o@K7x%H-m%B4R

51Testing软件测试网]Xn2u2B m%]J;t^~

So, Bridge Operator, what numbering system are you going to use? How about:51Testing软件测试网NDtEV q;aA l

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

!~*W-f dd7` B0= load of 1.00

`:`UuZO5Bd8W051Testing软件测试网?T2s:r*T,M

= load of 0.5051Testing软件测试网4Xc#?&Aw4i-z!`D

{5qs1S;BE*m ^0= load of 1.7051Testing软件测试网2M h7kw0V8H[s

51Testing软件测试网z9O @7pN%k_6nl


:E5`1Ipeo"m)w0
G(p&w]/c1?051Testing软件测试网1sDCS+kL

51Testing软件测试网o ~0hB L0|Hz

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.

{8t-RA5Bc051Testing软件测试网&C"zY9M@m5HHH

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.51Testing软件测试网4O c?%[;|

So you're saying the ideal load is 1.00?

bq'RM;D C v3F.c'g0P0Well, 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:51Testing软件测试网%r6S }s^)Dc

  • 51Testing软件测试网w*LfryX:v

    The"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.51Testing软件测试网s rO9m-J.u2F`

  • :yl s A*gq4z9z0The"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.51Testing软件测试网S(ltVf gW

  • U@ d@~0The"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.51Testing软件测试网 cPb D!A\,{E

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

51Testing软件测试网CWV S a.B oH

Got a quad-processor system? It's still healthy with a load of 3.00.51Testing软件测试网'W:n4{ z%D~

9qy JR(S0On 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软件测试网AR%|!Y%eo_

U6y? A3W9g_{0If 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%JD*@4rENv051Testing软件测试网#}f!O"Nl)U

= load of 2.00 on two-lane road51Testing软件测试网 S/?1cN.GZ M#b d

0fS^7MoQ |B5h0k0Same 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.

*`9L!w3b} z2`#r0

Multicore vs. multiprocessor

51Testing软件测试网 ~%c;c@5A5z6IpQ

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, thetotal number of coresis what matters, regardless of how many physical processors those cores are spread across.

c7A x!QD C051Testing软件测试网.P$oV2Fo Wc"vQxg

Which leads us to a two new Rules of Thumb:51Testing软件测试网,qi9y L?Zt

  • V*w?#o2\} Eiw/Oc0The "number of cores = max load"Rule of Thumb: on a multicore system, your load should not exceed the number of cores available.

    )C+^j l4X0y1\5m1yz(l0
  • 8E@ H T6t Gu[/k0The"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.

    PE'k4s"|\Ps s0

Bringing It Home

51Testing软件测试网$B;b&JA$U%x

Let's take a look at the load averages output fromuptime:51Testing软件测试网Dten F Vx9f4n"W$N

~ $ uptime51Testing软件测试网;z _h(E4X\t4Pg c
23:05 up 14 days, 6:08, 7 users, load averages: 0.65 0.42 0.36
51Testing软件测试网(_-pghr)X)dNk:M

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.

^F@^,G-ov$F?051Testing软件测试网3vd.i V|

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:51Testing软件测试网e9k?K7rMJ+w v-U)h

*i$k(h(PAm0Which average should I be observing? One, five, or 15 minute?51Testing软件测试网;[8]h@ n&l)k

51Testing软件测试网2R1md3UH c#lC [

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).

G0ed#H1E'T5S"~P9\j;w051Testing软件测试网 AU6`:g r.Y&E2u8FL

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

fm d-t$P0

B+dG&|P%r0cat /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 -l51Testing软件测试网O~7D.Te^/HZ

 


TAG: Linux linux load

 

评分:0

我来说两句

Open Toolbar