Reduce High CPU Usage In WordPress

High CPU usage in WordPress can be caused by various factors, and here’s how each of the solutions provided can address these causes:

  1. Heartbeat API: The Heartbeat API, which triggers AJAX requests at regular intervals, can contribute to high CPU usage, especially on busy websites. By disabling or limiting the frequency of Heartbeat API requests using a plugin like Heartbeat Control, you can reduce the strain on the server’s CPU.
  2. Inefficient Plugins: Some plugins may execute resource-intensive operations or inefficient code, leading to high CPU usage. By identifying and deactivating such plugins, or optimizing their code, you can alleviate the strain on the server’s CPU.
  3. Poorly Coded Themes: Similarly, poorly coded themes can execute inefficient code or load unnecessary resources, causing high CPU usage. Switching to a lightweight and well-optimized theme or optimizing the existing theme can help reduce CPU usage.
  4. Caching Mechanisms: Implementing caching mechanisms such as page caching, object caching, and browser caching can reduce the number of requests reaching the server and the CPU load associated with generating dynamic content. This improves overall performance and reduces CPU usage.
  5. Insufficient Server Resources: If your website exceeds the resources provided by your hosting plan, such as CPU and memory limits on shared hosting, it can lead to high CPU usage. Upgrading to a plan with more resources, such as a VPS or dedicated server, can alleviate CPU constraints.
  6. Database Queries: Slow or inefficient database queries can significantly contribute to high CPU usage. Optimizing database queries using plugins like WP-Optimize or WP-DBManager can reduce the time spent processing database requests and lower CPU usage.
  7. Outdated Software: Outdated WordPress core, themes, and plugins may contain performance issues or security vulnerabilities that can lead to high CPU usage. Keeping your WordPress installation and plugins up to date ensures that you have access to the latest optimizations and security patches.
  8. Content Delivery Network (CDN): Implementing a CDN can reduce the load on your server’s CPU by serving static content from servers closer to your visitors, offloading bandwidth and reducing the number of requests handled by your server.

To address high CPU usage caused by the HeartBeat plugin, you can try the following steps:

  1. Disable or Limit Heartbeat: You can use the Heartbeat Control plugin to disable or limit the frequency of Heartbeat API requests. Set the interval to a higher value or completely disable it if it’s not essential for your website’s functionality. This can significantly reduce CPU usage. You can set Override Heartbeat frequency to 60 For all options in General settings in Heartbeat Control by WP Rocket plugin.
  2. Optimize Other Plugins: Apart from Heartbeat, other plugins might also contribute to high CPU usage. Identify and deactivate any plugins that are resource-intensive or unnecessary. Use a performance profiling plugin like Query Monitor to identify which plugins are causing the most load.
  3. Optimize Your Theme: Similarly, poorly coded themes can also contribute to high CPU usage. Consider switching to a lightweight and well-optimized theme, or optimize your existing theme by removing unnecessary features, scripts, and styles.
  4. Use Caching: Implement caching mechanisms such as page caching, object caching, and browser caching to reduce the load on your server. Popular caching plugins like W3 Total Cache or WP Super Cache can help improve performance and reduce CPU usage.
  5. Upgrade Your Hosting Plan: If you’re on a shared hosting plan, consider upgrading to a VPS or dedicated server with more resources. This will provide your website with more CPU and memory resources to handle traffic spikes and resource-intensive tasks.
  6. Monitor Server Resources: Use server monitoring tools to keep an eye on your server’s resource usage. This will help you identify any spikes in CPU usage and take appropriate action to optimize your website’s performance.
  7. Optimize Database Queries: Slow database queries can also contribute to high CPU usage. Use a database optimization plugin like WP-Optimize or WP-DBManager to clean up your database and optimize queries for better performance.
  8. Update WordPress and Plugins: Make sure that WordPress core, themes, and plugins are up to date. Developers often release updates to improve performance and fix security vulnerabilities.
  9. Consider a Content Delivery Network (CDN): Implementing a CDN can offload some of the server’s workload by serving static content from servers closer to your visitors, reducing the strain on your server.

By implementing these steps, you should be able to reduce CPU usage caused by the HeartBeat plugin and improve the overall performance of your WordPress website.

You can also put the following code in your .htaccess file to prevent Bots.

RewriteEngine On
RewriteCond %{HTTP_USER_AGENT} ^(.*)MJ12bot/v1.4.8(.*)$ [NC]
RewriteCond %{HTTP_USER_AGENT} ^(.*)AhrefsSiteAudit/6.1(.*)$ [NC]
RewriteRule ^.* - [F,L]

Fix common WordPress issues