24/7 Magento, server & cloud support · USA · UK · Europe · Middle East · Asia hello@scripulse.com
Linux10 min read

How to Troubleshoot High CPU Usage on a Linux Production Server

Step-by-step guide to diagnosing high CPU and load on Linux production servers: top, vmstat, mpstat, pidstat, iowait, steal time and PHP-FPM.

High CPU alerts are among the most common pages an on-call engineer receives. The goal is to answer three questions quickly: is it really CPU, what is using it, and why now. This is the sequence we use on production web servers.

1. Confirm what “high” means

Load average is not CPU usage. It counts processes that are running or waiting (including waiting on disk in uninterruptible sleep). Compare load with the number of cores:

uptime
nproc

A load of 8 on an 8-core server can be healthy; on a 2-core server it means work is queuing. Then look at where CPU time is going:

vmstat 1 5
  • us high: application code (PHP, Java, Node) is busy.
  • sy high: kernel work such as networking, context switching or many small syscalls.
  • wa high: CPU is idle waiting for disk. This is a storage problem, not a CPU problem.
  • st high: steal time, meaning the hypervisor is giving your vCPU to someone else. On AWS burstable instances this often means CPU credits are exhausted.
  • r (run queue) consistently above core count: CPU saturation.

2. Find the processes responsible

ps -eo pid,ppid,user,%cpu,%mem,etime,cmd --sort=-%cpu | head -15
top -c          # press 1 for per-core view, P to sort by CPU
pidstat 1 5     # per-process CPU over time (sysstat package)

Check whether one core is pinned (a single-threaded process) or all cores are busy (many workers). mpstat -P ALL 1 shows per-core usage. To see threads inside a process, use top -H -p PID.

3. Common culprits on web servers

PHP-FPM workers

Many busy php-fpm processes usually mean expensive requests or a traffic spike. Enable the slow log to see what they are executing:

; in the pool config
request_slowlog_timeout = 5s
slowlog = /var/log/php-fpm/slow.log

Our PHP-FPM tuning guide covers sizing workers correctly.

Bots and crawlers

Aggressive crawlers, scrapers and credential-stuffing bots can generate thousands of uncached requests. Count top clients and user agents:

awk '{print $1}' /var/log/nginx/access.log | sort | uniq -c | sort -rn | head
awk -F'"' '{print $6}' /var/log/nginx/access.log | sort | uniq -c | sort -rn | head

Rate-limit at the web server or WAF, and make sure cacheable pages are actually cached.

MySQL

If mysqld is at the top, look at running queries:

mysql -e "SHOW FULL PROCESSLIST" | sort -k6 -n -r | head

Long-running queries, missing indexes and lock contention show up here. Enable the slow query log for ongoing analysis.

Cron jobs and indexers

Heavy scheduled tasks — reindexing, imports, report generation, backups — often explain spikes at regular times. Check crontab -l for each user and /etc/cron.d/, and correlate with your monitoring graphs.

Unexpected processes

Unknown processes with high CPU, especially running as the web server user from /tmp or /dev/shm, can indicate a cryptominer after a compromise. Treat this as a security incident.

4. Look deeper when the cause is not obvious

  • perf top shows which functions are consuming CPU, including kernel functions.
  • strace -c -p PID summarises system calls for a process. It adds overhead, so use it briefly in production.
  • For high sy with networking, check connection counts with ss -s.
  • For high wa, use iostat -xz 1 and look at device utilisation and await times.

5. Fix the cause, not just the symptom

Restarting a service may restore service, but capture evidence first (process list, slow logs, graphs). Then address the cause: cache more, block abusive traffic, optimise the query, reschedule heavy jobs, or right-size the server. Finally, add an alert on the leading indicator so you catch it earlier next time.

Need help with a struggling server?

Our Linux and SRE engineers diagnose production performance problems and fix them at the root. Talk to a Linux engineer →

S
Scripulse Engineering Team
Written and reviewed by our Magento, Linux, SRE, cloud and security engineers. About our team.
Let’s talk

Need a reliable engineering partner for your platform?

Tell us what you need. A senior engineer will reply within one business day with a clear next step.

Book a free audit →