The Central Processing Unit (CPU) work like the brain of the machine to handle any tasks that the server has been sent. The CPU typically processes requests for running PHP scripts, handles MySQL queries, sends email, etc. Resources on a server are limited and therefore the CPU usage and disk usage are monitored for problematic levels of usage. While temporary spikes in CPU usage are normal, consistently high CPU usage may be indicative of a problem. The acceptable levels of resource usage differs according to the type of hosting you have, whether shared, VPS, or dedicated.
What Is High Resource Usage?
In comparison with desktop CPU activities, the level of CPU processing for a website should be minimal and in fractions of a second of CPU time for execution. A shared server CPU will start running into problems when even a few of the websites on it start running more intensive CPU activities. These intensive activates require more processing power, leading to an increase in ready time and processor queuing on the host. Every server has a fixed number of CPU cores. Therefore, the processing time that can be requested per user account from the CPUs is limited when you are on a shared hosting platform. In a shared hosting environment, when a single user requires an excessive amount of CPU time, it can lead to delays for other user’s website requests. Being aware of the impact of your website on the server’s CPU can help prevent any potential account suspensions for high resource usage.
What Causes High CPU Usage Problem?
If your site receives a lot of traffic, it may lead to high CPU usage but in most cases there are other factors responsible for it. The following list describes some common software issues that can cause high CPU usage:
- Inefficient scripts and excessive add ons/extensions/modules/plugins
- Multiple WordPress websites
- Frequent cron jobs or scheduled tasks
- Hacked website
- Comment spam
- Uncontrolled search engine crawlers and automated robots activity
- High volume of web traffic
1. Inefficient Scripts And Excessive Add Ons/Extensions/Modules/Plug-in
Computer code is as a set of instructions for the machine to follow in order to receive the same expected end result again and again. Generally for web hosting, the set of instructions will be in a scripting language, such as PHP. If the scripts on your website are custom coded efficiently, it should typically have under a second of execution time each. Not all websites are the same though when it comes to memory usage, as some scripts have built-in optimizations or extensions, such as the cache feature in Joomla. Depending on the level of traffic that your site receives, even a single poorly coded or resource intensive active script/plug-in can become resource intensive. So it is best to limit the number of extensions, modules, or plugins in use and uninstall ones that are no longer active. An out of date script/plugin/module may often contribute to resource abuse issues, so all installed scripts including any 3rd party add-ons have to be updated. Developers also have to constantly improve their scripts and patch security holes to boost performance.
Despite these measures, if high resources usage issues persist, then the problematic script has to be isolated and fixed by re-configuring, disabling, or replacing it with a working script. Profiling of entire PHP pages in XAMPP, WAMP, and EasyPHP environments can expose specific scripts or individual functions consuming major resource time. It is possible to detect the plugin causing the issue using P3 Profiler plug-in, which can then be replaced with a better alternative.
2. Multiple WordPress Websites
Most dynamic Content Management Systems, like WordPress, use a database back-end to store information, so that every time a visitor comes to the site, the PHP scripts interact with the database to recall that information for hand-off to the web-browser. On shared hosting platform, if your site gets decent traffic, using this default system of WordPress to regenerate the same HTML page for each visitor’s request is highly inefficient.
With advanced WordPress users, it is recommended that you typically use a caching plug-in, like the W3 Total Cache plug-in. And for basic WordPress users consider optimizing with WP Super Cache plug-in, to reduce the resource load by 90%. If you have multiple WordPress websites on a single host, it will require more RAM and CPU to run proficiently on a shared hosting account so consider investing in additional hosting space for some of your blogs.
Managed Hosting Services Get more information on managed services for Shared hosting, Scalable VPS Cloud hosting, and Dedicated hosting.
3. Frequent Cron Jobs or Scheduled Tasks
A cron job lets you setup a scheduled task for your website, without the need to be present in order to initiate the task. Running particularly resource-intensive cron jobs too frequently can cause problems with your server performance.
It is better to run cron jobs only as often as necessary. When on a shared hosting account, the shortest interval for cron jobs should be at least 15 minutes. If any database backups or set-up of other maintenance jobs are causing high CPU usage then you can temporarily disable it. It is also possible to automate and schedule activity in a cron job to reduce usage. WordPress, for example, has its own scheduling script so disabling its wp-cron.php will help reduce the overall resource usage.
4. Hacked Website
A hacked site often leads to abnormal and extra CPU resource usage on your account because of the additional automated multiple activities it will generally try to do on top of a page load. Malicious users often try to hack into your website to redirect users to a compromised site or just indulge in spamming.
Besides using a secure password and keeping all software up-to-date, you may install a plugin, such as Sucuri, to scan your site and warn you of the possibility of it being hacked. It is wise to protect your hosting account by having a full backup of your account for the last 30 days so that you can easily restore it from any previous unhacked version. If your website has already been hacked, then it has to be manually resolved by an expert who may have to clean up the htaccess code or a code injection attack, to stop hackers from re-directing traffic from your site.
5. Comment Spam
Your website is open to the entire digital community and there will generally be a section for visitors to leave comments on your website. Unfortunately comment boxes and forums can also allow spammers to fill up your pages with malicious junk and fake comments, trying to lure people back to their own websites. Comment spam on your forum or WordPress blog can impact the CPU usage as it increases the size of your database, reduces loading speed, and it can also potentially affect your search engine ranking if the spam content is left intact.
Inspect your account for old installations that you can remove, or for automated comments and spam postings. You can disable commenting but it may not be the ideal solution. Do consider disabling the WordPress default commenting system in favor of a 3rd party commenting system, like Disqus. The best way to eliminate spam comments is by implementing CAPTCHA protection for your website to make it harder for automated bots to create fake accounts.
6. Uncontrolled Search Engine Crawlers And Automated Robots Activity
Automated robots from various search engines, such as Google and Bing, crawl the net to find and index new content for faster dissemination of information. Even one automated bot visitor to your website can end up consuming the resource usage equivalent to hundreds of normal human visitors. Automated bot visitors crawl from the front page and spider out to every link on your site in order to locate all content on your site. This results in an excessive amount of resource usage coming from your account that can cause your account to be suspended.
You can control rule abiding robots by implementing a standardized robots.txt rules file, with a Crawl-delay setting of 30 seconds or higher. But the bad news is that not all automated robots are going to comply with your robots.txt rules. Therefore, you have to block those unwanted bots from your site using htaccess in order to prevent them from using your account’s resources.
7. High Volume Of Web Traffic
Surges in traffic can occur for any of the following reasons:
- When automated bots crawl your site
- If your website is being comment spammed
- Due to other ongoing malicious activity
- You have legitimate traffic going to your website in a short span of time.
If your website is popular, then your site may see consistently high CPU usage and you probably need to look at upgrading to a dedicated server from a shared one. If there is an unexpected large surge of traffic in your site all at once, your hosting account will require more system resources to handle such high volume traffic. A completely static website with just HTML files and images, are much lighter on shared server resources than a dynamic website based on Joomla, Drupal or WordPress.
When your web traffic rises, the jump in website requests increase the demand on the server’s resources. You can upgrade your account to a VPS (Virtual Private Server) or dedicated server, so that you have access to more resources. The most common ways to optimize your website for larger volumes of traffic is by implementing caching (page and browser caching) to reduce duplicate database calls and by limiting dynamic content such as plugins/modules.
Is Your Web Host To Blame?
It may also be that the high CPU usage is not your fault and your hosting provider is the one to blame for not supplying sufficient system resources to your hosting account. This may be particularly true for shared hosting with multiple companies offering cheap hosting for very low CPU usage limit. To resolve any issues with your web host, confirm the CPU usage limit and hardware configuration of the shared server on which your site is hosted.
Now that you are aware of some of the major issues behind high system resource usage, you can easily fix them. But if you still continue to experience high resource usage problems on your current hosting platform, you can either upgrade your hosting plan to have a higher resource usage limit for your account or you can change your web host provider.