Performance method: USE, load average, steal time, the toolkit, profiling, and strace pitfalls

USE: for every resource ask utilisation, saturation and errors. Saturation is what hurts latency, and utilisation lies — especially on a throttled container.

Read the briefing
About 4 min to read 7 drills

What to remember

  1. Utilisation lies; saturation hurts. Low CPU with terrible latency is a throttled cgroup or a queue somewhere.
  2. Load average counts D-state tasks. High load with idle CPU means waiting on I/O or locks, not compute.
  3. %util on an SSD is not saturation. Read await and queue depth; parallel devices serve many requests at once.
  4. Steal time is the hypervisor taking your CPU. Fix by moving or resizing, never by tuning the application.
  5. PSI is the best saturation signal, and it is per cgroup. It rises before the outage, which is what makes it alertable.

The big picture

Performance work is about not guessing. The USE method (for every resource: utilization, saturation, errors), the 60-second checklist, load average and pressure stall information, steal time in virtual machines, and knowing when to reach for perf and flame graphs versus strace. Interviewers use this topic to separate people who run top and guess from people who have a method that terminates in a named bottleneck.

The mental model

Resources, not symptoms. List the resources (CPUs, memory, disks, network, plus software resources such as locks, thread pools, connection pools, and cgroup quotas) and for each one ask: how busy, is work queuing, are there errors. Saturation is what hurts latency: a queue means work is waiting. Only when a resource is saturated do you profile the code that is consuming it.

In depth

USE and the 60-second checklist

The USE method asks three questions of every resource: Utilization (fraction of time busy), Saturation (queued work or wait time), Errors. The Linux 60-second checklist walks the resources in order: uptime (load average trend), dmesg -T | tail (OOM kills, disk errors, NIC resets), vmstat 1 (r run queue against CPU count, b blocked, si/so swapping, us sy id wa st), mpstat -P ALL 1 (one hot CPU means a single-threaded bottleneck or an interrupt storm), pidstat 1 (who is consuming CPU over time), iostat -xz 1 (r/s w/s, await, aqu-sz; note %util is misleading on SSDs and arrays, which serve requests in parallel), free -m (buffers and cache are reclaimable; look at available), sar -n DEV 1 (throughput against line rate), sar -n TCP,ETCP 1 (connection rate, retransmits), and top for a sanity check. Saturation indicators are what you are hunting: run queue longer than the CPU count, blocked tasks, aqu-sz above 1 per spindle-equivalent, drops on a NIC, throttled periods on a cgroup.

Load average, PSI, and steal

The Linux load average counts tasks that are runnable or in uninterruptible sleep (state D), damped over 1, 5, and 15 minutes. High load with idle CPUs therefore means tasks are waiting on I/O or locks, not on CPU. PSI (/proc/pressure/cpu, memory, io) measures the share of wall time in which tasks stalled for a resource: some (at least one task stalled) and full (all non-idle tasks stalled), averaged over 10, 60, and 300 seconds, and it is available per cgroup, which makes it the best saturation signal for containers. Steal (st in vmstat/top) is time your virtual CPU wanted to run but the hypervisor ran something else: oversubscribed hosts or noisy neighbours, fixed by resizing or moving to dedicated capacity rather than by tuning the application. In containers the host can look idle while the workload is starved: read cpu.stat in the cgroup for nr_throttled and throttled_usec before believing a low utilization number.

Profiling versus tracing: perf, flame graphs, strace

Once a resource is saturated, find the code. perf top and perf record -g -F 99 -p <pid> -- sleep 30 followed by perf report or a flame graph show where CPU time goes; good stacks need frame pointers or --call-graph dwarf, and JIT runtimes need their own profilers or perf-map agents. Off-CPU analysis (bpftrace, BCC offcputime) explains waiting rather than computing, which is where most latency lives. strace is ptrace-based: it stops the process at every system call and can slow a busy service by one or two orders of magnitude; use it bounded (timeout 10 strace -c -f -p <pid> for a summary, -e trace=network -T for a filtered view), preferably on a canary, and prefer perf trace or bpftrace on production. tcpdump and /proc complete the toolbox. Finish by stating the bottleneck, the evidence, and the fix you would test.

Myths and facts

Myth: A high load average means the CPUs are busy.

Fact: Linux load counts uninterruptible (D-state) tasks too; high load with idle CPUs points at disk, network filesystems, or locks.

Myth: iostat %util at 100% means the disk is saturated.

Fact: %util means at least one request was in flight; SSDs and arrays serve many in parallel. Read await and aqu-sz for saturation.

Myth: strace is a safe first tool on a production process.

Fact: It is ptrace: every syscall stops the process. On a hot service it can be a self-inflicted outage; bound it or use perf trace/bpftrace.

Myth: Low CPU utilization means CPU is not the bottleneck.

Fact: A cgroup can be throttled, one core can be pinned at 100% while the average looks fine, and averaging hides bursts; check saturation (run queue, PSI, throttling).

Myth: Free memory is low, so the host needs more RAM.

Fact: Page cache and buffers are reclaimable; look at 'available', swap activity, and memory PSI.

How pros do it

  • Start with the 60-second checklist and write down the USE state of each resource before touching the application.
  • Alert on saturation signals (PSI, run queue per CPU, cgroup throttling, disk queue depth, NIC drops), not on utilization alone.
  • Profile with perf and flame graphs when CPU is the saturated resource; use off-CPU analysis when tasks are waiting.
  • Bound every tracing tool: timeouts, filters, summaries; test strace on a canary, not the last healthy replica.
  • End every investigation with a sentence: resource X is saturated because Y; the fix is Z; verified by W.

Questions people ask

Load is 30 on an 8-core box but CPU is 70% idle. What is going on?

Tasks are waiting, not computing: Linux load counts uninterruptible (D-state) sleepers alongside runnable tasks, so high load with idle CPUs is a queue on disk, a network filesystem or a lock. Say that, then name the reads: vmstat's b column, iostat await and aqu-sz, /proc//stack for the waiters, and /proc/pressure/io. The caveat: the numbers are damped averages, so quote the trend across 1, 5 and 15 minutes rather than one sample.

When is strace the right tool?

Rarely on a hot production process, and only bounded: timeout 10 strace -c -f -p <pid> for a syscall summary, or -e trace=network -T for one specific question, ideally on a canary. The mechanism is ptrace: every syscall stops the process, so a syscall-heavy service slows by one to two orders of magnitude while you are attached. For hot paths say perf trace or bpftrace instead, and remember strace cannot see a CPU-bound loop at all.

What does 20% steal mean for my VM?

One fifth of the time your vCPU was runnable and the hypervisor ran another guest: oversubscription, a noisy neighbour or exhausted burst credits. The only fixes are placement and instance type, a dedicated or bare-metal host, never application tuning. The caveat: on bare metal steal is zero, and the equivalent invisible losses are SMT sibling contention, frequency throttling and remote NUMA access.

Which is better, top or PSI?

They answer different questions. PSI says whether anyone is waiting for a resource, as a share of time, per host and per cgroup, which makes it the saturation signal to alert on; top shows utilization and names the consumer. Lead with PSI to decide whether a resource is saturated, then top or pidstat to say who. The caveat: PSI needs kernel 4.20 or newer, and some distributions ship it disabled until you boot with psi=1.

How do I profile a Go or Java service?

Use the runtime's own profiler first, pprof for Go and JFR or async-profiler for the JVM, because they give symbolized stacks including the runtime's own work. perf works for native code and for JITs with perf-map agents. The caveat: a CPU profile shows where time is spent computing; if the service is slow while waiting, you need an off-CPU view (offcputime, or the runtime's block and mutex profiles).

Further reading

Drills · 7

Answer in your head, or out loud, before you reveal. Mark each one: "Again" brings it back, "Got it" counts on your desk.

1 Pick the strongest answer

You get paged: an 8-core host shows a load average of 30 while mpstat reports the CPUs 70% idle. What does that combination tell you?

  1. Many tasks are in uninterruptible sleep (D state) waiting on I/O or locks; Linux load counts them, so the bottleneck is disk, a network filesystem, or contention, not CPU. Load = runnable + uninterruptible; idle CPUs with high load means waiters.
  2. Too many threads; raise the CPU count. More CPUs do not help tasks waiting on disk.
  3. CPU saturation that mpstat is averaging away. Run queue would show as r in vmstat and per-CPU busy in mpstat; 70% idle rules it out.
  4. The load average is broken; reboot. The number is correct and informative.
In short

Many tasks are in D state waiting on I/O or locks, and Linux counts them in the load average, so the bottleneck is disk or contention, not CPU.

Why

Follow the waiters: vmstat b column, iostat -xz await and queue, /proc/<pid>/stack for the stuck processes, and PSI io. The USE lens says: which resource is saturated? Not the CPU.

The common mistake

Treating load average as a CPU number and asking for more cores. A load of 30 with idle CPUs is a queue of waiters, and more CPUs do not drain it.

Read the docs

2 Answer out loud

A host is 'slow'. Walk me through the method you use to find the bottleneck, the specific signals you read for each resource, and how you know you are done. Four to six sentences.

In short

A strong answer checks utilization, saturation and errors for every resource, names the saturated one with evidence, and stops only when a tested fix makes that signal normal again.

What a strong answer does
  • method: USE method: for each resource utilization, saturation, errors; the 60-second checklist as the walk; saturation signals named (run queue, PSI, aqu-sz, throttling, drops).
  • depth: Explains saturation vs utilization, cgroup throttling and steal, then profiling (perf/flame graph, off-CPU) once the resource is known, with tool cost awareness.
  • termination: Done when a resource is named as saturated with evidence, a mechanism explains it, and a fix is tested against the same signal.
Why

The rubric rewards a method with a termination condition and the utilization-versus-saturation distinction; the tool list is the least important part.

The common mistake

Reciting commands in order (top, vmstat, iostat) without saying what each rules in or out, and stopping at 'the busiest process' instead of a saturated resource.

3 Pick the strongest answer

A VM's top shows %st (steal) at 25% and the application is slow. What does steal mean, and what actually fixes it?

  1. Kernel threads are stealing CPU from user space. That would be %sy, not %st.
  2. The application is stealing cycles via spinlocks. Spinning shows as user or system time in the guest.
  3. The hypervisor ran other guests during a quarter of the time this vCPU wanted to run (oversubscription or a noisy neighbour); move to a less contended or dedicated instance type, not to application tuning. Steal is time taken from the guest by the host; only placement or instance type changes it.
  4. It is a rounding artifact; ignore it. 25% steal is a large, real loss of capacity.
In short

Steal means the hypervisor ran other guests for a quarter of the time; move to a less contended or dedicated instance, do not tune the app.

Why

Steal is the hypervisor's fingerprint. Burstable instance classes that ran out of credits show it, as do oversold hosts; the fix is capacity or placement. Note that for cloud validators and RPC nodes, dedicated or bare-metal hosts exist largely to make this number zero.

Read the docs

4 Read the output

Walk me through this output: which resource is saturated, and what is the evidence?

$ uptime
 22:14:03 up 41 days,  3:12,  1 user,  load average: 38.20, 35.91, 21.04
$ nproc
8
$ vmstat 1 3
procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----
 r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa st
 2 34      0 812340 104220 9012340    0    0 48210    96 6120 9821  6  4 22 68  0
 1 36      0 810112 104220 9014400    0    0 51002   120 6390 9950  5  4 20 71  0
 3 35      0 809900 104220 9016120    0    0 49877   104 6201 9880  6  3 23 68  0
$ iostat -xz 1 2 | tail -2
Device   r/s      rkB/s    r_await  aqu-sz  %util
nvme1n1  3120.00  49920.0  11.20    35.10   99.8
  1. Disk reads on nvme1n1: 34–36 tasks blocked (b), wa around 70%, and an average queue of 35 requests with 11 ms waits; the run queue (r) is tiny, so CPU is fine. Next: find the reader with pidstat -d or iotop and check the volume's IOPS ceiling. b, wa, and aqu-sz all point at the same resource; r rules out CPU.
  2. CPU: load 38 on 8 cores. r is 1–3 and id is 20%+; load is inflated by D-state waiters.
  3. Network: interrupts (in) are high. 6k interrupts/s is unremarkable and the blocked tasks are on disk.
  4. Memory: free is only 800 MB. 9 GB of cache is reclaimable and si/so are zero; no memory pressure.
In short

Disk reads on nvme1n1 are saturated: about 35 blocked tasks, wa near 70%, and a queue of 35 requests waiting 11 ms each, while the run queue is tiny.

Why

Read the columns as a USE table: CPU utilization low, saturation none; disk utilization high, saturation high (queue 35). The story is a read-heavy workload exceeding the device's throughput or the cloud volume's provisioned IOPS. %util alone would have been a weaker signal than aqu-sz and r_await.

Read the docs

5 Find what's broken

A teammate wants to run this on the one healthy production replica. Two lines will hurt. Which, and why?

#!/usr/bin/env bash
# perf-triage.sh: first look at a slow host, then a deep dive on the api process
set -uo pipefail
uptime
dmesg -T | tail -n 20
vmstat 1 5
mpstat -P ALL 1 5
pidstat 1 5
iostat -xz 1 5
free -m
sar -n DEV 1 5
sar -n TCP,ETCP 1 5
# deep dive
PID="$(pgrep -o -x api)"
strace -f -p "$PID"
perf record -p "$PID" -- sleep 30
perf report --stdio | head -60
In short

Line 15 attaches an unbounded strace to a hot process, which will cripple it, and line 16 runs perf record without -g, so it captures no stacks.

What's broken
  • Line 15: strace -f attached to a hot process with no filter or time bound stops every thread at every syscall via ptrace; the healthy replica becomes the slow one, and the script never proceeds until Ctrl-C.
  • Line 16: perf record without -g (or --call-graph dwarf) captures no stacks, so the report shows hot symbols without the call paths needed for a flame graph.
Why

The checklist half of the script is fine, including iostat -xz and the TCP counters; pgrep -o -x picks the oldest exact match, which is what you want. The deep-dive half combines the most dangerous tool used carelessly with the most useful tool used weakly.

Read the docs

6 Scenario: what do you do next?

A containerized API's p99 latency is four times normal since this morning. The host dashboard shows CPU at 25% and memory at 60%. The developers say the CPU is fine so it must be the database, but the database team sees nothing unusual.

Step 1. Where do you start?

  1. With saturation, not utilization: run queue per CPU and PSI on the host, then PSI and cpu.stat throttling inside the API's cgroup, then disk and network queues; utilization averages hide starved containers. USE: a resource can be saturated for one consumer while the host average looks idle.
  2. Restart the pods. Destroys the evidence and rarely fixes a throttling or saturation issue.
  3. Ask the database team to look harder. No evidence points at the database yet; bisect your own resources first.
  4. Scale the API to more replicas. Without a cause, more replicas may reproduce the problem or mask it at cost.

Step 2. Inside the cgroup: cpu.max is 200000 100000 (2 CPUs); cpu.stat shows nr_throttled climbing by hundreds per minute and throttled_usec huge; the process runs 16 worker threads; PSI cpu some avg10 in the cgroup is 55%. Mitigation?

  1. Tune the database connection pool. Unrelated to CPU throttling.
  2. The container is CPU-throttled: 16 threads burst past a 2-CPU quota every period and stall. Raise or remove the CPU limit (keep the request), or match the thread count to the quota; verify throttled periods drop and p99 recovers. Saturation named with evidence; the fix targets the quota mechanism and is verified by the same counters.
  3. Add more CPUs to the host. The host has spare CPU; the quota is the limit.
  4. Set CPU requests higher but keep the same limit. Requests affect scheduling; the limit is what throttles.

Step 3. p99 recovered. Systemic fix?

  1. Alert on cgroup throttling and PSI rather than utilization, set a policy on CPU limits for latency-sensitive services, and add continuous profiling so CPU per request has an owner. Turns the lesson into signals, a policy, and an ongoing measurement.
  2. Remove all CPU limits in the cluster. A blanket change with its own noisy-neighbour risks; make it a policy with reasoning.
  3. Document 'check throttling' in the runbook. A reminder; an alert would have found this in minutes.
In short

Check saturation before utilization: cpu.stat shows the container is throttled by its 2-CPU quota, so raise the limit or match the thread count to it, then alert on throttling.

Why

Utilization said 'fine'; saturation said 'starved'. Cgroup throttling is the canonical example of why the USE method insists on saturation as a separate question, and PSI per cgroup is the signal that exposes it.

Read the docs

7 Quick recall

Follow-up: which process state inflates the Linux load average without using any CPU?

In short

D state, uninterruptible sleep, counts toward the load average without using CPU.

Accepted

D · D state · uninterruptible sleep

Why

Uninterruptible sleep (D): tasks waiting on I/O or certain locks are counted as load even though they are not runnable.

That's the last lesson in mission 02 Pick your next mission
Drill · Performance method
0:00

Loading…