Phase 2. Lesson 4 of 4. About 25 minutes.
Plain entry
A spec sheet tells you what a machine can do on its best day. A bottleneckThe single component or resource that limits a system's overall performance, so improving anything else makes little difference until it is fixed. Read more → is whatever is holding it back right now. The skill is to look at a slow machine, find the one part that is at its limit, and fix that instead of buying everything new. This lesson shows you how to watch a machine work and spot it.
Terms
- Bottleneck: the one part limiting the whole system.
- Load averageThree numbers Linux reports showing the average count of processes running or waiting over the last 1, 5, and 15 minutes, used to judge how busy a system is. Read more →: roughly, how many tasks are running or waiting for the CPUCentral Processing Unit: the chip that executes program instructions, measured by its cores, threads, clock speed, and cache. Read more →, averaged over 1, 5, and 15 minutes.
- Swapping: Linux moving memory to disk because RAMRandom Access Memory: the fast, temporary working memory that holds the programs and data a computer is using right now, cleared when power is lost. Read more → is full. When it happens a lot, everything slows down.
- I/O wait: time the CPU spends idle waiting for storage.
- Throughput / latencyThe time delay between sending a request and receiving the first byte of the response, typically measured in milliseconds. Read more →: how much data moves per second, versus how long one request takes. See bandwidth and latency.
Depth
Watch the whole machine
sudo apt install -y htop
htop
Top bars: one per CPU, then Mem, then Swp. Top right: Load average. Press F6 to sort, q to quit.
Rule of thumb for load: if the 5-minute load average stays above your CPU count, the CPU is a bottleneck. On a 2-CPU VMA software-based emulation of a complete computer that runs its own operating system and applications, isolated from the host hardware. Read more →, a load of 0.3 is idle and 4.0 is overloaded.
Find the bottleneck, part by part
vmstat 2 5
Expected output on an idle VM:
procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----
r b swpd free buff cache si so bi bo in cs us sy id wa st
1 0 0 1120384 48212 1540220 0 0 12 8 210 380 2 1 97 0 0
What each column tells you:
rhigh (above CPU count): CPU bound.si/soabove 0 for a while: swapping, need more RAM.wahigh (above 10 to 20): waiting on disk.idnear 100: the machine is not the problem.
Make a bottleneck on purpose
CPU:
sudo apt install -y stress-ng
stress-ng --cpu 2 --timeout 30s &
vmstat 2 5
You should see us near 100 and id near 0 for those seconds.
Memory: run stress-ng --vm 1 --vm-bytes 90% --timeout 30s and watch si/so and the Swp bar in htop climb. (If the VM freezes for a moment, that is what swapping feels like. It recovers when the test ends.)
Disk read speed, safely, no writes:
sudo hdparm -t /dev/sda
Timing buffered disk reads: 1520 MB in 3.00 seconds = 506.43 MB/sec
In a VM, this measures your host’s disk through the virtual layer, so treat it as rough.
Read a spec sheet with this in mind
When you look at any machine, ask four questions:
- How much RAM, and can it be upgraded (slots, or soldered)?
- What storage type: HDD, SATASerial ATA: the long-standing interface for connecting hard drives, SSDs, and optical drives, with a practical speed limit of about 550 MB/s. Read more → SSDSolid-State Drive: storage that keeps data on flash memory chips with no moving parts, making it far faster and more durable than a spinning hard drive. Read more →, or NVMeNon-Volatile Memory Express: a storage protocol built for flash SSDs that talks to the CPU over PCIe, delivering far more speed and lower latency than SATA. Read more →?
- How many CPU cores and what generation?
- What does it actually need to run? A file server needs disk and network; a build machine needs CPU and RAM.
The cheapest real-world upgrade on an old machine is almost always an SSD and more RAM. Flag before buying: BNLC labs never require you to buy parts.
Why it works this way
A machine is only as fast as its busiest part. Upgrading anything else changes nothing until that part stops being the limit. That is why you measure first. Measuring also stops the most common waste in IT: buying hardware for a problem that was one runaway process.
Myth vs fact
Myth: “More RAM always means a faster computer.”
Fact: More RAM helps only when you are running out. Once your programs fit, extra RAM mostly holds disk cache, and Linux uses idle memory for cache on purpose and hands it back the moment a program asks. On the course VM, free -h showed this:
total used free shared buff/cache available
Mem: 2.9Gi 454Mi 2.0Gi 10Mi 582Mi 2.4Gi
Read the available column, not free. If available stays high and vmstat shows si and so at 0, RAM is not your bottleneck and buying more will not help. Your numbers will differ.
Self-check
- Your 4-CPU machine has a 5-minute load of 9. What is the bottleneck?
vmstatshowssoat 2000 for a minute. What does that mean?- Which column in
vmstatpoints at slow storage?
Answers: (1) CPU. (2) It is swapping memory out to disk; it needs more RAM or fewer programs. (3) wa.
Sources
vmstat: https://man7.org/linux/man-pages/man8/vmstat.8.htmlstress-ng: https://manpages.ubuntu.com/manpages/resolute/man1/stress-ng.1.htmlhdparm: https://man7.org/linux/man-pages/man8/hdparm.8.html- Load average explained,
uptime: https://man7.org/linux/man-pages/man1/uptime.1.html - CompTIA A+ Core 1 (220-1201), hardware troubleshooting: https://www.comptia.org/certifications/a
free(1): https://manpages.ubuntu.com/manpages/resolute/man1/free.1.html- Linux ate my RAM: https://www.linuxatemyram.com/
- Linux kernel docs, memory management concepts (page cache): https://www.kernel.org/doc/html/latest/admin-guide/mm/concepts.html