In this webinar I will talk about WordPress Performance and why it will slow down over time.
So you have created a shiny new blog on WordPress and your site got really popular, also you have added more functionalities and now you have noticed that your WordPress website is not as fast as it used to be.
Welcome to the world of WordPress!
You are definitely not alone in that experience. Thousands of WordPress users suffer from a slow WordPress website.
But before you decide to throw away your WordPress website and rewrite a shiny new site in NodeJS or any other light framework, I recommend you to take a look at the potential causes for your WordPress website being slow.
Whatever the cause you can try to give a lease of new life to your website. You might actually be surprised to all the options that you have available.
Why WordPress gets slow
Before we get to the solutions, lets try to understand at the root of the problem.
WordPress Database Design Is Inefficient
The WordPress database was designed in such a way to have maximum flexibility in adding functionality without having to constantly change the database schema whenever a new plugin is added.
Almost every content item type in WordPress, be it a post, a product, a page or anything else created by a plugin, creates an entry in wp_posts. And associated with that, each wp_post item will have 1 or more entries in the wp_postmeta table, normally one entry per attribute. So for instance, imagine you have created a product with 10 attributes. For each product entry in wp_posts, you will have 10 entries in wp_postmeta. If the WordPress database was designed for efficiency and speed of access, it would have 10 columns instead!
No wonder then that, after some time, a website with many articles, and maybe with a large product catalog in WooCommerce will slow down dramatically!
Unfortunately Woocommerce is not the only plugin that will create entries in wp_posts and wp_postmeta. Almost every plugin in the wordpress realm will do!
The more data you have and after sometime your database will run to a crawl, with massive SQL queries with joins between wp_posts and wp_postmeta that will take over a minute to run each.
The infamous Table Lock
Now that we know that almost every wordpress plugin on earth will try create content under wp_posts and wp_postmeta, so is it really a surprise that they need to use locks to prevent race conditions in the generation of post ids?
By default most WordPress installations with Mysql database run on the MyISAM storage engine and this type of engine only supports table level locks. So any type of query on a table will lock it. A READ Lock for SELECT statements and a WRITE LOCK for INSERT/UPDATE statements.
This is indeed bad for performance.
By default wordpress creates a separate revision of a post each time you update it. This means that data stored for a post in multiple tables, gets duplicated. To make matters worse, wordpress normally is configured with autosave functionality which saves a revision of an article every 1 min. And by default there is no limit to the number of revisions for a post. And to make matters a bit worse, there is not automatic mechanism to clean up those revisions later down the line.
It is easy to see then why the size of a wordpress database can grow exponentially.
One of the reasons most WordPress websites slow down, is due to the high number and nature of plugins installed. Quite often these plugins come with lots of functionality and are “free”. However in reality these plugins come with an associated cost.
First of all, anyone who installs these plugins will have no idea what PHP code they are running. This code will often have performance impacts because of the way they are designed. Also any plugin updates in the future can bring in unexpected consequences. It is all too easy to update a plugin and suddenly your WordPress website crashes. Each plugin will also increase the size of the database.
Unfortunately many times uninstalling the plugin will not immediately resolve performance problems, because the data added to the database is not cleaned up automatically.
Did you know that by default WordPress tries to run a cron job every time a user accesses the site? In fact it is not a real cron job at all, because instead of relying on the OS to schedule a task, it relies on your visitors to trigger the job.
This will inevitably slow down the website due to the fact that if a cron job requires to update some WordPress data, it will lock tables in the database. This of course is never what is intended.
Out of date PHP
If you are running an old version of PHP, for instance 5.6 your website is running three times as slow as another WordPress website running PHP 7.3.
When you think things couldn’t get any worse, but unfortunately they do.
We have learned about the inefficient storage of data in WordPress. And we have already learned about the infamous table locking which makes matters worse.
The bigger your WordPress website gets, search becomes more of a necessity. You want visitors to your website to find the content they are looking for and you want to optimise your SEO, which quite often relies in displaying content for popular keywords.
By default the WordPress search relies on the database to find its data. And this is the final nail in the coffin. The search will kill your wordpress site quite quickly if you don’t do anything about it. Worst of all, if you do manage to get any search results on the website these will not be relevant at all.
Is this time to throw away WordPress? Not quite…
How to Fix your WordPress Site performance
Let’s look now at ways you can give a lease of new life to your website.
Update PHP Version and WordPress
If you update PHP to the latest version you can potentially improve your site performance by 300%. No brainer, and you should do it as one of the first things you do.
Minimise number of Plugins
Consider very carefully what plugins you are using. Less is more in WordPress world.
The reason why you have the plugins are most often for legitimate reasons.
For instance you might have installed the WPML plugin because you need to support more than one language. Or you installed the Yoast SEO plugin because your site needs to be optimised for SEO.
However if you have a large number of articles already in your wordpress, installing these plugins will make matters worse. Consider other ways of meeting this requirement without having to rely on a new plugin.
Upgrade your Mysql Database
If you are running on an old version of the Mysql database, it pays off to upgrade to the earliest version as long as it is supported by WordPress. Also ensure that you are using the InnoDB engine which allows wordpress to do row level locking instead of table level locking.
Implement a real cron job for WordPress
Disable the wordpress fake cron in wp-config.php and instead setup a real cron job that runs at fixed time intervals and scheduled these when there are less visitors to your site.
Setup Elastic Search
Don’t rely on wordpress search functionality if you have a big site. You can setup elastic search and in this way make your search tens of times faster and more relevant. Consider the amount of extra traffic you might get if suddenly your users are able to find the content they are searching for.
There are plugins available in wordpress to make it easier to setup elastic search without rewriting your code. Ok, its one more plugin but this one is for a good cause.
Limit Number of Revisions
Instead of allowing an unlimited number of revisions per article, consider limiting it to a fixed number. This is so that there is an upper limit on how much the database can grow.
Cleanup your database often
One of the side effects of installing plugins and later removing them is that you will have garbage data that will be left over in several WordPress tables. In addition, over time because of the autosave functionality there will be dozens of copies per blog post.
You should periodically cleanup these tables to make your database lighter. You can do this manually or using WordPress plugins that do the job already for you. Ensure that before you cleanup your WordPress database, you take a backup. You never need them when you have them, but better safe than sorry!
Tables to watch out for:
wp_posts, wp_postmeta, wp_options, wp_term_relationships
Always call OPTIMISE TABLE after you removed unnecessary entries to the table so that MySQL can release the storage and reorganise any indices.
One of the easiest ways to make your website faster is to cache as much as possible. You can setup caching at many different levels. For instance if you use Nginx as your webserver you can implement caching.
Or why not use Cloudflare? In cloudflare you can setup caching rules and at the same time you get the benefit of protecting your website against DDOS attacks.
So you have used almost every trick in the book to make your wordpress cope with the high levels of traffic, but still you are struggling.
Your website is a victim of its own success. At this stage you should consider the infrastructure in which you are running WordPress.
If you are running on a shared hosting plan, switch to a dedicated hosting plan.
If you are running on a dedicated server with a single WordPress instance and a single database, consider adding more WordPress instances and more databases.
If you have tried absolutely everything to increase the lifespan of your wordpress website but still you are struggling, then you may need to move away from wordpress and look into other frameworks. There are many options out there, and that will be the subject of a future article.