Is your VPS running at 100% CPU usage? High or constant CPU usage can cause slow performance, failed services, or even downtime. This guide will help you diagnose the cause and take steps to fix it.
Step 1: Connect to Your VPS
Start by logging in via SSH:
ssh root@your_server_ip
Step 2: Check System Load
Use the top or htop command to see real-time CPU usage:
Basic: Using top
top
Press P to sort by CPU usage.
Advanced: Using htop
If not installed:
apt install htop # Debian/Ubuntu
yum install htop # CentOS/RHEL
Then run:
htop
This gives a color-coded overview of CPU, memory, and process usage.
Step 3: Identify the High-CPU Process
In top or htop, look for:
• COMMAND using the most CPU
• USER running it
• PID (process ID)
You can also use:
ps -eo pid,ppid,cmd,%mem,%cpu --sort=-%cpu | head
Step 4: Common Causes of High CPU Usage
Cause |
Solution |
---|---|
Apache or Nginx overload |
Check traffic or limit worker processes |
PHP-FPM or scripts looping |
Check code or restart PHP |
MySQL/MariaDB consuming CPU |
Optimize queries or restart the service |
Background cron jobs |
Check crontab and adjust schedule |
Malware or brute-force attacks |
Install fail2ban or scan with rkhunter or chkrootkit |
Compiling processes |
Wait for completion or limit CPU via cpulimit |
Step 5: Restart or Stop the Offending Process (Temporary Fix)
Once you identify the high-CPU process, restart or kill it:
systemctl restart service-name
Or:
kill -9 PID
Replace PID with the actual process ID.
Step 6: Prevent Future CPU Spikes
Use cpulimit to throttle specific processes:
cpulimit -p PID -l 30
Use nice or renice to lower a process priority:
renice 19 -p PID
Monitor usage with top, htop, or uptime:
uptime
Shows load averages — if it’s consistently over the number of CPU cores, your VPS is overloaded.
Step 7: Check for Malware or Abuse
Install and run a rootkit or malware scanner:
apt install rkhunter
rkhunter --check
Or check for suspicious scripts in /tmp, /dev/shm, and crontab entries:
crontab -l
Step 8: Consider a VPS Upgrade
If your applications are optimized and clean, but you’re consistently hitting CPU limits, it may be time to:
• Add more CPU cores
• Upgrade to a larger VPS plan
• Use a load balancer or move heavy tasks to a separate VPS
Conclusion
High CPU usage can result from overloaded services, poorly optimized scripts, or malicious activity. By monitoring usage and taking targeted action, you can keep your VPS running smoothly.
If you’re unable to diagnose the issue or need help upgrading your VPS, contact Hosteons Support or access your server through https://vps.hosteons.com.