High CPU usage caused by WordPress

WordPress is a content management system written in PHP. This means that the content it serves is generated dynamically by a set of PHP scripts: every time a visitor arrives at your website, WordPress processes the request and generates a response.

Clearly, responding to a request implies a certain use of server resources: one has to look at the request itself, determine what the visitor wants to access, fetch it from the database, generate the HTML response, and so on.

With this in mind it is not difficult to find out what are the reasons why we can see high CPU usage on the server:

– You get too many requests. If a lot of users come to your website at the same time, or you receive many illegitimate requests (someone’s probably attacking your site), WordPress will have to process all those requests and, therefore, the use of server resources will increase.

– Requests are slow to resolve. If you have a lot of plugins installed or some of your plugins is inefficient for whatever reason, all the requests you get will take longer than needed, because WordPress will run a lot of inefficient code.

Analyzing the problem

First you need to locate the website which is causing the problem, especially if you have more then one WordPress sites installed.

For the purpose, please check the Statistics block on the hosting control panel home page (Dashboard). If you sort the sites by Hits you can easily locate the most visited one.

Then you can find more details about the traffic and if there is any unusual behavior from the Web Statistics section of your control panel. 

Another great tool to locate a high resource consuming website is the MySQL Stats 

After that you have to identify why CPU usage has increased on our website. Has the number of requests to our website increased? Is it now slower to serve individual requests?

Solving the problem

Once of the first things you should try is to get a cache plugin installed. Once of the most popular ones is W3 Total Cache 

This great plugin also allows you to to setup Memcached for your WordPress for additional optimization. Check out our WordPress with Memcached article. 

Another great tool to analyze your WordPress performance is the Query Monitor plugin. 
It enables debugging of database queries, PHP errors, hooks and actions, block editor blocks, enqueued scripts and stylesheets, HTTP API calls, and more.

Sometimes the reason for high CPU usage could be the so called Bad Bots. Bad bots are any bot that hit your website at no benefit to you. These bots consume server resources especially if they hit your website or wp-login page excessively.

One of the great plugins lately is Wordfence and using this plugin you can easily view and block any of those bots and add an extra layer of security to your WordPress along the way.
Wordfence includes an endpoint firewall and malware scanner that were built from the ground up to protect WordPress.

Please check the official WordPress optimization instructions page as well. 

Leave a Reply

Your email address will not be published. Required fields are marked *