Diagnosing a slow machine: CPU, memory and I/O
A calm, repeatable method for finding why a server is slow, with the commands and signals that matter.
On the roadmap:Intermediate · step 8: Reliability and observability
Lesson 12 of 18 · 10 min read · quiz · exercise
Start with a method, not with commands
When something is slow, people often run tools at random. A short routine finds the cause faster:
- Define the symptom: what is slow, since when, for whom? Latency, throughput or errors?
- Look for a change: deployments, configuration, traffic, data growth, a failing dependency.
- Check each resource with the USE method: for CPU, memory, disk and network, ask three questions:
- Utilisation: how busy is it?
- Saturation: is work waiting in a queue?
- Errors: is anything failing?
- Drill into the suspect with a more detailed tool (profiler, trace).
- Fix, then verify that the metric you started with improved.
Figure SDA-RWS-12-1 · Slow-system investigation flow · © forcsguy.com
Reading the signals
CPU
toporhtop: which processes use CPU? Is time spent in user code, system (kernel) or iowait (waiting for disk)?- Load average counts runnable and waiting tasks. Load much higher than the number of cores means queueing, but remember that tasks waiting on I/O also count.
- A flame graph (from
perfor a language profiler) shows which functions consume the time.
Memory
free -mandvmstat: available memory, swap use. Swapping heavily makes everything slow.- A process whose resident memory only grows has a leak (or an unbounded cache). Watch memory over time, then take a heap profile.
- The operating system uses spare memory as a file cache, so "used" memory is not always a problem. Check available.
Disk (I/O)
iostat -x: utilisation, queue length and await (latency per request). High await with a busy disk means storage is the bottleneck.iotopshows which process does the I/O.- Full disks and exhausted inodes cause odd failures.
Network
ss -s,netstat, and interface counters: connections in odd states, retransmissions, dropped packets.- Check DNS time, connection pool limits and ephemeral port exhaustion.
Application level
- Slow queries and lock waits in the database, thread pool or connection pool exhaustion, garbage-collection pauses, and calls to slow dependencies.
- Distributed traces show where each request spends its time. Logs with a correlation id fill in the detail.
Figure SDA-RWS-12-2 · Which tool looks at which layer · © forcsguy.com
A few useful commands
| Question | Tool |
|---|---|
| What is using CPU and memory? | top, htop, ps aux --sort=-%cpu |
| Is the machine swapping or waiting on disk? | vmstat 1, iostat -x 1 |
| What is a process doing? | strace -p PID (system calls), lsof -p PID (open files) |
| Network state | ss -tan, ping, traceroute, curl -w timing |
| Where is the time in the code? | a profiler or perf, then a flame graph |
Real-world reading
Related reading
- ZooKeeper: Wait-free Coordination for Internet-scale Systems (paper)Hunt et al. · Yahoo! ResearchPapers
- Steady State: Always Put Logs on Separate DiskMicrosoft engineers · MicrosoftCase Studies
- Brendan Gregg's WebsiteBrendan Gregg · brendangregg.comBlogs
- Compression Techniques to Solve Network I/O Bottlenecks at eBayeBay engineers · eBayCase Studies
Show 6 moreShow fewer
- Reduce Memcached Memory Usage by 50% at TrivagoTrivago engineers · TrivagoCase Studies
- The USE MethodBrendan Gregg · brendangregg.comBlogs
- Explaining Low-Level Systems (OS, Network/Protocol, Database, Storage)Wustl engineers · WustlBlogs
- Performance Optimization on OS, Storage, Database, NetworkStackify engineers · StackifyCase Studies
- Go at TrivagoTrivago engineers · TrivagoCase Studies
- Linux PerformanceBrendan Gregg · brendangregg.comBlogs
Check your understanding
Question 1 of 3
0 correct so far
A server shows high load average but low CPU use and high I/O wait. What is the likely bottleneck?
Go deeper
- The USE Method by Brendan Gregg: free; a checklist for finding performance bottlenecks
Topics covered in this lesson
Practise it: Find the slow part
Everything below is already set up for this lesson: change the design, run the traffic, and see whether you meet the goal.
- 1The task
- 2Build and test
At 20 seconds users complain the site is slow. Colours and charts show where.
Goal: Errors under 2%, the slowest 5% under 400 ms.
Run it, watch which part saturates, and take load off it.
Try it yourself
An API server's p99 latency tripled at 14:00. CPU is at 30%, memory is fine, but requests are slow. Outline your investigation.
Click what a strong design here would need:
More in Real systems
© 2026 forcsguy.com. Original lesson text and diagrams. Books and sites linked above belong to their authors.