Now a different kind of load: processes that need nothing but the CPU.
Three processes on one CPU
Start stress-ng in the background: three processes that only compute for 60 seconds. Then look at vmstat and at the states of the stress-ng processes.
First, predict
Three processes compute non-stop on a single CPU. What number will vmstat show in the r column in the lines after the first?
Now start the exercise, run the command and compare your prediction with the output.
vmstat 1 5 prints five lines one second apart. The first is the average since the machine booted; the current state is in the following lines. The r column is how many processes are in R: the three stress-ng-cpu workers of stress-ng, sometimes vmstat itself. While they compute, the load average climbs towards three — as at the start of the lesson, only now the CPU is busy.
The cpu group on the right shows shares of CPU time in percent:
| Field | Where the time went |
|---|---|
us |
programs |
sy |
the kernel, on behalf of programs |
id |
idle |
wa |
idle while processes wait for I/O |
st |
time the host took from the virtual machine |
The %Cpu(s) line in top has the same fields. A high load together with an id near zero is a queue for the CPU. A high load with a large id means processes in D: look for the cause in the storage.
A server has 4 CPUs. uptime shows load average: 6.10, 5.80, 5.20, vmstat shows r of about 6 and an id of 0. What do you do first?
-
There is no threshold of 10: the load is compared with the number of CPUs. 6 on four CPUs means two processes always wait in the queue.
-
Processes waiting for the disk sit in D, and the CPU stays idle meanwhile. Here id is 0 and r is about 6 — a queue for the CPU.
A load above the number of CPUs with an id of 0 and a large r is a queue for the CPU. Start with whoever takes most of it: top sorts by %CPU.