[CoLoCo] Odd load for sleep mode
Scott Scriven
ubuntu-us-co at toykeeper.net
Mon Sep 22 22:50:26 BST 2008
* Chris Yoder <chris at medioh.com> wrote:
> Or you could just run top in a terminal window, but it isn't as pretty.
Top is okay, but it misses some important resources, and the
display isn't as human-readable as a graph.
> I'd have to read the source to make sure, but normally a
> process blocked on IO does not contribute to the load, because
> the load average is the number of threads waiting to get onto
> the cpu, as a simplistic rule of thumb.
Nope, the load average isn't just CPU time. It's the number of
processes waiting on the kernel for any reason at all. For a
demonstration, try this... Open two shells. In each, run 'cat
/dev/sda > /dev/null'. Let it run for a while, and watch the
system load and the CPU use. The loadavg should stabilize right
at 2, while the CPU load stays down around 10%.
Another easy way to show it is to mount a dir via NFS, unplug the
network, then try to 'ls' the dir. Do this a dozen times, and
the load will rise to 12, but the system won't actually be doing
anything -- no CPU activity, no disk activity, and barely any
network activity.
An odd quirk is that you can actually have a load of 0.00 with
90% CPU activity. To do this is a little trickier, but fairly
simple. Just make a program like this:
while(1) {
for(i=0; i<1000000; i++) {} // requires calibration
usleep(1); // 1 microsecond
}
The idea is to eat up most of a time slice, then voluntarily give
control back to the kernel. Even though it's using most of the
CPU capacity, the process won't contribute to the load average at
all. The kernel calculates the load average at the end of each
time slice, at which point the task isn't waiting for anything
from the kernel.
That effect isn't usually so noticable, but I often see a load of
0.00 on an "idle" system while the CPU is 5%-20% busy.
Anyway, all I was getting at is that I don't often find loadavg
useful. It's a data point, but not one I place much value on.
-- Scott
More information about the Ubuntu-us-co
mailing list