Video in progress

The server shows a load average of 20, but top shows the CPU almost idle. What does this mean?

On Linux, load average counts not only the CPU queue but also tasks waiting for disk or network I/O in the uninterruptible (D) state. If the CPU is idle and the load is high, the disk or NFS is usually slow, so look at vmstat, iostat and threads in the D state.

📖 Answer

The three numbers in uptime are the 1, 5 and 15 minute averages: the number of tasks that are ready to run (R) plus those in uninterruptible sleep (D). In Java every thread is a separate task. If a service with 300 threads gets stuck writing logs to a slow disk, the load can easily exceed 20 while the CPU sits idle.

uptime
vmstat 1 5            # the 'b' column: waiting on I/O, 'wa': iowait
iostat -x 1 3         # %util and await: is the disk saturated
ps -eLo state,comm | awk '$1=="D"' | sort | uniq -c | sort -rn | head

Typical findings:

  • a log or heap dump is being written to a slow network disk, or the cloud volume's IOPS quota has run out;
  • the NFS server is not responding, and every thread that touches it gets stuck in D;
  • swap: memory has run out and the kernel is paging out to disk (si/so in vmstat). For Java this is very bad: the GC walks the whole heap and every page comes back from disk.

Compare the number with the core count: 12 on a 16-core machine is normal, on a 2-core one it is serious.

Inside a container, uptime shows the host's load, not the pod's, because /proc/loadavg is not namespaced. For a pod, look at cgroup metrics: CPU throttling and the cpu.pressure and io.pressure (PSI) files in cgroup v2.