
"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.
What exactly is slow? One page, one API endpoint, SSH, everything?
Since when? A sudden change points to an event. A gradual one points to a leak or growth.
What changed? Recent deploys, config edits, new cron jobs, traffic spikes, a marketing email.
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.
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:
sudo apt install sysstat htop iotop # Debian / Ubuntu
sudo dnf install sysstat htop iotop # Fedora / RHEL / RockyNow let us read the results, one resource at a time.
Step 1: Load Average
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 haveThe 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
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 timeIn 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
free -h
vmstat 1 5
ps aux --sort=-%mem | head -n 10In 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:
dmesg -T | grep -i -E 'out of memory|killed process'
journalctl -k --since '1 hour ago' | grep -i oomIf 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.
swapon --show # is swap configured, and how much is used?
cat /proc/meminfo # full memory breakdownStep 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?
iostat -xz 1 3 # extended stats, hide idle devicesRead 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:
sudo iotop -oa # processes doing I/O, accumulated (interactive)
pidstat -d 1 3 # per-process disk reads and writesOn 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?
df -h # space per filesystem
df -i # INODES per filesystem
du -xh / --max-depth=1 2>/dev/null | sort -rh | head -n 10Two traps catch people here:
Inode exhaustion.
df -hshows free space, butdf -ishows 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.Deleted files still held open.
dfsays the disk is full, butducannot find the space. A process is holding a deleted file open, often a rotated log. Find it with:
sudo lsof +L1 # open files with zero links (deleted but still in use)Restarting or reloading that process releases the space.
Step 5: Network
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 interfaceCheck the basics first:
Errors or drops in
ip -s linksuggest a faulty link, driver problem, or saturated interface.Throughput close to the link speed in
sar -n DEVmeans you are out of bandwidth.A huge number of connections in
ss -s(especially thousands inTIME_WAIT) can signal connection churn or exhausted ports.
Measure where the time goes
When a remote service feels slow, break the request into stages:
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.comSlow 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
ulimit -n # open-file limit for this shell
cat /proc/<PID>/limits # limits of a running process
ls /proc/<PID>/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.
top -H -p <PID> # per-thread view of one process
sudo lsof -p <PID> # files and sockets it has open
sudo strace -f -c -p <PID> # 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
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 | CPU-bound application |
|
High load, high | Disk bottleneck |
|
High load, low CPU use, processes in | Stuck I/O (disk, NFS, failing hardware) |
|
Low load but app is slow | Waiting on a database, API, DNS, or locks |
|
| Memory pressure and swapping |
|
High | Noisy neighbor or undersized VM | Resize or move the instance |
High | Too many threads or lock contention |
|
"No space left on device" but | Inode exhaustion |
|
Disk 100% full but | Deleted file still held open |
|
Random timeouts, nothing busy | Connection or file-descriptor limits |
|
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.
#!/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
Change one thing at a time. If you change three things and it improves, you have learned nothing.
Take notes with timestamps. What you ran, what you saw, what you changed. It becomes your post-incident report.
Prefer gentle actions first. Lower a process's priority with
renice +10 -p <PID>orionice -c3 -p <PID>before killing it.Be careful with
kill -9. Force-killing a database or anything writing to disk can corrupt data. Try a normalkill(or a service stop) first.Do not run heavy diagnostics on a dying box.
strace,perf, and bigfindcommands add load. Keep it light.Check backups before deleting data to free space.
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 runsudo systemctl enable --now sysstat. Review it withsar -u,sar -r, andsar -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=andCPUQuota=.Rotate and clean logs automatically. Many outages start with a full disk.
Test under load before launch, not after.
The 10 Commands to Memorize
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.
Comments0
Log in to join the discussion.
No comments yet.