Linux Performance Analysis for Beginners: A Quick Guide
If your Linux system is running slow, how do you find out what's wrong? This guide will help beginners analyze Linux performance step by step using simple tools. In just a minute, you can check CPU, memory, disk, and network performance using a few basic commands.
1. Check System Load (1 Second)
Run:
uptime
Output:
10:45:23 up 5 days, 2:34, 2 users, load average: 0.54, 0.66, 0.72
This shows how long your system has been running and the load average. The last three numbers represent the load over the last 1, 5, and 15 minutes. A high number (greater than the number of CPU cores) means your system is overloaded.
Troubleshooting Scenario:
Issue: Your system feels sluggish, and the load average is high. Solution: Check which processes are using the CPU.
2. Check for System Errors (1 Second)
Run:
dmesg | tail
Output:
[12345.678901] usb 1-1: USB disconnect, device number 3
[12345.679012] usb 1-1: new full-speed USB device number 4 using xhci_hcd
This shows the latest system messages, including hardware errors or crashes. If you see repeated errors, something might be wrong with your hardware or drivers.
Troubleshooting Scenario:
Issue: Your system crashes or behaves strangely. Solution: Check for error messages in dmesg
and investigate further.
3. Check Overall System Performance (1 Second)
Run:
vmstat 1
Output:
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 50000 10000 200000 0 0 5 2 200 500 5 1 94 0 0
This updates every second and shows:
CPU usage
Memory usage
Disk activity
System tasks
If the r
(running tasks) value is high, your system is overloaded.
Troubleshooting Scenario:
Issue: System is slow, but you don't know if it's CPU, memory, or disk-related. Solution: Use vmstat
to see which resource is overloaded.
4. Check CPU Usage Per Core (1 Second)
Run:
mpstat -P ALL 1
Output:
Linux 5.4.0-91-generic (ubuntu)
10:45:23 CPU %usr %nice %sys %iowait %irq %soft %steal %guest %idle
10:45:23 all 10.5 0.0 5.2 0.5 0.0 0.2 0.0 0.0 83.6
This shows CPU usage for each core every second.
If one core is much busier than the others, the workload is not balanced.
High
%usr
means applications are using a lot of CPU.High
%sys
means the system itself is using too much CPU.
Troubleshooting Scenario:
Issue: One CPU core is always at 100%. Solution: Check which process is using it with top
or pidstat
.
5. Check CPU Usage by Process (1 Second)
Run:
pidstat 1
Output:
Linux 5.4.0-91-generic (ubuntu) 02/27/2025
10:45:23 UID PID %usr %system %guest %CPU CPU Command
10:45:23 1000 1234 10.0 2.5 0.0 12.5 1 firefox
This updates every second and shows how much CPU each process is using.
Troubleshooting Scenario:
Issue: The system is slow, and you need to find out which process is the cause. Solution: Run pidstat
to find the most CPU-hungry process.
6. Check Disk Usage (1 Second)
Run:
iostat -xz 1
Output:
Device r/s w/s rkB/s wkB/s await svctm %util
sda 1.24 2.45 100.23 200.56 5.23 1.02 7.5
This shows disk performance:
High
%util
means the disk is very busy.High
await
means disk response time is slow.
Troubleshooting Scenario:
Issue: Applications are slow to load or save files. Solution: Check if the disk is overloaded with iostat
.
7. Check Memory Usage (1 Second)
Run:
free -m
Output:
total used free shared buff/cache available
Mem: 16000 8000 5000 1000 3000 7000
This shows how much memory is used and available.
Troubleshooting Scenario:
Issue: The system is slow, and programs are freezing. Solution: Check if memory is running low with free -m
.
8. Check Network Usage (1 Second)
Run:
sar -n DEV 1
Output:
10:45:23 IFACE rxpck/s txpck/s rxkB/s txkB/s
10:45:23 eth0 120.3 130.4 2000.5 1500.3
Troubleshooting Scenario:
Issue: Internet is slow or lagging. Solution: Use sar -n DEV
to check if your network is overloaded.
9. Check Active Processes and CPU Usage (Real-Time)
Run:
top
Output:
top - 10:45:23 up 5 days, 2:34, 2 users, load average: 0.54, 0.66, 0.72
Tasks: 250 total, 2 running, 248 sleeping, 0 stopped, 0 zombie
...
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
1234 user 20 0 200000 50000 10000 R 12.5 5.0 0:05.32 firefox
10. Capture Short-Lived High-CPU Processes
Run:
perf record -F 99 -a -g -- sleep 10
This command captures system performance data for 10 seconds at 99Hz, helping to identify processes that appear briefly but consume high CPU.
Troubleshooting Scenario:
Issue: A process appears in top
but disappears too quickly to identify. Solution: Use perf record
to capture the activity over time, then analyze the results using perf report
.
Troubleshooting Scenario:
Issue: The system is slow, and you need to find the cause. Solution: Run top
and look at the highest CPU-consuming processes.