Find the bottleneck on a WordPress server: htop, vmstat, iostat
When a WordPress VPS becomes slow, the first question is which resource runs out: CPU, memory or disk. Three classic tools answer it in a minute, without installing a monitoring stack: htop shows the processes, vmstat the whole system over time, and iostat the disks.
Problem: Pages take seconds to load, the server is “busy”, and it is not clear whether PHP, MySQL, swap or the disk is the cause.
Solution: Look at the load and the top processes in htop, run vmstat 1 to see CPU wait, run queue and swap activity, and use iostat -x 1 to check disk utilisation and latency. Then go to the process that uses the resource.
Install
sudo apt install htop sysstat
vmstat is part of procps and is always there; iostat comes with sysstat.
htop: who uses the CPU and memory
htop
The header shows a bar per CPU core, memory, swap and the load average. F6 sorts (by PERCENT_CPU or PERCENT_MEM), F4 filters by name (php-fpm, mysqld), F5 shows a tree, so you see the PHP-FPM workers under their master process. A load average constantly above the number of cores means the CPU cannot keep up.
vmstat: the whole system over time
vmstat 1 10 # procs ---memory--- --swap-- ---io--- -system- ------cpu----- # r b swpd free si so bi bo in cs us sy id wa st # 6 0 0 210m 0 0 4 80 900 1500 85 10 5 0 0
r processes waiting for a CPU; above the core count = CPU bound b processes blocked on I/O si/so swap in/out per second; anything above 0 for a while = not enough RAM wa % of time the CPU waits for the disk; high = I/O bound st % stolen by the hypervisor; high on a cheap, overbooked VPS
The first line is the average since boot; read the following ones.
iostat: the disks
iostat -x 1 5
%util close to 100 means the device is busy all the time; r_await and w_await (in milliseconds) show how long a request waits. On SSD a few milliseconds are normal, tens are not.
Next step by result
free -h # memory, buff/cache is reusable df -h # a full disk stops MySQL and uploads sudo mysqladmin processlist # long queries running right now ps -o pid,rss,cmd -C php-fpm8.1 --sort=-rss | sed -n 1,10p # memory per PHP worker
CPU bound with many PHP workers: page caching or fewer, better cached queries. Swap activity: fewer PHP-FPM children or more RAM. High I/O wait with mysqld on top: the slow queries and the InnoDB buffer pool size. Basic commands are in Linux commands for WordPress developers.
NOTE: These tools show the moment you look. For problems that happen at night or once a week, let sysstat collect data (ENABLED="true" in /etc/default/sysstat) and read it later with sar, for example sar -u -f /var/log/sysstat/sa15 for the CPU on the 15th.