Performance and Troubleshooting

Diagnose slow or unhealthy machines methodically by checking CPU, memory, disk I/O and network with the right tools.

Intermediate · about 8 hours · difficulty 3/5

Learn first: Processes, Signals and Resources, Filesystems, Disks and Storage

When a server is slow, guessing wastes time. Use a method: check utilisation, saturation and errors (the USE method) for each resource: CPU, memory, disk and network.

The first-minute checklist

  • uptime: load averages (compare with CPU count).
  • top/htop: which process is hot; watch %wa (I/O wait) and st (steal time on VMs).
  • free -m and vmstat 1: memory pressure, swapping, run queue.
  • iostat -xz 1: disk utilisation and latency.
  • ss -tulpn and sar -n DEV 1: sockets and network throughput.
  • dmesg -T: kernel messages such as the OOM killer or disk errors.

Going deeper

strace shows the system calls a process makes (great for "why is it hanging?"), perf profiles CPU usage, and eBPF tools (bcc, bpftrace) answer precise questions with low overhead.

Pitfalls

Treating load average as CPU percentage, assuming "free memory is low" is a problem (Linux uses spare RAM for cache), and restarting the box before capturing evidence.

Good enough to move on: given a slow VM, you can tell within five minutes whether the bottleneck is CPU, memory, disk or network, and which process causes it.

Key concepts

  • USE method
  • Load average and CPU
  • Memory, cache and OOM killer
  • Disk I/O with iostat
  • vmstat, sar, ss
  • strace
  • perf and flame graphs
  • eBPF tools

Mini project

Use stress-ng to create CPU, memory and I/O pressure on a VM one at a time, and for each run record which tool revealed the problem first and what the key numbers looked like.

Check yourself

A 4-core machine shows a load average of 12 but CPU usage is only 20%. What is probably happening?

Free resources