How to reduce your WordPress CPU load without upgrading your WordPress shared hosting server? The last thing you’ll ever want is a slow server which might affect your Google ranking, a constant server crash (if you’re on dedicated server) or your web hosting company shutting off your blog without warning due to excessive usage. Here are the 7 method I used to reduce my WordPress CPU load and bandwidth without upgrading to a much more expensive server.
↓ 01 – Remove Jpeg and PNG Metadata
Remove the hidden metadata in all of your jpeg images in the ‘upload’ folder. Google doesn’t rely on these metadata on ranking or for keywords, I did a simple test by inserting a unique 10 digit number into a jpeg’s metadata, then I waited for a month and did a quick search for that 10 digit number on Google Images and the result was zero.
On average, each jpeg consist of 15 to 19KB of metadata. Assuming that average jpeg is roughly 60 to 80KB in size, this translates into a saving of 20 to 30% of bandwidth, not to mention the CPU load. If your WordPress Theme comes with lots of background images, by removing the metadata will greatly affect the overall performance.
I did an experiment on www.homeless.com.my by removing all of the jpeg’s metadata in the WordPress Theme and the bandwidth usage dropped by half, same goes for the CPU load, not to mention the time it takes to load is much more faster than it previously was.
As for PNG, here is a loss-less compression which I used. Not only was the software able to remove the metadata, it did a great job at compressing and optimizing the PNG. The file size is smaller with no visible loss of image quality.
- PNG Gauntlet (free) – Loss-less compression for PNG and Gif, somewhat slow
- Stripper (free) – Remove unnecessary metadata from JPG/JPEG/JFIF & PNG files, no loss of image quality
↓ 02 – Compress Jpeg
Jpeg itself is a compressed image/format; to further compress it is to reduce the quality of the image, subsequently the size. The average jpeg size in the ‘upload’ folder is about 80KB, by removing the metadata it comes to about 60KB, and by compressing it further with this software I was able to reduce the size to 45KB on average.
- JPEGmini (USD19.99) – Possibly the best image compressor ever! I use this software
- Advanced Jpeg Compressor (shareware) – Batch compress jpeg, remove metadata and fast
Based on my test result using Advanced Jpeg Compressor with 5830 jpeg images – 259MB (Before) vs 105MB (After). That means for every 100MB the server transferred, it was able to save 150MB. This will greatly reduce the server’s load and web hosting bandwidth. Plugin that does the image optimizing job inside WordPress:
By removing unnecessary codes and line breaks, you might have the opportunity to reduce the CSS file size by 50%. Again, this translates into massive bandwidth saving due to the fact that your style.css file is downloaded every time a unique visitor visits your blog. Here is one of my favorite online tool – Online CSS Optimizer or Clean CSS.
Don’t just stop there, remove and optimize all those unwanted codes from the two most requested pages – index.php and single.php, remove line breaks, empty spaces, comments, redundant codes and many more. This will probably shave off another 10KB. This can be done automatically on the fly with 2 cache plugins:
↓ 04 – Outsource All Images via CDN With Parallel Downloads
You can dramatically reduce your CPU load by hosting your WordPress Theme’s images on another server, no plugin or special software required. You don’t even have to spend much on another web hosting plan – simply upload the images to a CDN.
Some argued on the additional DNS connection required, again, based on my test with tools.pingdom.com, my site is faster than before. The best solution going forward is to use a CDN, also known as Content Distribution Network. For small blogs, here are 2 of the more affordable CDN in the market:
- Amazon CloudFront CDN (Fastest with many servers, parallel downloads available)
- MaxCDN (Flat rate. Affordable but no Asia server. Parallel downloads available)
- Jetpack Photon by WordPress (Free)
- CoralCDN is a free CDN, but the reliability may vary from time to time.
Read our previous article on – 5 CDN Comparison MaxCDN, Amazon CloudFront, CloudFlare, CacheFly and EdgeCast.
As for parallel downloads, this means the CDN server has the ability to deliver images via multiple sub domains. For instant, it is faster to have the image delivered via 4 subdomains such as image01.domain.com, image02.domain.com, image03.domain.com and image04.domain.com, then to have it delivered via a multiple sub domain.
↓ 05 – Clean WordPress Options
When you activate a plugin, it leaves a small footprint in the MySQL ‘wp_options’ database. It may be a good idea to clean the WordPress Options database. WordPress Clean Options plugin’s goal is to give users an easy and safe way to get a bloated wp_options table down to a manageable size, thus improving the performance of their blog. Remember to deactivate and delete unused plugins before performing the cleaning up process.
Note: This plugin is somewhat outdated, but it still works. Remember to backup your database before performing any cleaning or removing of data.
↓ 06 – Optimize MySQL Database
Imagine entering a library where books are scattered everywhere without proper archiving. Just like Windows, your MySQL database gets fragmented as time goes by. By optimizing (defrag) your database, WordPress is now able find the bits and pieces faster, this translates into lesser time it requires for the CPU to search and compile the information, thus more time to serve newer queries or request. If logging into your MySQL database is too troublesome, then install these 2 amazing plugin.
↓ 07 – GZip Compression
Skip this if you have WP-SuperCache or any other cache plugin that perform this task. According to Webo, by enabling Gzip compression on your blog, it will significantly increase the CPU Load while reducing the bandwidth. If you have a fast CPU, by all means go ahead. GZip has its own strength and weakness, the good thing about GZip compression is pages tend to load faster due to the smaller size, on average the the files are 60 – 75% smaller.
Smaller file size means faster serving/downloading, meaning to say your CPU have more processing power for some other stuff. I guess this is a very subjective topic. Anyway, to enable GZip in WordPress, simply insert this code into header.php, it must be above everything else, not before any other code.
<?php if (substr_count($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip')) ob_start("ob_gzhandler"); else ob_start(); ?>
Alternatively, you can insert this simple Gzip code into your .htaccess file
Here are three of my favorite GZip site verification tools. Each with its own uniqueness when it comes to the report, such as the speed it loads, method used and many more.
GZip compression are performed automatically by W3 Total Cache and WP Super Cache plugin.
↓ 08 – Lazy Load Plugin
Developed by Automattic, the guys behind WordPress. Lazy load images to improve page load times and server bandwidth. Images are loaded only when visible to the user. Very useful for those with lots of images. Personally, I prefer a3 Lazy Load [ Highly Recommended ]
↓ 09 – Enable the Default WordPress Object Cache
Skip this if you are using a cache plugin. WordPress 2.0 and higher comes with a feature known as WordPress Object Cache, sadly it is not enabled by default, therefore making this feature somewhat of a mystery.
- Step 1 – Open your wp-config.php file
- Step 2 – Insert the following code
To set it’s expiration time you can add this line:
If you’re using Wp-SuperCache of W3 Total Cache, ignore the WordPress Object Cache feature. Last but not least, use a good WordPress theme, choose wisely, a well coded theme will greatly reduce the number of queries, have minimal W3C error and is Google friendly. Insert this quote to find out the number of queries for different themes:
<?php echo $wpdb->num_queries; ?>q, <?php timer_stop(1); ?>s
↓ 10 – Set Expire Header, Cache and Cookies
You can set Expires headers on specific files or even file types. Then when the browser comes to the website it can see when was the last time it downloaded the specific file types. If it was recently it will display them from the cache, if you haven’t visited the site in a while it will download the newest version from the web server. The following code includes every possible files and configuration for Apache server, does not work with Ngnix configuration. Include the following code into your .htaccess file.
# ---------------------------------------------------------------------- # Expire Header # ---------------------------------------------------------------------- # Use UTF-8 encoding for anything served text/plain or text/html AddDefaultCharset UTF-8 # Force UTF-8 for a number of file formats
↓ 11 – Manually Remove Redundant Data From MySQL
Clean up “wp_commentmeta” Junk Entries – Use the following command to delete “junk” entries which have no relation to wp_comments. Junk entries are like orphan entires, data from comments you removed and etc.
DELETE FROM wp_commentmeta WHERE comment_id NOT IN ( SELECT comment_id FROM wp_comments )
Akismet Related Metadata in wp_commentmeta Table – Every time a spammer drops a comment, Akismet saves a record of it, records such as IP address and more. These data may be useful to some but this is the mother of all load. By right, the wp_commentmeta ought to be 2KB or less, due to the presence of Akismet, it can be as huge as 10MB or more, depending on the amount of spam you receive. Remove all the unwanted data by performing this simple query.
DELETE FROM wp_commentmeta WHERE meta_key LIKE "%akismet%"
Remove Comment Agent – By default, whenever someone commented on your blog, it captures a small amount of info such as browser, IP address, and etc. These data are useful for stats purposes by most of us uses Google Analytics, thus it doesn’t make any sense to store these data on your blog. Batch remove these data.
update wp_comments set comment_agent ='' ;
Mass Close Trackbacks and Pings On All Posts – Nobody uses trackbacks anymore, so is ping. Remember Technorati? Yes, ping and trackbacks are officially dead and it shall be buried along with the rest of redundant feature by closing all ping channels. Batch close by using this query.
UPDATE wp_posts SET ping_status = 'closed';
Delete all Unused Tags – Tags, Cloud Tags and many more are dead due to massive abuse by bloggers. Tags no longer helps in ranking or convey the intended message. Categories are still the best option. If you happen to have lots of redundant and unused tags, why not perform these simple queries to clean up the database.
DELETE FROM wp_terms WHERE term_id IN (SELECT term_id FROM wp_term_taxonomy WHERE count = 0 ); DELETE FROM wp_term_taxonomy WHERE term_id not IN (SELECT term_id FROM wp_terms); DELETE FROM wp_term_relationships WHERE term_taxonomy_id not IN (SELECT term_taxonomy_id FROM wp_term_taxonomy);
Delete Feed Cache – Yet another feature made obsolete by abuse. I have to say having feed is a popular feature, it is like having your own personal facebook. As time goes by, mobile surfing took over and thus the death of feed. Why not delete all the useless transient created by the blog?
DELETE FROM `wp_options` WHERE `option_name` LIKE ('_transient%_feed_%')
Delete all post revisions and their metadata – Post revision is a very useful feature, however, it can occupy a significant of space if you blog too often. Your database will be big and bloated with lots of unnecessary data. Mass remove these revision with the following query:
DELETE a,b,c FROM wp_posts a WHERE a.post_type = 'revision' LEFT JOIN wp_term_relationships b ON (a.ID = b.object_id) LEFT JOIN wp_postmeta c ON (a.ID = c.post_id);
Change the Default ‘Admin’ Username – Prior to WordPress 3.0, users are forced to use the ‘admin’ username as the default username. For security purposes, it is a good idea to change the old ‘admin’ username to something else.
UPDATE wp_users SET user_login = 'YourNewUsername' WHERE user_login = 'Admin';
↓ 12 – Blog Address And Site Address
Set the address instead of having the server checking it, this will reduce server queries. Set the code in wp-config.php
define('WP_HOME', 'https://www.geckoandfly.com'); define('WP_SITEURL', 'https://www.geckoandfly.com');
↓ 13 – Disable The Post-Revisioning
Post-revision is perhaps the most annoying feature, not only it causes the mysql database to be bloated up in a matter of months, it creates lots of redundant entries and took up precious database spaces. Set the code in wp-config.php
↓ 14 – Increase PHP Memory
This trick might not work if you’re on a shared hosting, then again, it might, depending on your web hosting company. Usually 64MB is more than enough. Set the code in wp-config.php
define('WP_MEMORY_LIMIT', '64M'); define('WP_MEMORY_LIMIT', '96M'); define('WP_MEMORY_LIMIT', '128M');
↓ 15 – Disable Cron Job
Not recommended, you will have to manually perform the cron job! Will break some plugins. The WordPress Cron job is a resource intensive task that runs every single time yourWordPress is accessed.The best way to optimize the efficiency of your WordPress cron jobs is to disable WP-cron and set up a normal cron job through cPanel which will run every 12 hour or once per day.
You can disable WP-cron by modifying the wp-config.php (located in the folder where WordPress is installed). Open the wp-config.php file, add a new line after