NewCode CLOUD — 20% off your first month on all cloud VPSClaim

Troubleshooting High CPU Load on a Linux Server: A Step-by-Step Method

“The server is at 100% CPU” is one of the most common support requests — and the cause is almost always inside the server: a busy PHP site under bot traffic, a slow database query, a runaway process, a backup job, or occasionally malware. This guide gives you a repeatable method to find the cause in minutes rather than guessing.

Step 1: Is it really CPU?

uptime
nproc
top

Compare the load average with the number of cores. Then look at the CPU line in top:

What you see It’s probably
High us (user) Applications: PHP, Node, Java, database
High sy (system) Kernel: lots of network packets, context switching
High wa (I/O wait), low us Disk, not CPU — see step 6
High st (steal) on a VPS The host is busy; contact support if persistent
High load but CPU mostly idle Processes stuck waiting on disk or network storage

Step 2: Which process?

ps aux --sort=-%cpu | head -15

Or in htop, sort by CPU (F6) and enable tree view (F5) to see parent processes — 40 php-fpm children are one problem, not 40.

Note the user and command. Then follow the matching section below.

Step 3: PHP-FPM (WordPress, Laravel, Magento…)

Many busy PHP workers means many PHP requests. The question is why.

Look at the traffic

# Top client IPs in the last 10,000 requests
tail -n 10000 /var/log/nginx/access.log | awk '{print $1}' | sort | uniq -c | sort -rn | head

# Top URLs
tail -n 10000 /var/log/nginx/access.log | awk '{print $7}' | sort | uniq -c | sort -rn | head

# Top user agents
tail -n 10000 /var/log/nginx/access.log | awk -F'"' '{print $6}' | sort | uniq -c | sort -rn | head

Common findings:

  • One IP or a few hammering the site → rate limit or block (Nginx rate limiting, Fail2ban).
  • /wp-login.php or /xmlrpc.php flooded → brute-force attack; protect those URLs.
  • Aggressive crawlers (SEO tools, AI scrapers) → robots.txt crawl-delay for polite bots, block by user agent for others.
  • Search or filter URLs with endless parameters → bots crawling faceted navigation; block or cache.

Find slow scripts

Enable the PHP-FPM slow log in the pool configuration:

request_slowlog_timeout = 5s
slowlog = /var/log/php-fpm-slow.log

It records a stack trace of any request taking more than 5 seconds — usually pointing straight at the plugin or function responsible.

Reduce the cost per request

Full-page caching means anonymous visitors (and most bots) never reach PHP — see WordPress speed optimisation. This is often the single fix that turns 100% CPU into 10%.

Step 4: MySQL / MariaDB

If mysqld or mariadbd is at the top:

sudo mariadb -e "SHOW FULL PROCESSLIST;" | grep -v Sleep

Long-running queries in the list are the immediate cause. Then:

  • Enable the slow query log and find the worst queries — MariaDB tuning.
  • EXPLAIN them and add missing indexes.
  • Check the buffer pool size; a too-small pool turns memory reads into disk reads.
  • Look for a plugin or cron job running heavy reports during business hours.

Step 5: Java, Node.js and other apps

Java: find the busy thread and see what it is doing:

top -H -p PID                     # threads of the Java process; note the busy thread ID
printf '%x\n' THREAD_ID           # convert to hex
jstack PID | grep -A 20 nid=0xHEX

Garbage collection storms (memory too small for the heap) also show as high CPU: check GC logs or jstat -gcutil PID 1000.

Node.js: a single process at 100% of one core usually means a CPU-heavy synchronous operation blocking the event loop (large JSON parsing, crypto, image processing, a regex on big input). Profile with node --prof or clinic.js on a staging copy.

Any process: perf top (package linux-tools-common / perf) shows which functions are using CPU across the whole system.

Step 6: When it’s actually the disk

High load with high wa:

iostat -xz 2
sudo iotop -oPa

Typical causes: swapping (check free -h, vmstat 2), backups or updatedb running, database without enough memory, a log being written furiously. Schedule backups at night with lower priority:

nice -n 19 ionice -c3 /usr/local/bin/backup.sh

Step 7: Processes you do not recognise

Random names, binaries in /tmp or /dev/shm, processes owned by www-data that are not PHP-FPM, and constant 100% CPU even at night are classic signs of a cryptocurrency miner. Killing it is not enough — it will come back. Follow has my server been hacked?.

Step 8: Kernel and network (high sy / si)

High system and softirq time with lots of network traffic can mean a SYN flood or very high packet rates:

ss -s
ss -tan state syn-recv | wc -l
sar -n DEV 1 5        # packets per second (sysstat)

Many half-open connections suggest a SYN flood. Small attacks can be mitigated in the kernel (net.ipv4.tcp_syncookies=1, on by default) and firewall; large ones need upstream protection — DDoS protected hosting.

Quick fixes vs real fixes

Quick relief Real fix
Restart PHP-FPM / the app Find the slow code or the abusive traffic
Block the top IP Rate limiting, caching, bot management
Kill the long query Index it, rewrite it, or move reporting off-peak
Kill the miner Rebuild and close the entry point
Add more CPU Only after confirming the workload is legitimate and optimised

When to upgrade

Upgrade when legitimate, optimised load is consistently high: CPU above ~70% at normal peak, response times rising with traffic, and caching already in place. Cloud VPS plans can be upgraded in place; dedicated servers offer more cores and no “noisy neighbours”. Compare options on the VPS and dedicated server pages.