Skip to content
Linux system performance · Chapter 3 of 21 Day 1: Methodology – how to ask a performance question

Day 1: Methodology – how to ask a performance question

Goal: reliably tell apart the basic terms latency, throughput, utilization, saturation and errors, measure them in your own lab and know methods that lead to the goal – and those that only look like it · Duration: about 2.5 hours · Prerequisite: Day 0

Where we start

perf1 and last1 are reachable via SSH, the extra disk is mounted under /daten, and fio and stress-ng are installed.

# on perf1
findmnt -no SOURCE /daten

-n without header, -o SOURCE only the column with the device.

Expected:

/dev/sdb
# on perf1
fio --version

Expected:

fio-3.36
# on perf1
stress-ng --version

Expected:

stress-ng, version 0.17.06 (gcc 13.2.0, x86_64 Linux 6.8.0-151-generic)

If /dev/sdb is missing, repeat Drill 4 of Day 0; if a program is missing, Drill 3.

Introduction

Today you do not learn a new tool. You learn to ask the right questions – and that is the harder part. Most performance problems are not solved badly because someone does not know a tool, but because they look at the wrong number: utilization when the issue is waiting time, the average when users complain about outliers, or the CPU because top shows it first.

So today you clarify the terms the whole course works with and measure each of them in your own lab. You will see that a disk can become faster and slower at the same time, that a CPU at 100 % can still be fine – and that at 100 % it can also no longer be fine. Then you learn methods that turn a vague complaint into a question you can test.

Today you learn:

  • to tell apart latency, response time, throughput and IOPS and to see how they are related,
  • why percentiles say more than averages,
  • to tell apart utilization, saturation and errors – the three questions of the USE method,
  • to recognize typical anti-methods that cost time and prove nothing,
  • to narrow down a complaint with the problem statement,
  • to describe a load with workload characterization: who, why, what, how,
  • to use the USE method and the RED method as fixed checklists.

Background

The picture for today: the waiting room

Yesterday you set up the practice. Today you look into the waiting room – almost everything this day explains is in there.

  • How long a treatment takes is the latency. How long the patient was in the practice in total – waiting room plus treatment – is the response time. How many patients are seen per hour is the throughput.
  • If the doctor is busy all the time, she is utilized. If people are sitting in the waiting room, the practice is saturated. Patients who leave untreated are errors.
  • A doctor can be 100 % busy without anyone waiting – then all is well. Only a full waiting room makes every single visit longer.
  • And whoever prescribes pills at “I feel bad” without asking and examining is working with an anti-method.

The terms

Term Meaning In the picture
latency duration of a single operation duration of a treatment
response time latency from the waiting party’s point of view, sum of many parts time in the practice
throughput, IOPS operations completed per unit of time patients per hour
percentile (p99) value below which 99 % of the measurements lie the waiting time almost nobody exceeds
utilization share of time a resource is busy doctor busy
saturation work that has to wait full waiting room
errors failed operations patients who leave
USE, RED checklists for resources and services examination from head to toe

Remember: Utilization says how busy the doctor is. Saturation says how full the waiting room is. Things only get slow because of the waiting room.

Latency, response time, throughput

Latency is the time something waits or takes – depending on whom you ask. In this course: latency is the time a single operation takes, from its start to its end. A read request to the disk, a system call, an HTTP request: each has a latency. It is measured in units of time – milliseconds (ms), microseconds (µs), nanoseconds (ns).

The response time is the latency from the point of view of the one who waits – usually a user. It is the sum of many latencies: network, queue in the web server, compute time, database query, disk. If you want to improve a response time, you need to know which parts it consists of.

Throughput is the amount done per unit of time: requests per second, megabytes per second, packets per second. For disks one speaks of IOPS (I/O operations per second) – input and output operations per second, regardless of their size.

Latency and throughput are related, but not the way you first think. If a system can do several things at the same time, roughly:

throughput ≈ number of concurrent operations ÷ latency of one operation

This is a form of Little’s Law from queueing theory. If an application always waits for a reply before it sends the next request (one operation at a time), and each takes 1 ms, it manages at most 1000 per second – no matter how fast the disk actually is. Only when it sends several requests in parallel does throughput rise. But then the latency of each one rises too, because they have to share the disk. Drill 1 measures this.

Average and percentiles

A disk that answers 99 requests in 1 ms and one in 100 ms has an average latency of just under 2 ms. That sounds good. The user whose page contains the 100 ms request sees it differently. With pages made of a hundred individual requests, it hits almost everyone.

That is why one works with percentiles: the 99th percentile (p99 for short) is the value below which 99 % of all measurements lie. p50 is the median – half lie below it, half above. Average and median can be far apart if a few outliers are very large. Good tools therefore show distributions, for example as a histogram like runqlat on Day 0 or as a percentile table like fio.

Utilization, saturation, errors

Every resource of a computer – CPU, memory, disk, network card, but also a lock or a pool of database connections – can be described with three questions:

  • Utilization: how much of the time was the resource busy? Or, for resources of fixed size such as memory: how much of it is in use? Given in percent.
  • Saturation: how much work is waiting because the resource is busy at the moment? This is usually a queue: threads waiting for a CPU, requests waiting for the disk, memory that first has to be freed.
  • Errors: how many operations went wrong? Failed disk accesses, dropped packets, refused connections.

The difference between utilization and saturation is the most important one of this day. A resource at 100 % utilization is fully busy – but as long as nothing is waiting, nobody is served more slowly. Only when work waits does latency rise. Conversely, a resource can cause waiting time although its average utilization is low: when the load comes in short bursts that the one-minute average smooths out. Drill 2 shows both cases on the CPU.

Errors are often overlooked because they are not in the big charts. Yet they are often the cheapest lead: a network that drops packets forces TCP to retransmit, and each retransmission costs waiting time. A single look at an error counter can save an hour of searching.

Anti-methods

Before getting to good methods, it is worth looking at bad ones. They are widespread because they feel like work:

  • Streetlight method: you look where the light is – with the tools you know. If you only know top, you only find CPU problems. But maybe the problem is in the disk.
  • Random change: you change a setting, see whether things get better, and change the next one. Without a measurement before and after you do not know whether the change helped or whether the load just happened to drop. Changes that achieved nothing often stay behind – and confuse someone later.
  • Blame-someone-else method: “It’s the network.” “It’s the database.” You push the problem to another team without evidence. The team searches, finds nothing, pushes it back.
  • Mindless cookbook: you work through a list of tuning tips from the internet that was written for a different system, a different kernel and a different load.

All four have in common that they start without a question. The methods that follow start with one.

The problem statement

The first and cheapest method: before you start a tool, you ask the person who complains some questions. These often already reveal the cause, surprisingly:

  1. How do you notice that it is slow? Which number, which page, which operation?
  2. Since when? Was it ever fast? Is there a point in time when it tipped over?
  3. What changed during that time? Software, configuration, hardware, load, number of users?
  4. How can it be expressed in numbers? Latency, run time, throughput – before and now.
  5. Does it affect everyone or only some? Other users, other servers, other applications?
  6. What does the environment look like? Which software, which version, which hardware?

The answers to 2 and 3 are often already the solution: “since the update on Tuesday” is a hot lead. The answer to 4 is your later success criterion – without it you do not know when you are done.

Workload characterization

The second method does not look at the system but at the load it has to carry. It asks four questions:

  1. Who generates the load? Which process, which user, which remote address?
  2. Why is the load generated? Which code path, which job, which service?
  3. What are the properties of the load? Reading or writing, large or small blocks, random or sequential, how many requests per second?
  4. How does it change over time? Steady, in bursts, with a daily rhythm?

This method finds the best improvements of all: often the fastest request is the one that is never made. A process that runs unnecessarily, a backup during peak business hours, a cache that is too small and therefore passes every request through to the database – you only see all this if you ask who does what and why.

The USE method

The third method is a fixed checklist across all resources. For every resource you check utilization, saturation and errors – hence the name USE (Utilization, Saturation, Errors). You start with a list of resources:

Resource Utilization Saturation Errors
CPU share of busy time per CPU threads in the run queue, PSI cpu rare (hardware)
main memory share in use swapping, reclaim, PSI memory, OOM memory errors, failed allocations
disk share of time with requests in progress queue, PSI io read/write errors
network card throughput relative to bandwidth packets dropped because of full buffers checksum errors, collisions
software (locks, pools) share of time they are held waiting threads timeouts

From Day 2 you learn which command fills each cell of this table; Appendix A contains the complete list for Linux. The strength of the method: it is complete. You check every resource, not just the one that comes to mind first – and rule out causes instead of guessing them. Its limit: it finds bottlenecks in resources, not in the logic of an application. If a program simply does too much, no resource stands out; it is just utilized.

The RED method

For services instead of resources there is a sister of the USE method. For every service – a web server, an API, a database – you measure:

  • Rate: requests per second,
  • Errors: failed requests per second,
  • Duration: duration of the requests, as a distribution.

RED is the view from outside, USE the one from inside. In operations you combine both: RED tells you that and which service is slow, USE tells you why the machine underneath is.

From coarse to fine

All methods lead to the same approach: first look broadly (which resource, which service, which process?), then deeper (which code path, which system call, which request?). This drill-down also determines the structure of the course: Day 2 shows the broad view in 60 seconds, the resource chapters go deeper, and tracing and eBPF on Days 13 and 14 take you down to the single kernel function.

Drill 1: Latency and throughput on the disk

Where you are: on perf1, in the directory /daten.

What you have afterwards: four measurements that show how parallelism increases throughput and latency at the same time – and a calculation that connects the two.

You read randomly from a file four times for ten seconds, each time with more concurrent requests. You know the fio command from Day 0; the only new thing is that you change the queue depth (--iodepth) – the number of requests that may be in flight at the same time.

Step 1 – Change to the extra disk.

# on perf1
cd /daten

Step 2 – One request at a time.

# on perf1
fio --name=qd1 --filename=/daten/fio-test --size=1G --rw=randread --bs=4k --direct=1 --ioengine=libaio --iodepth=1 --runtime=10 --time_based
  • You know the fio parameters from Day 0, Drill 7. The only new thing is the value of --iodepth, here 1.
  • --name=qd1 gives the run a name of its own, --runtime=10 measures only ten seconds.

fio prints a long report. You need three lines: the one with read: (IOPS), the one with clat (usec) (average latency avg) and the one with 99.00th (p99).

Expected (excerpt – these three lines):

  read: IOPS=1201, BW=4807KiB/s (4922kB/s)(46.9MiB/10001msec)
    clat (usec): min=9, max=404232, avg=763.40, stdev=5512.50
     | 99.00th=[ 10028], 99.50th=[ 17695], 99.90th=[ 58459], 99.95th=[ 93848],

Step 3 – Four at a time. The same command, only --name=qd4 and --iodepth=4:

# on perf1
fio --name=qd4 --filename=/daten/fio-test --size=1G --rw=randread --bs=4k --direct=1 --ioengine=libaio --iodepth=4 --runtime=10 --time_based

Expected (excerpt):

  read: IOPS=8057, BW=31.5MiB/s (33.0MB/s)(315MiB/10005msec)
    clat (usec): min=78, max=102713, avg=461.41, stdev=1312.66
     | 99.00th=[ 3195], 99.50th=[ 6849], 99.90th=[18220], 99.95th=[24773],

Step 4 – Sixteen at a time.

# on perf1
fio --name=qd16 --filename=/daten/fio-test --size=1G --rw=randread --bs=4k --direct=1 --ioengine=libaio --iodepth=16 --runtime=10 --time_based

Expected (excerpt):

  read: IOPS=24.6k, BW=95.9MiB/s (101MB/s)(960MiB/10001msec)
    clat (usec): min=113, max=143563, avg=627.17, stdev=1748.88
     | 99.00th=[ 3589], 99.50th=[ 7635], 99.90th=[22152], 99.95th=[32375],

Step 5 – Sixty-four at a time.

# on perf1
fio --name=qd64 --filename=/daten/fio-test --size=1G --rw=randread --bs=4k --direct=1 --ioengine=libaio --iodepth=64 --runtime=10 --time_based

Expected (excerpt):

  read: IOPS=35.0k, BW=137MiB/s (143MB/s)(1367MiB/10001msec)
    clat (usec): min=562, max=169326, avg=1807.63, stdev=1014.99
     | 99.00th=[ 4228], 99.50th=[ 4817], 99.90th=[ 7635], 99.95th=[11600],

Write the values into a small table, then you see the pattern:

iodepth IOPS average latency p99
1 1,201 0.76 ms 10.0 ms
4 8,057 0.46 ms 3.2 ms
16 24,600 0.63 ms 3.6 ms
64 35,000 1.81 ms 4.2 ms

Step 6 – Interpret. Three observations:

  1. Throughput rises with parallelism – from 1,200 to 35,000 IOPS, almost thirty times as much. Same disk, same file. If you only measure with one request at a time, you think the disk is thirty times slower than it is.
  2. From a certain point only latency rises. From 16 to 64 concurrent requests, throughput grows by 40 %, but the average latency almost triples. The disk (more precisely: everything between fio and the real storage under the hypervisor) is saturated – additional requests wait in a queue.
  3. Little’s Law holds. Divide the parallelism by the average latency: 64 ÷ 1.81 ms = 35,400 per second – measured 35,000. 16 ÷ 0.63 ms = 25,400 – measured 24,600. The formula from the Background section is not theory, it describes your disk.

The first line also stands out: with a single request, the average latency is higher than with four, and p99 is at 10 ms. With so little load, the layers underneath (hypervisor, the host’s storage system) do things that do not matter under more load, such as waking up from a power-saving state. Exactly such effects make measurements under low load unreliable.

Step 7 – Clean up.

# on perf1
rm -f /daten/fio-test

Remember: More parallelism brings throughput until the resource is saturated – after that only waiting time grows. Throughput ≈ parallelism ÷ latency.

If it doesn’t work

  • You cannot find the three lines: the read: line is fairly high up in the report, directly below the line with groupid=0; clat (usec) follows two lines further down, the percentiles below that.
  • Your numbers are completely different: that is fine. On NVMe storage throughput rises into the hundreds of thousands, on a hard disk it stays at a few hundred. You see the pattern – first throughput, then only latency – everywhere.

Save your progress? Sign up for free

Drill 2: Utilization versus saturation on the CPU

Where you are: in two terminals on perf1.

What you have afterwards: two measurements that both show 100 % CPU utilization – only one of which is a problem, and the proof of it.

stress-ng creates load on demand. --cpu N starts N workers, each of which computes without a break. perf1 has four CPUs. With four workers every CPU is therefore fully busy; with eight workers twice as many want to run as there are CPUs.

Step 1 – Four workers on four CPUs. In the first terminal you start the load:

# on perf1, terminal 1
stress-ng --cpu 4 --timeout 40s

stress-ng --cpu 4 --timeout 40s – four computing workers; after 40 seconds everything ends by itself. You do not need what stress-ng prints along the way.

Step 2 – Measure. Wait about 25 seconds so that the load settles. Then in the second terminal:

# on perf1, terminal 2
vmstat 1 5

vmstat 1 5 prints five lines, one per second. Important: the first line shows averages since system start, not the current state. Only the lines from the second one on count for the present.

Expected:

procs -----------memory---------- ---swap-- -----io---- -system-- -------cpu-------
 r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa st gu
 5  0      0 4890352 119336 6969356    0    0    31   124 1865    4  4  1 93  0  1  0
 4  0      0 4890352 119336 6969396    0    0     0     0 4125   63 100  0  0  0  0  0
 4  0      0 4890480 119336 6969396    0    0     0     0 4077   47 100  0  0  0  0  0
 4  0      0 4890480 119336 6969396    0    0     0     0 4099   57 100  0  0  0  0  0
 4  1      0 4890676 119336 6969396    0    0     0   960 4246  135 100  0  0  0  0  0

Right after, while the load is still running:

# on perf1, terminal 2
cat /proc/pressure/cpu

You know /proc/pressure/cpu from Day 0.

Expected:

some avg10=0.00 avg60=0.00 avg300=0.00 total=1612180910
full avg10=0.00 avg60=0.00 avg300=0.00 total=0
# on perf1, terminal 2
uptime

uptime shows how long the system has been running and the load average.

Expected:

 12:12:35 up 2 days,  2:46,  1 user,  load average: 1.58, 0.38, 0.16

You get to know all the columns of vmstat on Day 2. Today three count:

  • r (runnable) – threads that are running or want to run and are waiting for a CPU. Here: 4. With four CPUs this means every worker has its own CPU, nobody waits.
  • us – share of the time in which the CPUs execute program code (user). Here: 100. The CPUs are fully utilized.
  • cs (context switches) – how often per second the kernel switches from one thread to the next. Here about 50 per second, very few: every worker may stay on its CPU.

And PSI says: some avg10=0.00 – in the last 10 seconds not a single thread had to wait for a CPU. 100 % utilization, zero saturation. For the workers this is the best case; for any other program that wants to compute something now it gets tight – but nobody is waiting yet.

Step 3 – Eight workers on four CPUs. Wait until the first run in terminal 1 has finished (the prompt appears again), and about 20 seconds longer. Then start eight workers there:

# on perf1, terminal 1
stress-ng --cpu 8 --timeout 40s

After about 25 seconds you measure the same three values again in the second terminal:

# on perf1, terminal 2
vmstat 1 5

Expected:

procs -----------memory---------- ---swap-- -----io---- -system-- -------cpu-------
 r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa st gu
 9  0      0 4871908 119340 6969404    0    0    31   124 1865    4  4  1 93  0  1  0
 8  0      0 4871908 119340 6969404    0    0     0     0 4135 1383 100  0  0  0  0  0
 8  0      0 4871908 119340 6969404    0    0     0     0 4112 1260 100  0  0  0  0  0
 8  0      0 4871908 119340 6969404    0    0     0     0 4111 1348 100  0  0  0  0  0
 8  0      0 4871908 119340 6969404    0    0     0     0 4126 1366 100  0  0  0  0  0
# on perf1, terminal 2
cat /proc/pressure/cpu

Expected:

some avg10=92.36 avg60=36.92 avg300=9.09 total=1640975360
full avg10=0.00 avg60=0.00 avg300=0.00 total=0
# on perf1, terminal 2
uptime

Expected:

 12:13:36 up 2 days,  2:47,  1 user,  load average: 4.00, 1.19, 0.45

Step 4 – Compare. The us column shows 100 in both runs. If you only look at utilization – and that is exactly what the CPU bar in top and every monitoring system shows first – you see no difference. The difference is elsewhere:

  • r = 8 – twice as many threads want to run as there are CPUs. Four are always waiting.
  • cs ≈ 1,300 instead of 50 – the kernel constantly switches between the workers so that each gets its turn. Every switch costs a little time.
  • PSI some avg10=92.36 – in 92 % of the last 10 seconds at least one thread had to wait for a CPU. That is saturation, and for every worker it means: it needs twice as long for the same computing work.

The value avg60=36.92 is smaller because the last 60 seconds also include the quiet pause before. PSI computes over three time windows (10, 60 and 300 seconds) so that you see whether pressure is building up right now or has been there for a long time. The full line always stays at 0 for the CPU at system level; it only gains a meaning with cgroups on Day 15.

A look at uptime: after 25 seconds with eight workers, the load average is only at 4.00, not at 8. It is a moving average over one, five and fifteen minutes that follows new values only slowly. For the question “Is anything waiting now?” it is too sluggish – Day 3 explains what it measures instead.

Remember: 100 % CPU alone is not a finding. Only r greater than the number of CPUs and PSI some above zero show a full waiting room.

If it doesn’t work

  • r shows more than 8 or us less than 100: something else is running on your VM. You find it with the next drill.
  • PSI shows clearly above 0 in the first run: then another process is computing besides the four workers – or your VM has fewer CPUs than you think. Check with nproc and use as many workers as nproc prints.
  • bash: wait … or the runs overlap: the output of the second run shows r = 12. Wait longer between the runs or end leftovers with pkill stress-ng.

Save your progress? Sign up for free

Drill 3: Characterizing a load

Where you are: on perf1.

What you have afterwards: the four questions of workload characterization answered for a process you “do not know” – and a pitfall of ps you now know about.

First you start a load as if it had come from someone else: as a systemd service running in the background. Then you forget what you did and find it out with the four questions.

Step 1 – Start the “foreign” load.

# on perf1
systemd-run --user --unit=rechner stress-ng --cpu 2 --timeout 90s

systemd-run starts a command as a short-lived systemd service (transient unit).

  • --user creates it in your own user area, without sudo.
  • --unit=rechner gives it the name rechner.service (“calculator”).
  • After that comes the command: two computing workers for 90 seconds.

Expected:

Running as unit: rechner.service; invocation ID: …

From now on you pretend you know nothing about it. You have 90 seconds – wait about 30, then off you go.

Step 2 – How? The load over time.

# on perf1
uptime

Expected:

 12:15:59 up 2 days,  2:50,  1 user,  load average: 1.29, 1.10, 0.52

The three values are the load average over 1, 5 and 15 minutes. The value for one minute is larger than the one for fifteen: the load is rising right now. If it were the other way round, it would be fading – then you might already be too late. This one line roughly answers the fourth question.

Step 3 – Who? The processes with the most CPU time.

# on perf1
ps -eo pid,user,pcpu,etime,comm --sort=-pcpu | head -4

ps lists processes.

  • -e takes all processes, not just those of your own terminal.
  • -o pid,user,pcpu,etime,comm selects the columns: process ID, user, CPU share, elapsed time since start and program name.
  • --sort=-pcpu sorts by CPU share; the minus means descending.
  • head -4 shows the header line and the first three processes.

Expected:

    PID USER     %CPU     ELAPSED COMMAND
  73870 ubuntu    250       00:00 ps
  73867 ubuntu    100       00:29 stress-ng-cpu
  73868 ubuntu    100       00:29 stress-ng-cpu

Two processes named stress-ng-cpu have been running for 29 seconds and use 100 % each – that is, a whole CPU each. That answers “who”: two processes of the user ubuntu.

And then there is ps itself with 250 %. That is the promised pitfall: the %CPU column of ps is not the current consumption but the total CPU time of a process divided by its running time. A process that has only been alive for a fraction of a second and is doing its work right now gets absurd values this way. For long-lived processes the value is an average over their whole life – a service that has been running for weeks and is running amok right now looks harmless. For the current consumption you use top or pidstat (Day 2).

Step 4 – Why? Where does the process come from? The process ID alone does not say who started it. systemd assigns every process to a cgroup, and its path reveals which service it belongs to:

First you need the process ID of the parent process:

# on perf1
pgrep -o -x stress-ng
  • pgrep -x stress-ng searches for processes whose name is exactly (-x) stress-ng – that is the parent process that started the workers (the workers are called stress-ng-cpu).
  • -o (oldest) takes the oldest if there are several.

Expected:

73865

Yours shows a different number. Put yours in below.

# on perf1
ps -o pid,cgroup:70,args -p 73865
  • -p 73865 selects exactly this process.
  • cgroup:70 shows the cgroup in a 70-character-wide column, args the complete command with all arguments (unlike comm, which shows only the name).

Expected:

    PID CGROUP                                                                 COMMAND
  73865 0::/user.slice/user-1000.slice/[email protected]/app.slice/rechner.ser /usr/bin/stress-ng --cpu 2 --timeout 90s

The path ends in rechner.ser… – cut off because of the column width. The rest comes from the file that ps reads:

# on perf1
cat /proc/73865/cgroup

/proc/<PID>/cgroup is the file from which ps reads the CGROUP column.

Expected:

0::/user.slice/user-1000.slice/[email protected]/app.slice/rechner.service

Now you know: the process belongs to the service rechner.service, in the area of the user with ID 1000. That is the answer to “why” – at least as far as the system knows it. Who created the service and what for is something you would now ask the owner in real life. You can look at the service more closely:

# on perf1
systemctl --user status rechner --no-pager | head -8

systemctl --user status shows the state of a service in the user area; head -8 the first eight lines.

Expected:

● rechner.service - /usr/bin/stress-ng --cpu 2 --timeout 90s
     Loaded: loaded (/run/user/1000/systemd/transient/rechner.service; transient)
  Transient: yes
     Active: active (running) since Mon 2026-11-30 22:59:06 UTC; 30s ago
   Main PID: 73865 (stress-ng)
      Tasks: 3 (limit: 14307)
     Memory: 21.9M (peak: 22.3M)
        CPU: 1min 390ms

Transient: yes means: a service that someone started with systemd-run, without a unit file. Tasks: 3 are the parent process and the two workers. CPU: 1min 390ms is the CPU time used: over a minute in 30 seconds – two CPUs fully busy.

Step 5 – What? The properties of the load. The four answers together:

Question Answer
Who? two processes stress-ng-cpu, user ubuntu
Why? service rechner.service, started with systemd-run
What? pure compute load: two CPUs fully busy, hardly any memory (22 MB), no I/O
How? for 30 seconds, rising (load 1 min > 15 min)

With this table you can now decide – a conversation with the owner, a limit (Day 15) or switching it off – instead of enlarging the CPU. After 90 seconds the service ends by itself.

Remember: Before any measure, describe the load: who, why, what, how. A process’s cgroup reveals which service it belongs to – whereas %CPU in ps is a lifetime average.

If it doesn’t work

  • Failed to connect to bus: No medium found with systemd-run --user: your session has no systemd user service of its own, for example because you logged in with su instead of SSH. Log in directly via SSH.
  • ps no longer shows the processes: the 90 seconds are up. Start Step 1 again.
  • error: list of process IDs must follow -p: pgrep found nothing because the service has already ended – the same case.

Save your progress? Sign up for free

Diagnosis task

Today you do not need a command. This message arrives in your ticket system:

“The order page is terribly slow, please make the server bigger urgently!”

Task (15 minutes): write down the questions you ask before you log in to a server. Assign each question to a method from the Background section and think about which answer would already narrow down the problem.

Solution path. A good list follows the problem statement and adds workload characterization:

  1. How do you notice it? – “Submitting the order takes forever.” So it is not “the page” but an operation: submitting, which presumably means writing to the database.
  2. Since when? – “Since this morning.” So it was fast once.
  3. What changed? – “Nothing … except that the new version was deployed last night.” That is the hottest lead, and it speaks against “make the server bigger”.
  4. In numbers? – “It used to be one second, now eight.” That is your success criterion.
  5. Everyone or some? – “All customers, but only when submitting; searching works.” That narrows it down further: reading is fast, writing is slow.
  6. Environment? – which server, which database, which version. Then you know where to log in.

With these answers you start in a targeted way: a RED view of the order service (rate, errors, duration of submitting), then USE on the database server with a focus on disk and locks – and above all a look at the changes in the new version. The request “make the server bigger” is a solution without a diagnosis. It would cost money and probably not change anything about eight seconds for a write to the database.

Challenge

Create a file ~/use-perf1.md on perf1 that makes the USE table from the Background section concrete for your VM: which CPUs are there, how much memory, which disks (sda and sdb separately), which network card? For each cell, enter which command from Days 0 and 1 you already know for it – and mark the cells for which you do not know one yet.

Solution path: from Days 0 and 1 you know vmstat (us, r) and PSI for the CPU, fio as an active test for the disk (which, however, creates load itself and is therefore not a measuring tool in production), and iperf3 (equally active) and ping for the network. You are still missing a command for memory saturation, disk queues in production and all the error rows. Exactly these gaps are filled by Day 2 and Day 3; the complete table is in Appendix A. Keep the file – you extend it on Day 2.

Save your progress? Sign up for free

Checkpoint

# on perf1
ls /daten

Expected: no test file any more (fio-test is deleted). lost+found is a directory that ext4 creates itself, and it belongs there.

# on perf1
pgrep -c stress-ng

Expected: 0 – no load is running any more. -c counts the matches instead of listing them.

# on perf1
cat /proc/pressure/cpu

Expected: in the some line an avg10 close to 0, for example avg10=0.00. If it shows more, something is still running – back to Drill 3.

Test yourself

  1. A disk manages 1,200 IOPS with one request at a time and 35,000 with 64 at a time. Which number is “the performance of the disk”?
  2. The average latency is 2 ms, p99 is 100 ms. Who complains, and why?
  3. Two servers both show 100 % CPU. How do you recognize which one has a problem?
  4. Why do you ignore the first line of vmstat?
  5. ps shows a process with 300 % CPU that is one second old. What is going on?
  6. Which two questions of the problem statement most often already reveal the cause?

Answers:

  1. Neither alone – throughput depends on parallelism. The honest figure states queue depth and latency along with it.
  2. The users whose requests fall into the slowest percent – with pages made of many individual requests, almost all of them. The average hides them.
  3. By the waiting room: r greater than the number of CPUs and PSI some clearly above zero.
  4. It shows averages since system start, not the current state.
  5. %CPU in ps is CPU time divided by running time; for very young processes this gives nonsensical values. For the current consumption use top or pidstat.
  6. “Since when?” and “What changed during that time?”

Interview Note

The question “Is a CPU at 100 % a problem?” is a popular trick question. The best answer is “It depends – on saturation”, with a reason: utilization says how busy a resource is, saturation whether work has to wait. Name the metrics by which you recognize saturation on the CPU (run queue, PSI) and that a batch job at 100 % is running exactly right, while a web server at 100 % with a growing queue is already too late. If you also mention Little’s Law and percentiles, you show that you understand performance as a set of relationships and not as a list of tools.

Enterprise Note

In larger organizations the methods of this day are often more valuable than any tool. The problem statement belongs in the template for performance tickets as mandatory fields (“since when, what changed, number before/after”) – that saves the first hour of every search. Monitoring should show RED metrics with percentiles for services and, for hosts, not only utilization but also a saturation metric per resource; PSI is the simplest way in. And every change made in the name of performance needs a measurement before and after in the change request – otherwise settings whose purpose nobody knows any more pile up over the years.

Summary

  • Latency is the duration of an operation, throughput the amount per unit of time. With more parallelism, throughput rises until the resource is saturated – after that only latency rises. Throughput ≈ parallelism ÷ latency (Little’s Law) was confirmed on your own disk.
  • Percentiles instead of averages: p99 shows the outliers users complain about.
  • Utilization says how busy a resource is, saturation whether work is waiting, errors whether something goes wrong. 100 % CPU without anyone waiting is not a problem; 100 % with r > number of CPUs and high PSI is.
  • The load average follows the load sluggishly; the first line of vmstat shows averages since start; %CPU in ps is a lifetime average.
  • Anti-methods (streetlight, random change, blame someone else, cookbook) start without a question.
  • Problem statement, workload characterization (who, why, what, how), USE for resources and RED for services are the methods that lead to the goal.

Commands at a glance

Command What it does Parameters
fio … --iodepth=N disk load with N concurrent requests --iodepth queue depth
stress-ng --cpu N --timeout 40s N computing workers for a fixed time --cpu number, --timeout duration
vmstat 1 5 system counters, five times at one-second intervals interval, count; first line = since start
cat /proc/pressure/cpu CPU saturation as PSI (10/60/300 s) –
uptime running time and load average (1/5/15 min) –
systemd-run --user --unit=NAME COMMAND start a command as a short-lived service --user user area, --unit name
ps -eo pid,user,pcpu,etime,comm --sort=-pcpu processes by CPU share -e all, -o columns, --sort sort order
ps -o pid,cgroup:70,args -p PID cgroup and complete command of a process -p process, cgroup:70 column width
pgrep -o -x NAME process ID for a name -x exact name, -o oldest, -c count
cat /proc/PID/cgroup cgroup of a process –
systemctl --user status NAME state of a user service --no-pager print directly

Contents

More