Fixing High CPU Usage in Plesk Servers

High CPU usage on a Plesk server can significantly affect its performance and may lead to service interruptions. To resolve this issue, you need to diagnose the root cause and implement the appropriate fixes. Here’s a step-by-step approach:

1. Identify the Processes Using High CPU

The first step is to identify which processes are consuming the most CPU resources on your server. You can do this via command line or through Plesk’s monitoring tools.

Using Command Line:

  • Log into your server via SSH as the root user.
  • Run the following command to identify resource-hogging processes:
top
  • This command displays the processes using the most CPU. You can press P to sort by CPU usage.
  • If you want a more detailed process list, use:
ps aux --sort=-%cpu

Using Plesk:

  • Plesk also has a resource monitoring tool where you can view CPU usage by clicking on Tools & Settings > Server Health.
  • This will give you an overview of CPU load over time.

2. Check for Abnormal Traffic or Attacks

High CPU usage could be caused by an external attack, such as a Distributed Denial of Service (DDoS), or an abnormal surge in traffic.

  • Check the server’s logs for unusual patterns in traffic, especially around the time when CPU usage spikes.
  • Review the Apache or Nginx logs:
    • Apache: /var/log/httpd/access_log (or /var/log/apache2/access_log)
    • Nginx: /var/log/nginx/access.log
  • You can also use tools like netstat to identify high numbers of open connections:bashCopy code
netstat -an | grep ESTABLISHED | wc -l

If you suspect a DDoS attack, implement firewall rules or use services like Cloudflare to block malicious traffic.

3. Review Resource-Intensive Websites or Applications

Certain websites, applications, or scripts may consume excessive resources. Review these components to identify any issues.

  • WordPress and other CMS: These often have plugins or themes that can be inefficient and consume excessive resources.
  • Database-intensive Applications: Applications that rely heavily on databases (e.g., WordPress, Magento) can cause high CPU usage, particularly if the database queries are not optimized.
  • Check MySQL or MariaDB (depending on your server configuration):
    • Run the following command to analyze the database:
mysql -u root -p -e "SHOW PROCESSLIST;"
  • Look for long-running queries that may be consuming excessive CPU.

4. Optimize Web Server Configuration

Web servers such as Apache and Nginx can be optimized for better performance.

  • Apache:
    • Enable caching (mod_cache, mod_expires).
    • Use KeepAlive with proper configuration.
    • Adjust the number of worker processes based on server capacity (MaxClients in Apache).
  • Nginx:
    • Ensure that the worker processes are configured efficiently by adjusting the worker_processes and worker_connections directives in the configuration file.
    • Enable caching for static content.

5. Review Server’s Hardware Resource Allocation

Ensure your server’s resources are sufficient for the current load:

  • Increase RAM: If the server is running out of memory, it could cause CPU to spike as processes get swapped to disk.
  • Upgrade CPU: If the server is consistently under heavy load, consider upgrading to a more powerful CPU.
  • Consider SSD: If you are still using traditional hard drives, upgrading to SSDs can significantly improve I/O performance, thus reducing CPU load.

6. Check Running Services

Some services on the server may be consuming unnecessary resources. For example, backup services, email processing (e.g., spam filtering), or security tools may be resource-intensive.

Check for cron jobs that run frequently and may be consuming CPU. Review the cron logs:

Review Plesk extensions that are enabled, such as anti-virus, backup, or other monitoring tools. Consider disabling or optimizing them.

cat /var/log/cron

7. Check for Malware or Malicious Scripts

Malware or scripts running on your server can cause high CPU usage. Ensure that your server is secure.

  • Run a malware scan to check for any malicious scripts or files using Plesk’s security tools or third-party software like ClamAV or Imunify360.
  • If malware is detected, immediately quarantine and remove the malicious files.

8. Update Software and Plesk

Ensure that both Plesk and your server software (including Apache, Nginx, MySQL, PHP, etc.) are up to date. Outdated software may have bugs or inefficiencies that lead to high CPU usage.

  • Update Plesk:
plesk installer update

Update server software:

apt-get update && apt-get upgrade  # For Ubuntu/Debian
yum update                      # For CentOS/RHEL

9. Adjust PHP Settings

PHP processes can sometimes consume too much CPU, especially with inefficient scripts. Consider the following optimizations:

  • Increase the memory_limit in PHP configuration.
  • Optimize the number of PHP-FPM workers if using PHP-FPM.
  • Review PHP error logs for issues such as excessive errors or warnings that might indicate poorly performing scripts.

10. Restart Services or Reboot the Server

After making optimizations or changes, restarting services can help reduce CPU load temporarily and apply new configurations:

  • Restart the web server (Apache/Nginx) and database (MySQL/MariaDB):
service apache2 restart      # Apache
service nginx restart        # Nginx
service mysql restart        # MySQL/MariaDB

If needed, reboot the entire server:

reboot

11. Monitor and Set Alerts for CPU Usage

After resolving the issue, set up regular monitoring and alerts to proactively detect future high CPU usage.

  • Plesk provides monitoring tools in Tools & Settings > Server Health.
  • Use external monitoring services like UptimeRobot, Pingdom, or New Relic to get alerts about high CPU usage.

Conclusion

By following these steps, you should be able to diagnose and resolve high CPU usage issues on your Plesk server. Identifying the root cause—whether it’s inefficient scripts, an overload of traffic, or poorly configured services—is key to ensuring smooth and efficient server operation. Regular monitoring and updates will also help keep CPU usage under control in the future.