Performance Problems
Diagnose CPU, memory, and system load issues.
Quick Overview
# System snapshot
uptime
free -h
vmstat 1 5
# Top processes
top -bn1 | head -20High CPU Usage
Identify CPU Hogs
# Top by CPU
ps aux --sort=-%cpu | head -10
# Real-time
top -o %CPU
# Per-CPU view
mpstat -P ALL 1 5
# Process CPU history
pidstat 1 5Diagnose Process
# Process details
ps -p PID -o pid,ppid,%cpu,%mem,cmd
# What's the process doing?
strace -p PID -c
# Threads
ps -T -p PIDCPU Information
# CPU info
lscpu
cat /proc/cpuinfo | grep "model name" | head -1
# Load averages explained
# 1-min, 5-min, 15-min averages
# Values > number of CPUs = overloaded
uptime
nproc # Number of CPUsHigh Memory Usage
Check Memory
# Memory overview
free -h
# Detailed
cat /proc/meminfo
# Per-process
ps aux --sort=-%mem | head -10
# Real-time
top -o %MEMMemory Hogs
# Top memory users
ps aux --sort=-rss | head -10
# Specific process
pmap -x PID
# Shared memory
ipcs -mMemory Issues
# OOM killer activity
dmesg | grep -i "out of memory"
journalctl -k | grep -i oom
# Swap usage
swapon --show
vmstat 1 5 # si/so columns
# Cache/buffers (usually OK to use)
free -h # buff/cache columnHigh Load Average
Understanding Load
# Load average
uptime
cat /proc/loadavg
# Number of runnable processes
vmstat 1 5 # r column
# What's in run queue
ps -eo state,pid,cmd | grep "^R"Common Causes
# I/O wait (blocked on disk)
vmstat 1 5 # wa column
iostat -x 1 5
# CPU bound
mpstat 1 5 # %usr high
# Too many processes
ps aux | wc -lSystem Diagnostics
vmstat Explained
vmstat 1 5
# r: running processes
# b: blocked processes
# si/so: swap in/out (bad if high)
# us: user CPU %
# sy: system CPU %
# id: idle %
# wa: I/O wait % (bad if high)sar (Historical)
# Install sysstat
sudo apt install sysstat
# CPU history
sar -u
# Memory history
sar -r
# I/O history
sar -bQuick Fixes
CPU
# Kill runaway process
kill -9 PID
# Lower priority
renice 19 -p PID
# Limit CPU with cgroups
sudo cgcreate -g cpu:/limited
echo 50000 | sudo tee /sys/fs/cgroup/cpu/limited/cpu.cfs_quota_us
sudo cgclassify -g cpu:limited PIDMemory
# Clear caches (usually not needed)
sync && echo 3 | sudo tee /proc/sys/vm/drop_caches
# Kill memory hog
kill -9 PID
# Adjust OOM score
echo -1000 | sudo tee /proc/PID/oom_score_adj # Protect
echo 1000 | sudo tee /proc/PID/oom_score_adj # TargetDiagnostic Summary
| Metric | Tool | Normal | Problem |
|---|---|---|---|
| CPU | top, mpstat | < 80% | > 90% sustained |
| Memory | free -h | < 80% | Swap active |
| Load | uptime | < num CPUs | > 2x CPUs |
| I/O wait | vmstat | < 10% | > 20% |
- performance
- cpu
- memory
- load
- troubleshooting