There are so many ways in which the user experience can be disrupted within a WordPress site. That’s why developers lay down a solid foundation as they tackle the initial build. The right theme and plugins are chosen. The proper performance optimizations are put into place.
But a WordPress developer’s work is never finished.
Even once your well-planned website has launched, there’s still plenty to do to maintain and improve upon its performance. It’s just the nature of websites, in general. As more gets added, and traffic grows, a website’s performance can flounder. So, it’s your job to stay abreast of these slowdowns and keep visitors from being greatly impacted by these changes.
As such, today’s post is going to focus on WordPress performance tuning you can do post-launch. In particular, we’re going to pay close attention to the WordPress MySQL performance tuning and how optimizing your database after the fact can help restore your site’s speed to acceptable levels.
Free Website Speed eBook
The 12-Step Checklist to
Achieve Loading Times Under 1 Second
WordPress Performance Tuning: Why You Have to Do It
I don’t need to remind you that the effort you put into WordPress performance tuning matters a great deal to visitors. And, because speed is so closely tied to their satisfaction with a website, Google puts a strong emphasis on page speed as well.
On July 9, 2018, Google rolled out what it dubbed the “Speed Update”. This was an algorithmic change that penalized and rewarded mobile websites based on loading speed.
In Why Performance Matters, Jeremy Wagner sums up why Google has increasingly placed such an emphasis on speed:
Retaining users is crucial to improving conversions. If you run an online business, conversions are the goal and performance is critical. Slow sites have a negative impact on revenue, and the opposite is also true.
Google’s Impact Calculator will actually show you what sort of effect page speeds have on your revenue. Take this example that provides a monetary gain for improving speed by just .2 seconds:
And here’s what that figure turns into when you can shave off 1 second:
Wagner also explains why developers have a moral obligation to design websites for speed:
Improving performance should not be seen solely as a means of advancing ourselves, but also as ethically responsible behavior. Poorly performing sites and applications can pose real consequences and costs for the people who use them.
Clearly, this is a matter you can’t afford to ignore.
What Causes WordPress Website Performance to Falter?
There are a number of reasons why a WordPress site would slow down.
- Images are uploaded at unnecessarily large sizes.
- Images haven’t been compressed.
- Pages are too long or contain too much dynamic content.
- Themes are poorly coded.
- Themes use scripts that unnecessarily query the database.
- Plugins are poorly coded.
- Plugins run excessive external scripts.
- The website is running on outdated software.
- The database hasn’t been configured at all, so it’s running inefficiently.
- The web hosting plan is unable to sufficiently handle the website’s requests.
This shouldn’t come as a surprise to you. A WordPress installation in its own right is a fairly lightweight piece of software. It’s only when we start to add things like media and themes, and update our configurations, that things start to slow down.
But how can it be avoided?
In order to grow a business and, consequently, the traffic being driven to that business’s website, it must evolve. Your blog becomes a thriving resource for visitors. New marketing strategies appeal to visitors to stay longer on the site. Design trends change and so too must the design of the website over time. It’s inevitable.⚙️ You must schedule time for WordPress performance tuning as well as that of your MySQL database. The quicker you can get requests in and out of the database, the better your site will perform. #WordPress Click To Tweet
How Do You Find WordPress Performance Tuning Bottlenecks?
Unlike your initial attempts to optimize your site, WordPress performance tuning doesn’t come with one blanket checklist of required actions. Each website should be assessed on a case-by-case basis. This means gathering data on the website’s performance--in the past, the present, and as you progress forward into the future.
Using the right set of tools, you can narrow in on bottlenecks and address each of them as they arise.
Here are some tools you should add to your development and maintenance WordPress performance tuning arsenal now if you haven’t already:
Google Pagespeed Insights
This needs to be your baseline tool. With Google PageSpeed Insights, you’ll receive a fast assessment regarding your website’s pagespeed and recommendations on how to improve performance.
There will be two scores to look at: one for mobile and one for desktop. While both should be reviewed and addressed, prioritize mobile.
Also, take note that the kinds of suggestions Google recommends are more along the lines of WordPress performance tuning optimizations you’d do prior to launch. If you haven’t gotten this in order by then, this tool will ensure you do.
Free online speed testing tools like Pingdom will give you a glance at your site’s performance from another perspective:
As you can see here, the focus is on the size of the page and how that translates to HTTP requests. Pingdom breaks this out based on the following kinds of requests and content:
- Text docs
- And more
Further down the page, Pingdom will expand on how many file requests hit the server for just this one page of your website:
You can see there’s a lot of stuff happening at the server and database level (like checking the DNS record and SSL certificate) that prolongs the loading of the site. There are also quite a few scripts slowing things down. If you were to move deeper into the analysis, you’d start to encounter themes and plugins that load later in the process and, again, stall page speed.
So, if you’re looking for a guilty party to blame, you need Pingdom on your side for coming up with a WordPress performance tuning plan.
Query Monitor Plugin
To drill down even further, you should look at queries occurring in your database.
The Query Monitor plugin allows you to complete your WordPress performance tuning inside of, well, WordPress while you run this type of diagnostic test. With each new page or post you visit inside WordPress, you’ll receive a unique assessment for each and it can readily be accessed from the admin toolbar at the top:
In the toolbar, take note of the red block. This won’t always be red; that’s only the case when there’s a database error that needs to be addressed.
Those four numbers that appear in the block are broken down under “Overview”. They are:
- Page Generation Time
- Peak Memory Usage
- Database Query Time
- Database Queries
The sidebar in your Query Monitor will then allow you to dig into what’s causing that particular page to take so long to load. This one, in particular, has 145 queries it has to process and send back to the visitors’ browsers. As you can imagine, there are a number of elements on the site that are causing issues for you:
Now that you have these three tools in place, you can develop an accurate picture of what’s happening on the backend of the site and how it correlates to page speed. The next step is to take action and develop a WordPress performance tuning plan.
13 Things to Include in Your WordPress Performance Tuning Strategy
Before we take a look at the list of tasks for WordPress performance tuning your MySQL database and website, first be sure the lagging page speeds aren’t solely relegated to the dashboard. If that’s the case, use this slow dashboard optimization checklist to get your WordPress installation in order.
1. Review the Basics
The WP Buffs’ 12-step checklist for reducing loading speeds covers the basics you need when configuring a WordPress site during development. Before you begin targeting MySQL database-specific WordPress performance tuning tasks, make sure these are still in place and working as they should be.
These will include:
Install a Caching Plugin
Most caching plugins do more than just cache your pages and the users’ browsers. Here are some of the WordPress performance tuning optimizations your plugin should put in place:
- Server-side caching
- Browser caching
- Page-level caching
- Create image sprites
- Gzip compression
Optimize Images for Performance
Image optimization can take place both inside and outside of WordPress and is essential for any WordPress performance tuning strategy. To help reduce the strain on your server, ensure that images are sized no larger than the maximum size allowed on the site. This will keep unnecessarily large media files from overwhelming the server.
Also, be sure to have a compression system in place. You can use free tools online for this or install an image optimization plugin to automatically handle it for you.
The WordPress core and any themes or plugins you use within it must be updated on a regular basis. If you don’t have a system for monitoring and implementing these yet, consider automating the process so you never forget to do them. Just make sure you make a backup before running any updates.
Clean Out Unused Files
To ensure proper WordPress performance tuning, plugins, themes, media files, and even comments should be trashed if they’re unused or unwanted.
This will prevent the leeching of your database’s resources through your images.
Limit the Number of Saved Revisions
Every time a post or page is updated and saved, a new revision is stored in the database (along with those that existed before it). Put a cap on these so your database doesn’t have to hold onto page versions you’ll never need again.
Use a Database Optimization Plugin
With a click of a button, the WP-Optimize plugin can make space within your MySQL database and ensure it’s running at optimal speed.
2. Add a CDN
If in your original development of your WordPress site you didn’t think a CDN was needed, now may be a good time to look into one as a part of your WordPress performance tuning strategy.
If a bump in global traffic is causing your server and database to go into overdrive, reducing the workload through a content delivery network would be a big help. Even if it’s not a matter of where visitors are located, but more the sheer numbers of them, a CDN wouldn’t be a bad idea either.⏩ A CDN increases the number of servers through which your website can be served to visitors. So, even if your hosting company only has datacenters in North America and Europe, your website could be cached and delivered as quickly to… Click To Tweet
If you’re wondering where to start, refer to this list of the top CDNs for WordPress and select the one that’s right for your site.
3. Add a WAF
A web application firewall (or WAF) isn’t something people instantly think of when it comes to WordPress performance tuning... but that’s because we usually associate it with WordPress security.
That said, a WAF does come with the added benefit of speeding up HTTP requests. This happens as a result of how the WAF acts as a buffer between a website and those requesting access to it. If a threat is detected, your server is spared having to handle the corresponding request.
So, if you haven’t implemented one yet, now is as good a time as any to get it on your site. Check out this guide to the WAF for recommendations on top security plugins that include firewall protection and speed and consider one to include in your WordPress performance tuning plan.
4. Strengthen Your Web Hosting
Have you considered that the hardware and software powering your web hosting plan might be the culprit? If all the data shows your site performing reasonably and as expected, your server might be in need of a reconfiguration and some serious WordPress performance tuning.
Consider the following actions:
- Upgrade from shared hosting to VPS.
- Check that your server uses SSD.
- Check that your MySQL tables run through the InnoDB storage engine. It’s much more efficient and reliable than the other options.
- Increase the RAM so you have more than enough resources for MySQL processing.
- Distribute your website across various servers with a load balancer. This way, you can dedicate servers to specific functions, like one strictly for MySQL and one for PHP.
While you’re working on your server capacity and health, make sure all software is up-to-date. This includes:
By running on the latest versions, you can rest assured that it’s not the technology behind your site that’s causing the problem.
5. Implement More Caching Processes
When setting up your initial caching configuration, did you stick to the standard browser and server caching settings? If so, revisit your options now as a part of your WordPress performance tuning efforts, as there is a much broader expanse of website caching that can be used to optimize your server and databases.
- Varnish Cache is a web accelerator and reverse proxy caching mechanism that optimizes HTTP. In other words, it sits in front of your server and ensures the network runs as efficiently as possible.
- OpCache is caching for PHP and what it does is store precompiled script bytecode. To implement, you need to use a PECL extension and add additional parameters to the php.ini file.
- Memcached works to preserve the performance of your MySQL database. For websites that are large and dynamic in nature, any amount of savings you can get from caching is a help. Memcached helps you store smaller chunks of data as well as common queries to your database.
You can also code implement object caching using wp-cache functions.
If you can add these three layers of caching to what you already have in place, you’ll have WordPress performance tuning at the following levels:
6. Use a Transient Cleaner
Because you can cache data at the MySQL database level, this means there could be a whole bunch of expired “transients” stuck in there. Your caching mechanism may be smart enough to copy and save the data, but it probably isn’t taking care of cleanup for you.
That’s what this Transient Cleaner plugin is for. It will take care of sweeping up your database tables and clearing out expired data snippets you no longer need stored there, which will make more space for your table to store current data.
Free Website Speed eBook
The 12-Step Checklist to
Achieve Loading Times Under 1 Second
7. Separate Staging
There are a couple of reasons why you’d work in a staging environment. The first is during the development of a website. Rather than do all your work on a live server, you can handle it all away from prying eyes. Another reason you’d need one is for updates.
Updates in WordPress can be as simple as pushing through a new plugin version from the developer, or they could be client-initiated revisions they’ve requested you make to the design. Either way, you don’t want to go cowboy coding and potentially disrupt the live website in the process. So, you use a staging environment.
That said, you have to be careful about where you put that staging site. If it’s on the same server, it should have its own dedicated database. That way, you’re not stealing resources from the live MySQL database.
If you want to free up even more space, you could use a local development platform like Local by Flywheel to handle all revisions externally.
8. Limit PHP Memory
In some cases, increasing your PHP memory allows you to work around the restraints of the server. However, if your server isn’t up to the task of handling requests coming into it, then you should really be asking yourself what to do about the limitations at the server level and not trying to fudge the memory limits to make room for excessive tasks.
As such, I believe it’s a good idea to limit PHP memory to 128M (unless your site is really large, in which case you could bump it up to 256M):
define( 'WP_MEMORY_LIMIT', 128M );
If you have to temporarily expand it to handle a bigger chore, that’s fine. But always remember to return it to a reasonable limit.
9. Reduce the Number of External HTTP Requests
Think about all of the plugins or themes you use that call on external resources. While your server can handle these external HTTP requests, it does take up more time and resources than you likely had budgeted for.
I would suggest that you review your theme and plugins to see what sorts of external requests are being made. Is each of those external calls essential to your website? If not, is there a way to deactivate the specific features so the plugin can run more efficiently?
How about your theme; is it handling scripts and stylesheets per WordPress’s enqueue guidelines? If not, you can create a child theme and rewrite it so it stops making unnecessary queries on your database.
If you find your theme or plugins to be at fault for draining resources and you can’t find a way to disable or optimize them, you may need to find replacements. Here are some suggestions for lightweight WordPress themes you can trust.
10. Store Static Content Elsewhere
High-performance websites (e.g. Google, Amazon, YouTube) don’t generally keep all content in the same database or even server. What those developers do, instead, is to offload static content to a dedicated server of its own. This way, static and dynamic content can be handled separately and much more efficiently.
11. Confirm HTTP/2 Support
HTTP/2 is the next generation of the hypertext transfer protocol. A couple of years ago, this was something you had to take care of switching to in order to reap the benefits of the WordPress performance tuning that came from it. However, most sites should be on it now (especially if you have an SSL certificate configured).
Just to be on the safe side, run your website through KeyCDN’s HTTP/2 Test and get some peace of mind that your server is efficiently handling HTTP requests.
12. Minimize DNS Lookups
There was a screenshot I showed earlier from Pingdom that broke down each HTTP request that was made for a page and how long it took to load each part of it. One of the items noted was the DNS lookup.
A DNS lookup is basically a confirmation of the domain name service behind the page. There’s just one problem with it though.
In the case of the example I showed, there were 145 HTTP requests for the single page I searched for. Many of them lived on the same DNS (i.e. the main URL of the website). There were some, like the Google fonts link, that did not.
In order to reduce how much time each of the 145 HTTP requests takes to load, we could cache the DNS records as a part of our WordPress performance tuning efforts. This way, any subsequent requests for the same domain wouldn’t need to be performed again.
Check with your DNS provider to see about implementing caching of your DNS records.
13. Reduce Redirects
There are times when landing page redirects are necessary. Moving a site from HTTP to HTTPs is one of them. A rebranding that involves a domain name change is another. A restructuring of URLs is yet another.
But redirects force your server to do extra work. In addition to processing the standard HTTP request, it also has to stop to address the redirect.
In terms of what to do here, there are a number of actions you can take as a part of your WordPress performance tuning efforts:
- Remove any redirect directives that you don’t need anymore.
- Never use more than one redirect for a single page. For instance, if you’re changing the domain from “http://www.mysiterox.com” to “https://mysiterox.com”, don’t include an intermediary for “http://mysiterox.com”. Just make it happen in one fell swoop.
- Always start your WordPress site with a basic structure. There’s no need to overcomplicate with page IDs, dates, etc.
Redirects might seem like a minor detail when it comes to WordPress performance tuning, but every little bit counts!
As you can see, there’s never really an end to the maintenance work needed on WordPress sites. Even with the most solid WordPress performance tuning efforts in place, you have to remain cognizant of factors that could suddenly slow your site speed way down.
Of course, this means more work for you… and do you really want to deal with that?
If WordPress performance tuning is something you want to outsource, but still be able to provide to clients as an upsell, consider a partnership with WP Buffs. You get white-label outsourced maintenance and support, and your client gets a WordPress website that’s finely tuned long after launch. You can also read more about speeding up your WordPress site over at WPblog.
Want to give your feedback or join the conversation? Add your comments 🐦 on Twitter.