Notes
The USE method
The USE method, popularised by a performance engineer at Netflix, is simple. For every resource, CPU, memory, disk and network, ask three questions. Utilisation: how busy is it? Saturation: is work queuing because it is too busy? Errors: is anything failing? Saturation is the one people forget, and it is usually what users feel. Go through the boxes in order, and you rarely miss the real bottleneck.
- U utilisation: how busy? CPU 90%, disk 67% busy
- S saturation: how much work is waiting? run queue, disk queue, swapping
- E errors: anything failing? dmesg, NIC drops, I/O errors
- resources: CPU, memory, disk, network, plus limits
The first 60 seconds
Start with a quick pass over the whole machine, about a minute. Uptime for the load trend. dmesg for kernel errors like OOM kills or disk failures. vmstat for runnable tasks, swapping and I O wait. mpstat for a single hot core. pidstat for which processes. iostat for disks, free for available memory, and ss and ip for network totals and errors. Each of these answers one box of the USE method.
uptime load trend
dmesg -T | tail kernel errors
(OOM, disk)
vmstat 1 r, si/so, wa
mpstat -P ALL 1 hot cores
pidstat 1 per process
iostat -xz 1 disks
free -m available
ss -s; ip -s link network CPU
For the CPU: utilisation is user plus system time, per core with mpstat, so one maxed-out core is not hidden by an average. Saturation is the run queue: r in vmstat larger than the number of CPUs, a high load, or cgroup throttling in containers. Errors are rare, but dmesg reports hardware machine check errors. Last episode showed what saturation does: ShopRung's slowest requests got eight times slower.
- U: vmstat us+sy, mpstat per core (one core at 100%?)
- S: run queue r > CPU count, load average, cgroup throttling
- E: rare; dmesg for machine check errors
- last episode: p95 1.6 → 13 ms under saturation
Memory
For memory: utilisation from free, comparing used with available. Saturation means the kernel is struggling to find memory: swap activity in vmstat, or pressure stall information in proc pressure memory. Errors are OOM kills in dmesg. On our quiet machine, seven thousand four hundred and thirty eight megabytes were available, and memory pressure was zero.
- U: free -m: used vs available
- S: swapping (vmstat si/so), page reclaim, pressure stall info /proc/pressure/memory
- E: OOM kills in dmesg, allocation failures
- ours: 7,438 MB available, memory pressure 0
Disk
For disks, iostat with minus x answers all three. We wrote a large file directly to disk and measured: five hundred and twenty four writes a second, about five hundred and thirty six megabytes a second, each write taking one point two eight milliseconds on average, a queue size of point seven five, and sixty seven percent utilised. Utilisation is percent util; saturation shows as a growing queue and rising await; errors are I O errors in dmesg, and of course a full filesystem.
w/s 524 writes/sec wkB/s 536,576 ~536 MB/s w_await 1.28 ms per write aqu-sz 0.75 queue %util 67.2 U: %util S: aqu-sz, await E: dmesg I/O errors, df full
Pressure stall info
Newer kernels add pressure stall information, a direct measure of saturation. During our write test, I O pressure showed eleven point seven three percent for the last ten seconds: for that share of time, tasks were stalled waiting on the disk. There are matching files for CPU and memory. Many modern tools, including Kubernetes, read these files, because one percentage tells you how much time work lost waiting.
some avg10=11.73 full avg10=11.73 some: % of time at least one task waited on I/O full: % of time all tasks waited also /proc/pressure/cpu and memory: saturation in one line
Network
For the network: ss shows sockets. ss with minus t l n p lists who listens on which port, and on our machine ShopRung's node process was listening on port eight thousand and eighty. ip minus s link shows packets, drops and errors per interface, and nstat shows TCP retransmits, a classic sign of a congested or lossy path. Part two goes much deeper.
$ ss -s socket totals $ ss -tlnp who listens 0.0.0.0:8080 node (ShopRung) $ ip -s link RX/TX, drops $ nstat -az | grep -i retrans U: bandwidth vs link speed S: backlog queues, retransmits E: drops, errors, resets
Inside one process
If every resource looks healthy but one application is slow, look inside it. strace minus c on a running process shows which system calls take the time; minus T shows each call's duration, which exposes slow DNS lookups, slow disk reads or connections waiting to time out. lsof lists its open files and sockets. And perf shows which functions burn CPU. Language-specific profilers come in part eleven.
- strace -c -p <pid>: which syscalls take the time
- strace -f -T: each call's duration (slow DNS, slow disk, connect timeouts)
- lsof -p <pid>: open files, sockets
- perf top / perf record: which functions burn CPU
Common mistakes
Mistakes. Guessing instead of checking each resource in turn. Looking at utilisation but never saturation. Averages that hide one hot core or one slow disk. Skipping dmesg, where the kernel often states the answer. Changing two things at once, so you never learn which one helped. And fixing without measuring before and after.
- guessing instead of checking every resource
- looking at utilisation only, never saturation
- averages hiding one hot core or one slow disk
- ignoring dmesg
- changing two things at once
- no before/after measurement
Say it like this
In the interview: I use the USE method. For CPU, memory, disk and network I check utilisation, saturation and errors, with uptime, vmstat, mpstat, iostat minus x, free, ss and dmesg, plus pressure stall information. If the machine is healthy, I look inside the slow process with strace and perf. I change one thing at a time and measure before and after.
- "I use the USE method: for CPU, memory, disk and network I check
- utilisation, saturation and errors with uptime, vmstat, mpstat, iostat -x, free, ss and dmesg. If the box is fine, I look
- inside the process with strace
- and perf, and measure the fix."