--- title: "How to Troubleshoot a Slow Linux Server, Step by Step" author: "Arpan Singh" published: "2026-12-02T04:51:45.957Z" updated: "2026-12-02T04:51:45.957Z" url: "https://zyvop.com/how-to-troubleshoot-a-slow-linux-server-step-by-step-hoeaa" canonical: "https://zyvop.com/how-to-troubleshoot-a-slow-linux-server-step-by-step-hoeaa" tags: ["linux","sysadmin","Troubleshooting","performance","DevOps"] --- # How to Troubleshoot a Slow Linux Server, Step by Step A practical, step-by-step method for finding what is slowing down your Linux server, covering CPU, memory, disk, network, and the commands to prove it. ![Cover image]() ## "The Server Is Slow" Is Not a Diagnosis Someone pings you: the site is crawling, the API is timing out, SSH takes ten seconds to respond. Your heart rate goes up, and the temptation is to start restarting things. Resist it. A slow server is almost always slow for one of four reasons: it is **out of CPU**, **out of memory**, **waiting on disk**, or **waiting on the network** (or on something across the network, like a database). The skill is not knowing a hundred tools. It is checking those four resources in a sensible order and letting the evidence point you to the answer. This guide gives you that order. You will get a 60-second first look, focused checks for each resource, a symptom-to-cause table, four real-world scenarios, and safe habits for working on a production machine under pressure. ## Before You Touch Anything Spend one minute on context. It saves an hour later. 1. **What exactly is slow?** One page, one API endpoint, SSH, everything? 2. **Since when?** A sudden change points to an event. A gradual one points to a leak or growth. 3. **What changed?** Recent deploys, config edits, new cron jobs, traffic spikes, a marketing email. 4. **Is it the server at all?** Check whether the slowness is in the application, the database, DNS, or a third-party API. **Do not restart anything yet.** A restart often "fixes" the symptom and destroys the evidence you need to prevent a repeat. Capture the state first (there is a ready-made script near the end of this guide). ## The 60-Second First Look This is adapted from a well-known performance checklist popularized by Brendan Gregg and the Netflix performance team. Run these in order and read the output before moving on. ```bash uptime # load averages dmesg -T | tail -n 20 # recent kernel messages: OOM kills, disk errors, network drops vmstat 1 5 # CPU, memory, swap, and I/O in one view mpstat -P ALL 1 3 # per-CPU usage pidstat 1 3 # which processes use CPU iostat -xz 1 3 # disk performance free -h # memory sar -n DEV 1 3 # network throughput per interface top # a live overview (press q to quit) ``` Some of these (`mpstat`, `pidstat`, `iostat`, `sar`) come from the **sysstat** package. Install it before you need it: ```bash sudo apt install sysstat htop iotop # Debian / Ubuntu sudo dnf install sysstat htop iotop # Fedora / RHEL / Rocky ``` Now let us read the results, one resource at a time. ## Step 1: Load Average ```bash uptime # 14:02:11 up 41 days, 3:12, 2 users, load average: 9.80, 6.10, 3.40 nproc # how many CPU cores you have ``` The three numbers are the average load over the last 1, 5, and 15 minutes. A rough rule: load roughly equal to or below your core count is fine, and load far above it means work is queuing. - **Rising numbers** (1-minute higher than 15-minute) mean the problem is getting worse right now. - **Falling numbers** mean it may be passing. **Important detail:** on Linux, load includes processes waiting on disk (uninterruptible sleep), not just those using CPU. So a high load does _not_ always mean the CPU is busy. It might mean the disk is. The next steps tell you which. ## Step 2: CPU ```bash top # then press 1 for per-core view mpstat -P ALL 1 3 # per-core breakdown ps aux --sort=-%cpu | head -n 10 # top CPU consumers pidstat 1 3 # CPU per process, sampled over time ``` In `top`, read the CPU line: - `us` **(user) high:** your application code is busy. Find the process and profile it. - `sy` **(system) high:** the kernel is busy. Think heavy system calls, network handling, or too many threads fighting over locks. - `wa` **(I/O wait) high:** the CPU is idle but waiting on disk. Go to the disk section. - `st` **(steal) high:** you are on a virtual machine and the hypervisor is giving your CPU time to someone else. This is a "noisy neighbor" or an undersized instance, not something you can fix inside the VM. - `id` **(idle) high but the server is still slow:** the bottleneck is not the CPU. Also check whether **one core** is pegged at 100% while the others are idle. That points to a single-threaded bottleneck. A 16-core machine will not help a program that can only use one. Inside `top`, handy keys are `P` (sort by CPU), `M` (sort by memory), `H` (show threads), and `1` (per-core view). ## Step 3: Memory ```bash free -h vmstat 1 5 ps aux --sort=-%mem | head -n 10 ``` In `free -h`, ignore the "free" column and look at **available**. Linux uses spare memory for disk caching, so "free" is usually small on a healthy server. "Available" is what applications can actually get. In `vmstat`, watch the `si` and `so` columns (swap in and swap out). **Sustained non-zero values mean the system is actively swapping**, which makes everything dramatically slower because disk is thousands of times slower than RAM. Check whether the kernel has already killed something for lack of memory: ```bash dmesg -T | grep -i -E 'out of memory|killed process' journalctl -k --since '1 hour ago' | grep -i oom ``` If you find an OOM kill, you have your answer: the server ran out of memory, and the killed process (often your database or app) is the casualty. The question becomes "what is using so much?" A process whose memory keeps growing over days is a leak. A sudden jump is usually a traffic spike, a big query, or a bad deploy. ```bash swapon --show # is swap configured, and how much is used? cat /proc/meminfo # full memory breakdown ``` ## Step 4: Disk I/O and Space Disk problems come in two flavors: the disk is **slow** (busy), or the disk is **full**. ### Is the disk busy? ```bash iostat -xz 1 3 # extended stats, hide idle devices ``` Read these columns: - `%util`**:** near 100% means the device is saturated. - `r_await` **/** `w_await`**:** average milliseconds per read or write. High values (tens or hundreds of ms on an SSD) mean requests are queuing. - `aqu-sz`**:** average queue length. A growing queue means demand exceeds what the disk can deliver. Find out who is causing it: ```bash sudo iotop -oa # processes doing I/O, accumulated (interactive) pidstat -d 1 3 # per-process disk reads and writes ``` On cloud servers, also check whether you have run out of **burst credits** (common on small general-purpose instances and volumes). Performance can drop suddenly and look like a mysterious disk problem. ### Is the disk full? ```bash df -h # space per filesystem df -i # INODES per filesystem du -xh / --max-depth=1 2>/dev/null | sort -rh | head -n 10 ``` Two traps catch people here: 1. **Inode exhaustion.** `df -h` shows free space, but `df -i` shows 100% inode usage. This happens when millions of tiny files pile up (session files, mail queues, cache entries). You will see "No space left on device" even with gigabytes free. 2. **Deleted files still held open.** `df` says the disk is full, but `du` cannot find the space. A process is holding a deleted file open, often a rotated log. Find it with: ```bash sudo lsof +L1 # open files with zero links (deleted but still in use) ``` Restarting or reloading that process releases the space. ## Step 5: Network ```bash ss -s # socket summary ss -tan state established | wc -l # count established connections ss -tulpn # what is listening, and who owns it sar -n DEV 1 3 # throughput per interface ip -s link # errors and drops per interface ``` Check the basics first: - **Errors or drops** in `ip -s link` suggest a faulty link, driver problem, or saturated interface. - **Throughput close to the link speed** in `sar -n DEV` means you are out of bandwidth. - **A huge number of connections** in `ss -s` (especially thousands in `TIME_WAIT`) can signal connection churn or exhausted ports. ### Measure where the time goes When a remote service feels slow, break the request into stages: ```bash curl -o /dev/null -s -w 'dns: %{time_namelookup}s connect: %{time_connect}s first-byte: %{time_starttransfer}s total: %{time_total}s\n' https://example.com ``` - Slow **dns** means a resolver problem. - Slow **connect** means a network path or firewall problem. - Slow **first-byte** with fast connect means the remote application itself is slow. ### Hidden limits ```bash ulimit -n # open-file limit for this shell cat /proc//limits # limits of a running process ls /proc//fd | wc -l # how many files/sockets it has open dmesg -T | grep -i conntrack # "table full, dropping packet" ``` If a busy service hits its **file descriptor limit**, it starts refusing connections. If the kernel's **connection tracking table** fills up, it silently drops packets and you see random timeouts. Both look like "the network is flaky" until you check. ## Step 6: Dig Into the Culprit Process Once you know _which_ process and _which_ resource, zoom in. ```bash top -H -p # per-thread view of one process sudo lsof -p # files and sockets it has open sudo strace -f -c -p # summary of system calls (Ctrl + C to stop) systemctl status myservice # state and recent log lines journalctl -u myservice --since '30 min ago' ``` **A warning about** `strace`**:** it can slow the target process dramatically. On a production server that is already struggling, use it briefly or skip it. The same goes for `perf` and other profilers. Do not forget the **application's own logs** and, if a database is involved, its slow query log. Very often the "server" is fine and one bad query is holding everything up. ## Step 7: Logs and Recent Changes ```bash journalctl -p err --since '1 hour ago' # errors only dmesg -T | tail -n 30 # kernel messages sudo tail -n 100 /var/log/syslog # Debian/Ubuntu (/var/log/messages on RHEL) last -n 10 # recent logins ls -lt /etc | head -n 10 # recently modified config files grep CRON /var/log/syslog | tail -n 20 # recent cron activity (Debian/Ubuntu) ``` Ask: did something start at the same time the slowness began? A backup job, a log rotation, a cron task, a deployment, or someone running a heavy report are frequent culprits. ## Symptom-to-Cause Quick Reference | What you see | Likely cause | Next command | | --- | --- | --- | | High load, high `us` CPU | CPU-bound application | `ps aux --sort=-%cpu`, `pidstat 1` | | High load, high `wa` | Disk bottleneck | `iostat -xz 1`, `iotop -oa` | | High load, low CPU use, processes in `D` state | Stuck I/O (disk, NFS, failing hardware) | `ps aux \| awk '$8 ~ /^D/'`, `dmesg -T` | | Low load but app is slow | Waiting on a database, API, DNS, or locks | `curl -w` timing, app and DB logs | | `si`/`so` non-zero, low "available" memory | Memory pressure and swapping | `free -h`, `ps aux --sort=-%mem` | | High `st` (steal) | Noisy neighbor or undersized VM | Resize or move the instance | | High `sy` with many context switches | Too many threads or lock contention | `pidstat -w 1`, `top -H` | | "No space left on device" but `df -h` looks fine | Inode exhaustion | `df -i` | | Disk 100% full but `du` shows less | Deleted file still held open | `lsof +L1` | | Random timeouts, nothing busy | Connection or file-descriptor limits | `dmesg \| grep conntrack`, `ulimit -n` | ## Four Real-World Scenarios ### Scenario 1: Load of 40 on a 4-core server, but the CPU is 70% idle `top` showed very high `wa`. `iostat -xz 1` showed the disk at 100% utilization with long waits, and `iotop -oa` pointed to a nightly backup that had been moved into business hours. **Fix:** reschedule the backup, and run it at low priority with `ionice -c3 nice -n 19 ./backup.sh`. ### Scenario 2: Fine in the morning, crawling by evening `free -h` showed "available" shrinking all day, and `vmstat` showed constant swapping. One application process had grown from 400 MB to 14 GB. **Fix (short term):** restart the service during a quiet window. **Fix (real):** find and fix the leak, and add a memory alert so you hear about it early. ### Scenario 3: "Disk is full" but nothing is large `df -h` showed 100%, while `du` found only a fraction of that. `lsof +L1` revealed a 40 GB log file that had been deleted by log rotation but was still open by the application. **Fix:** reload the application so it releases the file, then configure rotation properly (for example, `copytruncate` or a reload hook). ### Scenario 4: "No space left on device" with 50 GB free `df -i` showed 100% inode use. A misbehaving app had created millions of empty session files. **Fix:** delete the stale files carefully, for example `find /var/lib/app/sessions -type f -mtime +7 -delete`, then fix the app and add a cleanup job. ## Capture Evidence Before You Fix Anything Save a snapshot you can study later (or hand to a teammate). This builds on the Bash scripting skills from earlier in this series. ```bash #!/usr/bin/env bash out="/tmp/snapshot_$(hostname)_$(date +%F_%H-%M-%S).txt" { echo '== uptime =='; uptime echo '== vmstat =='; vmstat 1 5 echo '== top =='; top -b -n 1 | head -n 25 echo '== memory =='; free -h echo '== disk space =='; df -h; df -i echo '== disk io =='; iostat -xz 1 3 echo '== sockets =='; ss -s echo '== kernel log =='; dmesg -T | tail -n 30 echo '== processes =='; ps auxf --sort=-%cpu | head -n 30 } > "$out" 2>&1 echo "Saved to $out" ``` ## Safe Habits During an Incident 1. **Change one thing at a time.** If you change three things and it improves, you have learned nothing. 2. **Take notes with timestamps.** What you ran, what you saw, what you changed. It becomes your post-incident report. 3. **Prefer gentle actions first.** Lower a process's priority with `renice +10 -p ` or `ionice -c3 -p ` before killing it. 4. **Be careful with** `kill -9`**.** Force-killing a database or anything writing to disk can corrupt data. Try a normal `kill` (or a service stop) first. 5. **Do not run heavy diagnostics on a dying box.** `strace`, `perf`, and big `find` commands add load. Keep it light. 6. **Check backups before deleting data to free space.** 7. **Tell people what is happening.** A short status update saves you from a stream of "is it fixed yet?" messages. ## Make It Easier Next Time - **Enable historical data.** The sysstat service records CPU, memory, disk, and network every few minutes, so you can look back at what happened _before_ you logged in. On Debian/Ubuntu, set `ENABLED="true"` in `/etc/default/sysstat`, then run `sudo systemctl enable --now sysstat`. Review it with `sar -u`, `sar -r`, and `sar -q`. - **Set up monitoring and alerts.** Tools such as Prometheus with node\_exporter and Grafana, Netdata, or a hosted service give you graphs and alerts. Alert on **saturation** (queue lengths, swap activity, I/O wait), not only on utilization. - **Learn your baseline.** You cannot spot "abnormal" if you have never seen "normal". - **Put guardrails on services.** systemd can limit a runaway service with settings like `MemoryMax=` and `CPUQuota=`. - **Rotate and clean logs automatically.** Many outages start with a full disk. - **Test under load before launch,** not after. ## The 10 Commands to Memorize ```bash uptime # is the load high or rising? vmstat 1 # CPU, memory, swap, I/O at a glance top # who is using what right now? free -h # how much memory is available? iostat -xz 1 # is the disk saturated? df -h; df -i # is space or inode capacity exhausted? ss -s # what do connections look like? dmesg -T | tail # did the kernel complain? journalctl -p err -n 50 # what do the logs say? pidstat 1 # which process is responsible? ``` ## Final Thoughts Troubleshooting performance is detective work. You do not need to guess, and you do not need to know everything. Check load, then CPU, memory, disk, and network. Let the numbers tell you where the bottleneck is, zoom in on the process, and only then fix it. Practice before you need it. On a healthy test server, run the 60-second first look and learn what normal output looks like. When the real incident comes, you will recognize what is wrong in seconds instead of minutes.