When production is slow, a calm checklist beats guessing and restarting things.
Work through resources one at a time; for each, ask about utilization, saturation (queueing) and errors.
- Load average (
uptime,top): the average number of tasks running or waiting over 1, 5 and 15 minutes. On Linux it also counts tasks in uninterruptible I/O wait, so compare it withnprocand check whether CPU or I/O is the cause. - CPU:
toporhtopper process;mpstat -P ALL 1per core. Highusis your code, highsythe kernel, highwawaiting for I/O, andst(steal) means the hypervisor is giving your VM less than you think. - Memory:
free -h(the available column),vmstat 1withsi/sofor swapping. When memory runs out, the OOM killer terminates a process;dmesg -T | grep -i oomorjournalctl -kshow the victims. - Disk:
iostat -xz 1(sysstat package) shows utilization, queue size and latency (await) per device;iotopshows which processes do I/O;df -hrules out a full disk. - Per process:
pidstat 1,/proc/<PID>/status,lsof -pfor open files and sockets. - Pressure stall information in
/proc/pressure/{cpu,memory,io}directly reports the share of time tasks were stalled.
vmstat 1 is the best single first command: its r, b, si/so, wa columns show at a glance which resource is under pressure.
Example
uptime # load average: 3.10, 2.05, 1.20 (1, 5, 15 min)
nproc # 4 -> a load above 4 means tasks are queuing
vmstat 1 5 # r=runnable b=blocked si/so=swap wa=I/O wait st=steal
top -o %MEM # or htop; sort processes by memory
free -h # look at 'available'
cat /proc/pressure/memory # some avg10=0.00 ... full avg10=0.00 ...
iostat -xz 1 3 # per-disk %util and await latency (sysstat)
sudo iotop -o # processes doing I/O right now
pidstat -u 1 5 # per-process CPU over time
sudo dmesg -T | grep -iE 'out of memory|killed process' # OOM killer victims
sudo lsof -p 1234 | wc -l # how many files/sockets a process holdsRemember
- Check CPU, memory, disk and network for utilization, saturation and errors
- vmstat 1 is the best first command; load counts I/O waits too
- dmesg / journalctl -k reveal OOM kills
Watch out for
- Adding CPUs to a machine whose high load average is actually caused by tasks waiting on a slow disk.