DEVOPS, SRE AND CLOUD · PART 1 · LINUX, FROM THE INSIDE · DEBUGGING · 27 OF 187

Linux Troubleshooting: A Method for Slow Servers

A repeatable method for "the server is slow" or "the app is down", applied to ShopRung with faults we really injected in Part 1: scope and evidence first, the service and its logs, the 60-second resource pass, then four cases: CPU contention (p95 1.6 to 13 ms, fixed by renice), a full disk, a deleted log still holding 100 MB, and an OOM kill (exit 137), each with symptom, proof and fix.

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  10. 10
  11. 11
  12. 12
  13. 13
  14. 14
  15. 15
  16. 16
  17. 17
  18. 18
  19. 19
  20. 20
  21. 21
  22. 22
  23. 23
  24. 24
  25. 25
  26. 26
  27. 27
  28. 28
  29. 29
  30. 30
  31. 31
  32. 32
  33. 33
  34. 34
  35. 35
  36. 36
  37. 37
  38. 38
  39. 39
  40. 40
  41. 41
  42. 42
  43. 43
  44. 44
  45. 45
1 / 13

Press play to hear the narration, or step through at your own pace.

Key takeaways

  • Scope
  • service
  • USE pass
  • mitigate, one change at a time
  • confirm
  • root cause
  • write-up

Notes

1 · Scope

Step one, scope it before you touch anything. What exactly is wrong: slow, errors, or completely down? Since when, and what changed around then, a deploy, a config change, a traffic spike? Is it everyone or some users, one server or all of them? How bad is it for users right now? Write times down from the first minute. Most incidents are caused by a change, so the timeline is half of the answer.

Ask first
  • what exactly is wrong? slow, errors, down?
  • since when? what changed? (deploy, config, traffic)
  • everyone or some users? one server or all?
  • how bad? users affected now?
  • write times down as you go

2 · The service

Step two, the service itself. systemctl status: is it running, has it restarted? journalctl for the last thirty minutes of its logs, where the cause is often written plainly. curl the health check with timing, which shows the status code and how long it took. And ss shows whether anything is listening on its port at all. These four commands answer most down-or-slow questions in under a minute.

Service checks
$ systemctl status shoprung
$ journalctl -u shoprung
    --since "30 min ago"
$ curl -s -w ' %{http_code}
    %{time_total}s\n'
    localhost:8080/api/health
{"status":"UP",...} 200
$ ss -tlnp | grep 8080

3 · Resources

Step three, if the service looks fine but slow, run the resource pass: uptime for load against the CPU count, dmesg for kernel complaints, vmstat for the run queue and swapping, d f for space and inodes, free for available memory, iostat for disks, and ps sorted by CPU. It is the USE method from episode fourteen in one screen. Now let's apply all of this to four real faults.

One pass
$ uptime          load vs nproc
$ dmesg -T | tail  OOM, disk
$ vmstat 1 5      r, si/so, wa
$ df -h; df -i    space, inodes
$ free -m         available
$ iostat -xz 1    disks
$ ps -eo pid,pcpu,pmem,comm
    --sort=-pcpu | head

Case 1 · CPU contention

Case one, slow but not down. Users saw ShopRung's slowest requests go from one point six to thirteen milliseconds. The resource pass proved it: load climbing towards four on two CPUs, vmstat showing four runnable tasks at ninety nine percent user time, and ps listing six shell loops at about thirty two percent each. We mitigated by renicing them to the lowest priority, which brought the ninety fifth percentile back to four point five. The real fix is asking why batch work runs on the web server at all.

From episode 13 (our runs)
symptom: p95 1.6 ms → 13.0 ms
proof: load rising toward 4 on
  2 CPUs; vmstat r=4, us=99
  ps: six sh loops ~32% each
mitigate: renice -n 19
  → p95 4.5 ms
root cause: why did a batch job
  run on the web server?

Case 2 · Disk full

Case two, a full disk. Symptoms are scattered: write errors, crashes, odd failures in unrelated places. The proof is quick: d f showed zero available, one hundred percent, and writes failed with no space left on device. Find what grew with du, one level at a time, sorted by size. Mitigate by rotating or compressing logs and clearing known caches, never by deleting database files. Then fix it for good: log rotation from episode nineteen and an alert at eighty percent.

From episode 11 (our run)
symptom: errors writing, app
  crashes, odd failures
proof: df -h → 0 avail, 100%
  dd: No space left on device
find it: du -xh --max-depth=1
  / | sort -h | tail
mitigate: rotate or compress
  logs, clear known caches
fix: rotation, alert at 80%

Case 3 · Deleted, full

Case three, someone already cleaned up, and nothing changed. A teammate deleted a huge log, but the disk was still full. lsof plus L one proved a process still held the deleted file: python three, a hundred megabytes, marked deleted. We stopped the holder and usage dropped to twenty four kilobytes. In production, reload the service so it reopens its logs, or truncate the file through slash proc if you cannot restart it.

From episode 4 (our run)
symptom: big log deleted, disk
  still 101 MB used
proof: lsof +L1
  python3 1110 ... 104857600
  /mnt/lab/big.log (deleted)
mitigate: restart/reload the
  holder, or truncate via
  /proc/<pid>/fd/<n>
result: 24K used

Case 4 · OOM kill

Case four, the app dies with no error of its own, and comes back after a restart. The exit code was one three seven, SIGKILL. dmesg said python three invoked the OOM killer, and the cgroup counted one OOM kill at exactly a hundred megabytes. Mitigate by restarting, and raise the limit only if the peak is genuine. The real fix is finding the leak, by graphing the process's resident memory over time.

From episode 12 (our run)
symptom: process vanishes,
  restarts, exit code 137
proof: dmesg: "python3 invoked
  oom-killer"; cgroup oom_kill 1
  at 104,857,600 bytes
mitigate: raise the limit if
  peak is legit; restart
fix: find the leak; RSS graph

4 · Mitigate first

Notice the pattern in all four. First mitigate, so users are fine again: roll back the change, restart, renice, add capacity or fail over. Make one change at a time and note it, then confirm with the same measurement that showed the symptom, like the ninety fifth percentile or d f. Only then hunt for the root cause, calmly, and finally make the change that stops it happening again.

In order
  • mitigate: roll back, restart, renice, add capacity, fail over: users OK again
  • one change at a time, noted
  • confirm with the same measurement as the symptom
  • then root cause, calmly
  • then the fix that stops it happening again

5 · Write it up

Last step, write it up, even for small incidents. What users saw and when. A timeline of detection, mitigation and resolution. The evidence, meaning the commands and numbers that proved the cause. The root cause, and the follow-ups: a new alert, log rotation, a memory limit, a runbook. Keep it blameless. Part twelve turns this into full postmortems. A team that writes these stops having the same incident twice.

A short write-up
  • what users saw, and when timeline: detect, mitigate, resolve (with times)
  • evidence: the commands and numbers that proved it
  • root cause
  • follow-ups: alert, rotation, limit, runbook
  • blameless (part 12)

Common mistakes

Mistakes. Restarting everything first, which destroys the evidence, like the OOM log or the open file. Making several changes at once. Never asking what changed. Deleting open log files or database files under pressure. Trusting a guess without proof. Keeping no notes, so nobody learns. And stopping at the mitigation, so the same fault returns next week.

Avoid these
  • restarting first, so evidence is lost
  • several changes at once
  • not asking "what changed?"
  • rm of open files or DB files
  • trusting a guess without proof
  • no notes, so no learning
  • fixing the symptom only

Say it like this

In the interview: first I scope it: what exactly, since when, what changed, who is affected. Then the service: status, recent logs, and the health check with timing. Then a USE pass over the machine: load against cores, vmstat, d f and d f minus i, free, iostat and dmesg. I mitigate first, one change at a time, confirm with the same measurement, then find the root cause and write it up with follow-ups.

In the interview
  • "I scope it: what, since when, what changed, who is affected.
  • Then the service: status, logs, health check with timing. Then a USE pass: load, vmstat, df, free, iostat, dmesg. I mitigate first, one change at a time, confirm, then find root cause and write
  • it up."

Interview questions

Q1Walk me through troubleshooting a slow server.

Scope (what, since when, what changed, who), check the service (status, logs, health check with timing), run a USE pass (uptime, vmstat, df -h/-i, free, iostat, dmesg, ps by CPU/memory), mitigate one change at a time, confirm with the same metric, find the root cause and write it up.

Q2Why not restart the service first?

Restarting can destroy evidence (OOM messages, open-file holders, stuck threads); capture what you need first unless users are hard down and a restart is the fastest mitigation.

Q3Disk is full: what do you do?

Confirm with df -h and df -i, find growth with du -xh --max-depth=1 | sort -h, check lsof +L1 for deleted open files, free space safely (rotate/compress logs), then add rotation and alerts.

Q4An app restarts with exit code 137. Next steps?

Check dmesg/journalctl -k or kubectl describe for an OOM kill, compare memory limit and RSS over time, raise the limit only for a legitimate peak, and fix the leak.

Q5How do you find what changed?

Deploy and config history, git log, CI/CD runs, package logs (/var/log/apt/history.log), and metrics around the start time.

Q6What is the difference between mitigation and root cause?

Mitigation restores service quickly (rollback, restart, failover, capacity); the root cause is why it happened, fixed afterwards to prevent recurrence.

Q7How do you confirm a fix worked?

Re-measure the same symptom metric (latency percentile, error rate, df) and watch it for a while.

Q8What goes into an incident write-up?

What users saw, a timeline with times, the evidence, the root cause, and follow-up actions, written blamelessly.