Slow server: find what is using your CPU and memory
A slow server usually has one of three causes: a program using the CPU, memory running out, or a busy disk. These commands find it in minutes, before you think about upgrading.
Last updated:
Step 1: look at the overall picture
top sorts programs by CPU, and Shift+M sorts by memory. Compare the load average with your core count: 4 on a four-core server means it is at full capacity.
$ top $ nproc $ uptime
Step 2: has memory run out?
Look at the available column, not free, because Linux uses spare memory as cache. If the system killed a program for lack of memory you will see it in the log, which explains a database stopping suddenly.
$ free -m $ sudo dmesg -T | grep -i "out of memory"
Step 3: is the disk the cause?
If the CPU is quiet but the server is slow, check the disk. A high wa value in top means the CPU is waiting on the disk. iostat comes with the sysstat package, and %util near 100 means a busy disk.
$ iostat -x 2 5Also make sure the disk is not full, since that slows everything down. See the guide on full disks.
Step 4: is it an attack or unusual traffic?
These count connections and show the addresses requesting your site the most. A few addresses with thousands of requests mean crawling or an attack, so block them in the firewall. The log path depends on your web server.
$ ss -tan | wc -l $ sudo awk '{print $1}' /var/log/nginx/access.log | sort | uniq -c | sort -n | tail -n 10
On Windows
Open Task Manager (Ctrl+Shift+Esc) and sort by CPU, memory or disk. Resource Monitor (resmon) gives more detail. Windows updates and antivirus are common causes.
When do you need a bigger plan?
When usage stays high all the time with healthy, tuned programs, not for a short while or because of one stuck program.

