As websites grow, it is possible to exceed the resources that your current web hosting plan offers. When this occurs, it can lead to performance problems for your site, causing it to load slowly, or in extreme cases, an outage may occur.
Excessive resource usage can occur for various reasons, including an overwhelming number of visitors accessing your site, poorly coded scripts, malware, outdated software, and other factors.
Let’s take a look at these factors and how we can fix them.
Common Resource Usage Problems
High Traffic
Normally, high traffic is a great thing to have, but the more visitors accessing your content means more resource usage. As such, many customers need to upgrade their web hosting plan to handle the increased traffic their website brings in.
The only other way to handle periods of high traffic is to utilize a Content Delivery Network (CDN). A CDN is a third-party service that stores copies of your website on additional servers that are closer to the user accessing your site. This means they will use fewer site resources to view your site’s content.
It is worth pointing out that CDNs are recommended for sites that have a lot of international users, as the experience is often better. However, eventually, upgrading your hosting plan will be the only option available to you as your traffic continues to grow, which is the ultimate goal of every website.
Poorly Coded Scripts, Plugins, & Themes
Inefficient code can cause extra resources to be used, thus wasting your server resources. For this reason, you will almost always see plugin and theme descriptions include the terms “Optimized Code” or some variation of it to signify that this won’t be an issue. However, you can’t trust it.
Many plugins and themes will lie to make themselves look more appealing to the WordPress userbase. Naturally, this problem is not exclusive to WordPress and is common on other CMS platforms. One way to fix most resource issues related to plugins and themes is to keep them updated.
Most updates are released to address resource usage issues and fix security problems. That said, if you have ever created custom code, you’ll need to examine the code to correct the problem, which can take several hours to identify the issue.
The best defense against poor coding is to ensure that you only install plugins that you need and that are highly rated. Tools that have millions of installs are usually a good indicator of quality.
Cyber Attacks
Cyber attacks come in many forms, with one of the most common being brute force attacks. These happen when bot attacks trigger a massive influx of traffic that overwhelms your site’s CPU and memory usage. It is the most basic form of cyber attacks, yet it remains the most effective.
While there is no surefire way to prevent these attacks from occurring, the best approach is to guard against bots. This includes adding a limited number of login attempts, implementing multi-factor authentication, and including simple CAPTCHA checks.
Of course, there are other kinds of attacks, with malware infection being another common one. Put simply, Malware are files uploaded to your website that are intended to steal data, hamper site activities, and create backdoors. While some malware can be difficult to detect, if you notice high resource usage, check your files to see if there are any that you do not recognize or if the file size is much larger than normal.
If you notice malware, contact our support team to assist you with our Malware Cleanup services.
Image Creation
Images use a lot of resources to display to visitors, but if your site has any features that may create images or manipulate their appearance, they can use even more resources. For example, if your site allowed visitors to create simple memes and 100 users made requests simultaneously, that could easily exceed the server’s CPU usage limits.
Of course, this can also be on the backend of your site. For example, if you have a plugin that resizes your images for you when they are uploaded, you can overwhelm the system by uploading multiple images at once. The simple solution is to properly size images before uploading them to your site.
Hotlinking
Hotlinking occurs when another site links directly to images on your site. However, instead of copying the image and uploading it to their site to display it, they use the image URL from your site. The result is that the image is displayed on their website, but is downloaded from your website every time it is viewed.
Many refer to Hotlinking as a form of bandwidth theft, and it is highly frowned upon today. The good news is that you can easily guard against this by enabling hotlinking protection in the cPanel. Just be sure to whitelist your own website to ensure you do not block yourself by mistake.
Other Ways to Reduce CPU Usage in WordPress
In many cases, daily and routine actions can contribute to CPU usage that you may want to reduce in order to save resources. Here are a few ways you can reduce CPU usage to help prevent these problems from arising in the first place.
Manage Post Revisions
WordPress has a unique feature known as Revisions. A revision is a copy of the post or page that is made every time a change is made to it. By default, WordPress has no limit on the number of post revisions that it can store; thus, they can build up fast and use up a lot of disk space.
You have two options to deal with this. The first is to completely disable revisions, and the second is to limit the number of revisions that are made. To disable post revisions in WordPress, the simplest way is to install a plugin like Disable Post Revision.
If you would rather limit the number of revisions to help save space, simply add the following code to your wp-config.php file:
php
define('WP_POST_REVISIONS', 5);
The code will limit the number of revisions to 5. You can change this value to whatever fits your needs.
Regularly Update Your Site
Ensuring that your website is up to date plays a big role in helping manage your CPU usage. This includes updating WordPress core files, plugins, themes, and even your PHP version. Many updates help improve site performance and lower resource usage.
Other benefits also include closing security exploits, thus making it less likely that your website will be the victim of a cyber attack. Failing to update one piece of your site can cause compatibility issues that can create other problems. As such, it is always recommended to keep your website up to date.
Protect Your Login Area
We’ve already talked about how too much traffic can cause resource problems for your site, but sometimes it can be because a few users are simultaneously trying to log in at the same time using the wrong information. And this can happen unintentionally.
For example, if you have 30 users trying to log in when a new product is released, and half of them make a mistake in their login credentials, they will try again, and again, until they fix the issue. While the request may seem harmless, it can actually overload the system.
For this reason, many sites implement limited login attempts. This not only prevents users from continuously trying the same login credentials over and over again, but also limits the damage bots can do. You may also want to include a CAPTCHA to ensure they are human.
Caching
Caching offers websites several advantages, with improved load speeds being the most notable. However, it cannot be overstated enough that caching also helps reduce the amount of resources your site uses to deliver your content to visitors.
In simple terms, caching takes your frequently accessed content, like your homepage, and stores that data in a location that allows it to be delivered to visitors much quicker. Thus, instead of having to make a full request and load the data, your site skips most of the work.
Naturally, this helps reduce the resources your site will use. While there are several caching plugins available in WordPress, LiteSpeed Cache remains one of the best choices.
What if I cannot Lower My CPU Usage?
If you have optimized your site performance and still exceed your CPU usage limits, then it is time to upgrade your web hosting account. Many sites start in a shared hosting environment that has limited resources. These plans are perfect for beginners as they are cheaper to operate.
However, as your site grows, a shared hosting environment does not have the resource allotment that you will need. Purchasing a VPS hosting plan ensures you get an entire server to yourself that can be customized to fit your needs, which is the best option.