28.1. Building an Evidence-Based Investigation
A performance complaint is not yet a problem statement. "The web server is slow" could mean that name resolution takes a second, that the TLS handshake is delayed, that one backend query waits on a lock, that the disk queue is full, or that the host is stealing CPU from the guest. The first task is to choose a measurement that can distinguish those cases, and to know what the number should look like when the system is healthy. Figure 28.2 shows the loop that the rest of the chapter repeats.
Figure 28.2. Conceptual investigation loop. A change is not evidence until the same measurement is repeated and the previous state can be restored.
28.1.1. Defining Symptoms, Baselines, and Service Expectations
Write down the symptom in the terms the user experiences it: which request, which account, which time window, and how often. Then attach a service expectation: a login should complete in under two seconds, a nightly backup should finish before 05:00, free space should stay above 15 percent, or the monitoring target should answer within one scrape interval. Without an expectation, "high" and "low" are opinions.
The host baseline is the next layer. Read the load, memory, and service state before introducing load, so that a later number has a reference:
$ uptime
23:23:29 up 1:16, 1 user, load average: 0.21, 0.57, 0.85
Load averages are exponential moving averages over one, five, and fifteen minutes. On this two-vCPU guest the one-minute value of 0.21 is well below the CPU count, which is an idle baseline; the higher five- and fifteen-minute values still carry the earlier package installation, because longer windows decay more slowly. A load average by itself does not say whether tasks are runnable, blocked on I/O, or waiting in an uninterruptible sleep; Sections 28.2 and 28.4 separate those cases.
$ free -h
total used free shared buff/cache available
Mem: 1.9Gi 319Mi 1.2Gi 2.7Mi 547Mi 1.6Gi
Swap: 0B 0B 0B
free distinguishes free from available: the latter estimates memory that
can be given to a new workload after reclaiming page cache. The baseline has no
swap, so any later si/so activity is a deliberate change rather than normal
operation. A service baseline is equally concrete:
$ systemctl status nginx --no-pager
● nginx.service - A high performance web server and a reverse proxy server
Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; preset: enabled)
Active: active (running) since Mon 2026-11-23 23:22:46 UTC; 46s ago
Invocation: 915e6a545ebd403f854246f1fa812eaf
Docs: man:nginx(8)
Main PID: 17891 (nginx)
Tasks: 3 (limit: 2316)
Memory: 3M (peak: 3.3M)
CPU: 33ms
CGroup: /system.slice/nginx.service
├─17891 "nginx: master process /usr/sbin/nginx -g daemon on; master_process on;"
├─17892 "nginx: worker process"
└─17894 "nginx: worker process"
The unit is active, has two worker processes, and has consumed almost no CPU. If a later test shows a long request but this unit is not using CPU, the delay is probably elsewhere - in DNS, the backend, or the network. That is already a useful exclusion. Record the baseline in the same place as the incident notes; a graph without a known healthy state is only decoration.
The general-purpose sampling tools have short option sets that are worth learning once:
| Option | Description |
|---|---|
vmstat 1 3 |
Print three samples one second apart; the first line is the average since boot. |
vmstat 5 2 |
Print two samples five seconds apart; each line covers the longer interval. |
mpstat -P ALL 1 2 |
Report per-CPU utilization for two one-second intervals. |
pidstat 1 2 |
Report per-process CPU use for two intervals. |
pidstat -d 1 2 |
Add per-process read and write rates and I/O delay. |
iostat -xz 1 2 |
Show extended device statistics with two one-second samples. |
sar -u 1 5 |
Sample CPU counters live, five times. |
28.1.2. Rates, Percentiles, Saturation, and Measurement Intervals
Counters are cumulative; rates are differences divided by time. A counter that
reaches 1000 tells you nothing until you know whether it rose by 10 or by 1000
during the interval. vmstat does that division for you, and the interval
changes the answer:
$ 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 gu
1 0 0 1282228 15580 544908 11 122 9681 4174 631 4 6 2 74 18 0 0
0 0 0 1282148 15580 544928 0 0 0 0 191 192 0 0 100 0 0 0
0 0 0 1282148 15580 544928 0 0 0 12 120 118 0 0 100 0 0 0
The first block is an average since boot: it includes the package installation and filesystem activity that has already finished. The next two one-second samples show the idle baseline. Sampling the same system over five seconds smooths short bursts into a different picture:
$ vmstat 5 2
procs -----------memory---------- ---swap-- -----io---- -system-- -------cpu-------
r b swpd free buff cache si so bi bo in cs us sy id wa st gu
1 0 0 1281904 15588 544936 11 122 9673 4170 631 4 6 2 74 18 0 0
0 0 0 1281904 15596 545012 0 0 11 22 305 452 1 0 97 2 0 0
Both are correct. The one-second view shows that the system was idle at that instant; the five-second view says the interval average was mostly idle. For a user-visible symptom that lasts a few hundred milliseconds, a one-minute sample can miss it entirely. For capacity planning, a one-minute or five-minute sample is more stable and cheaper to store. Match the interval to the symptom, and do not compare samples taken at different intervals as if they were the same measurement.
An average hides the tail that users feel. The backend used in these examples
is a small Python HTTP server; its /slow path sleeps 250 ms and its
/variable path sleeps a random 50–300 ms. The script is backend.py in the
performance workspace:
#!/usr/bin/env python3
import random
import time
from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer
class Handler(BaseHTTPRequestHandler):
def do_GET(self):
if self.path.startswith("/slow"):
time.sleep(0.25)
elif self.path.startswith("/variable"):
time.sleep(random.uniform(0.05, 0.30))
body = b"backend ok\n"
self.send_response(200)
self.send_header("Content-Type", "text/plain")
self.send_header("Content-Length", str(len(body)))
self.end_headers()
self.wfile.write(body)
def log_message(self, fmt, *args):
pass
ThreadingHTTPServer(("127.0.0.1", 8080), Handler).serve_forever()
Run it as john in a second terminal; it stays in the foreground and produces no output, because its request-logging method is suppressed. Stop it with Ctrl+C. The following script makes thirty requests to its variable-delay endpoint and writes the samples:
#!/usr/bin/env bash
set -euo pipefail
for _ in $(seq 1 30); do
curl -s -o /dev/null -w '%{time_total}\n' http://127.0.0.1:8080/variable
done
Run it from john's performance workspace and write the samples to a file. The redirection writes the file, so the command itself prints nothing:
$ bash request-samples.sh > samples.txt
The summary script reads those numbers, sorts them, and reports the mean and the upper percentiles:
#!/usr/bin/env python3
import statistics
import sys
values = sorted(float(line) for line in open(sys.argv[1]) if line.strip())
if not values:
raise SystemExit("no samples")
print(
f"n={len(values)} mean={statistics.fmean(values):.3f}s "
f"p50={values[int(len(values) * 0.50) - 1]:.3f}s "
f"p95={values[int(len(values) * 0.95) - 1]:.3f}s "
f"max={values[-1]:.3f}s"
)
$ python3 summarize-latency.py samples.txt
n=30 mean=0.178s p50=0.176s p95=0.263s max=0.290s
The mean is 178 ms, but the 95th percentile is 263 ms and the maximum is 290 ms: one request in twenty took roughly 90 ms longer than the median. A service objective stated as "the mean is below 200 ms" is met by this sample while its slowest five percent approach 300 ms; an objective stated as a percentile, such as "95 percent of requests under 300 ms," describes the tail the users feel. Neither form is universally better, but the choice must be deliberate. Percentiles also need enough samples: thirty observations make the 95th percentile an interpolation between the top two values, not a precise estimate. High-traffic services should compute percentiles from histograms over a known window rather than from a handful of manual requests.
Saturation is the third axis. Utilization says how busy a resource was;
saturation says whether work had to wait. A disk at 100 percent utilization may
still serve a queue of one request promptly, while a disk at 60 percent
utilization with a deep queue can have terrible latency. Section 28.4 reads
both %util and aqu-sz; Section 28.2 reads run queues and pressure stall
information for the same reason. A useful measurement therefore has a rate, a
distribution, and a saturation indicator, all over the same interval.
28.1.3. Correlating Application Metrics with Host Activity
Application metrics and host metrics are only comparable when they share a time window. The next command sends one request to the slow path and records the total time:
$ curl -s -o /dev/null -w '%{time_total}\n' http://127.0.0.1:8080/slow
0.251258
A single 251 ms result correlates with the backend's own delay. To decide whether the host contributed, run the same request while sampling the process, the run queue, and the disk:
$ pidstat -p $(pgrep -f 'backend.py' | head -1) 1 3
Linux 6.12.86+deb13-amd64 (perf1) 11/24/26 _x86_64_ (2 CPU)
00:32:04 UID PID %usr %system %guest %wait %CPU CPU Command
00:32:05 1001 33468 0.00 0.00 0.00 0.00 0.00 0 python3
00:32:06 1001 33468 0.00 0.00 0.00 0.00 0.00 0 python3
00:32:07 1001 33468 0.00 0.00 0.00 0.00 0.00 0 python3
Average: 1001 33468 0.00 0.00 0.00 0.00 0.00 - python3
The process is idle; the delay is in the application's sleep, not in CPU
contention. If the same request instead showed
high %wait or a run queue larger than the CPU count, the host would be a
candidate. The correlation rule is simple: the application interval and the
host interval must overlap, and the host measurement must be specific enough to
identify the process or cgroup. pidstat -p does that; a whole-system vmstat
line does not.
A practical investigation records four things for each observation: the exact command, the time, the identity and working directory of the caller, and the service state at the time. The rest of this chapter supplies the commands; the record is what makes a later comparison possible.