Lesson 1 of 13 · 16m
The Bottleneck Isn't Where You Think
Wall time splits into on-CPU and off-CPU, and USE/RED find which resource owns the missing milliseconds before you touch code.
A request takes 800 ms. The box shows 6% CPU. Someone opens the codebase, finds the function they wrote last sprint, and starts "optimizing" it. That reflex is why most performance work is wasted: the time is almost never where the staring happens.
Wall time decomposes into two buckets. On-CPU time is the process actually executing instructions. Off-CPU time is everything else — waiting on a disk, waiting on a mutex, waiting on the network, waiting for a CPU to run on, sleeping out a cgroup throttle window. perf answers the first question. It answers nothing about the second, and on a service under contention the second bucket is where the 800 ms went.
The mental model that burns time
The wrong model is "slow means slow code." It produces diffs that shave a hot function from 40 ms to 35 ms while the request still waits 700 ms on a mutex held by a logging call. The right model is "slow means time went somewhere" — find where before deciding what to fix.
Off-CPU splits further into voluntary and involuntary waits. Voluntary: the thread asked to sleep — read() on a socket, futex_wait on a contended lock, fsync on a log file. Involuntary: the scheduler or the hypervisor took the CPU away — runnable threads queuing on saturated cores, a cgroup quota window, hypervisor steal time. Each has its own tool and its own fix, and none of them is a faster algorithm.
Amdahl's law does the arithmetic for you. If a function accounts for 8% of wall time, rewriting it to be infinitely fast buys you 8%. Not half. Eight percent. Engineers routinely spend a week optimizing code that is 5% of the request path because it was the code they understood, not the code that mattered.
USE, not vibes
Brendan Gregg's USE method is the checklist that replaces guessing: for every resource — CPU cores, memory, each disk, each network interface, the thread pool, the connection pool, every mutex — check utilization, saturation, and errors. Low CPU with high latency means the CPU is not the resource. So walk the others: vmstat's blocked column, iostat's await, cpu.stat's throttled counter, the pool's active-versus-max gauge.
For request-driven services, Tom Wilkie's RED variant applies the same idea one level up: rate, errors, duration per request type. A p99 duration that p50 never shows is saturation hiding in the tail, not a code problem.
Evidence from the field
Google's 2015 warehouse-scale profiling paper (Kanev et al., ISCA) sampled the fleet continuously and found cores stall on memory and instruction fetch far more often than they retire work — typical server binaries run at an IPC near 1 on hardware able to retire four instructions per cycle. The machines were not out of CPU; the cores were parked waiting on DRAM. Teams that profiled learned that. Teams that guessed "optimized" loops that were never the bottleneck.
The other canonical case: a service whose p99 traced entirely to a mutex serializing requests through a shared client. The on-CPU profile looked clean because every thread was blocked in futex_wait, not computing. The profile told the truth; it was being asked the wrong question.
The practice
Decompose one request before touching code:
perf stat -p <pid> sleep 10for on-CPU density: instructions, IPC, context switches.offcputime-bpfcc -p <pid> 10for where the threads block.vmstat 1,iostat -xz 1,mpstat -P ALL 1for the resource picture.- The application's own pool and queue gauges for saturation that never reaches the kernel.
Order findings by fraction of wall time, not by which looks fixable. Fix the top one. Re-measure. The bottleneck moves — that is the point of the exercise.
Was this lesson helpful?
Keep reading
Related articles from the SudoSecurity blog.
Your Minecraft Server Isn't Slow, It's Misconfigured
Can't keep up! is not a hardware message. It's the server telling you a tick took longer than 50ms, and almost every cause is a default nobody changed. Here's what actually moves MSPT, with the flags that are now wrong and the setting that isn't where every guide says it is.
Your Minecraft Server Wants Java 25, Not Java 26
Every six months the same thread appears and nobody maps the JVM engineering onto what a Minecraft server actually does. This does — version by version, with the flag most guides still tell you to set that will eventually stop your server from booting.
Your Container Is Running SerialGC and Nobody Told You
You tuned G1 flags for a week. Your pod has one CPU, which means the JVM quietly picked a single-threaded collector at startup and ignored every flag you set. Here is the OpenJDK source that made that decision.
How to Debug Minecraft Server Lag with Spark Profiler (2026 Guide)
Your server dropped to 12 TPS. You copied Aikar's flags. You upgraded Java. Nothing changed. That's because JVM flags don't fix plugin bugs. Here's how to find what's actually killing your tick budget.