The run queue and the load average

Video 072 of 140 in Virtualization Foundations, in the unit “Processes, threads and scheduling”. 3:33, with English and Hindi audio.

A monitoring screen says a server's load is forty. Is that bad? The answer depends on what that number counts, and on how many CPUs the server has. The load average is easy to misread, because it counts more than busy processors. This article explains the run queue, what the load average includes, how to read it with the CPU count, and why it can disagree with the CPU usage figure.

What you will learn

What the run queue holds

Each CPU has a run queue, which is the line of threads that are ready to run on it. The scheduler picks the next thread from that line. A CPU runs one thread at a time, so every other ready thread waits in line, and that wait is the price of being busy.

A thread that sleeps while it waits for network data is not in the line. A thread stuck waiting on disk is different. Linux still counts it, because its work is not finished.

What the load average counts

The load average is a count of threads, not a percentage. It includes the threads that are running, the threads that are ready and waiting in line, and the threads stuck waiting on disk. It does not include threads that sleep while waiting for network data.

In the Harbor Point example, the file server shows a load of forty on a machine with eight CPUs, while its processors are mostly idle. That combination looks strange, and it is the reason to read the load average with care. Two threads that are stuck on disk add to the load, but use no CPU at all.

Read the load on a Linux machine

The uptime command prints the time, the uptime, the number of users and three load averages. They cover the last one, five and fifteen minutes.

Show the three load averages
uptime

The same numbers sit in a plain text file inside the special proc folder. That file also gives the count of running threads over the total, and the newest process ID.

Show the load averages from the proc folder
cat /proc/loadavg

Put the load next to the CPU count. A load above the CPU count means threads are waiting in line.

Count the CPUs
nproc

Load average and CPU usage are different measures

Read the two together. A high load with a busy CPU means real queueing, so threads wait for a turn. A high load with an idle CPU points elsewhere, often at threads stuck on disk or storage.

Note: Always read the load together with the CPU figures, and understand what each number counts before you act on it.

Read the load against the CPU count

You need a Linux terminal. You will read the load in two ways, then compare it with the number of CPUs on the machine.

  1. Show the time, the uptime, the users and the three load averages.

    uptime

    What you should see: The three numbers are the load over the last one, five and fifteen minutes.

  2. Read the same load averages from the plain text file in the proc folder.

    cat /proc/loadavg

    What you should see: The first three values are the load averages. The fourth field is running threads over total threads, and the fifth is the newest process ID.

  3. Count the CPUs, then compare the one-minute load with that number.

    nproc

    What you should see: The output is the CPU count. A load above it means threads are waiting in line.

Terms

Run queue
The line of threads that are ready to run on a CPU, from which the scheduler picks the next one.
Load average
A count of running, ready and disk-waiting threads, averaged over one, five and fifteen minutes.

Check yourself

Does a load of forty always mean the CPUs are full?

No. The load average counts threads, including threads stuck on disk, so it can be high while the CPUs are mostly idle.

Which threads does the load average not count?

Threads that sleep while they wait for network data. Threads stuck on disk are still counted.

What does a load above the CPU count tell you?

That threads are waiting in line for a CPU.

Previous: The scheduler: who gets a CPU, and for how long?. Next: Priorities and the nice value.