Join GitHub today
WordPress Popular Posts has been built with efficiency in mind. However, there are some circumstances that might affect its performance, such as:
- Your hosting either does not support the InnoDB storage engine or it's been disabled, which can have a noticeable performance impact on your server when using this plugin;
- Large / high traffic sites;
- Presence of other resource-intensive plugins and/or scripts on your site;
- et cetera.
To help reduce the load on your server, WordPress Popular Posts offers the following features:
Whenever someone visits a given post or page on your website, WordPress Popular Posts stores this page view to the database to keep track of visits: 1 view = 1 database write.
It's highly unlikely that the above scenario could cause any issues on low traffic sites. Medium / high traffic sites, however, can be affected by this: (too) frequent database write operations could cause performance issues (and even database lockdowns in extreme cases) which is, of course, not an ideal situation.
Starting version 4.2.0, WordPress Popular Posts can store views data in-memory (Redis, Memcached, etcetera) and batch update the views count of your posts & pages every 5+ minutes, which greatly reduces the number of database writes. This of course also means better overall performance.
This feature is considered Beta as it hasn't been fully tested yet.
To enable the pageviews cache:
- you need access to an in-memory data storage, like Redis or Memcached (check with your hosting provider);
- install and set up a persistent object cache plugin on your site (eg. Redis Object Cache by Till Krüss, or Memcached Object Cache by Automattic);
define('WPP_CACHE_VIEWS', true);to your site's
wp-config.phpfile anywhere before the
/* That's all, stop editing! Happy blogging. */message.
After enabling the feature, WordPress Popular Posts will start storing your views data in-memory immediately. Setting
WPP_CACHE_VIEWS to false (or removing the constant entirely from your
wp-config.php file) will disable the feature.
Caching DB queries results
WPP has its own caching mechanism based on WordPress' Transients.
WPP can store the resulting data from each database query in cache for a fixed amount of time (configurable via Settings > WordPress Popular Posts > Tools). The basic idea here is to reduce the number of database queries required to show the popular posts list(s) on your site, which can help a lot in terms of performance. And if your server supports memcached or Redis, then installing a memcached/Redis object cache plugin can improve things even further.
How do I enable / disable WPP's cache?
Go to Settings > WordPress Popular Posts > Tools, under the Data section you'll find the Data Caching option.
Are there any disadvantages to having this option enabled?
Just one: when someone checks any of your posts and pages, your popular posts list won't be updated immediately.
The plugin will use the cached data to build the popular posts list. Once the cached data expires, WPP will query the database again to retrieve the updated popular posts data, refresh the data cache and build the list.
It's a trade-off: the plugin will use less resources at the expense of not display a live popular posts list.
Does this affect the Stats dashboard?
No. The Stats dashboard will always show live statistics. The caching feature only affects every instance of WPP (the WPP widget, the wpp_get_mostpopular() template tag, and/or the [wpp] shortcode) on the public side of your site.
By default, WordPress Popular Posts stores every single page view your site gets in a database table which can grow quite a bit over time - especially on large / high-traffic sites.
You can instruct WPP to delete old views data periodically to keep the database table from getting too big for your server to handle. To do so:
- Go to Settings > WordPress Popular Posts > Tools.
- Under Data, change Set log limit from Disabled to Keep data for and set the amount of days WPP should keep data stored.
- Hit the Apply button to save changes.
After enabling this feature the old data will be deleted every day around midnight. Keep in mind that this cannot be undone, so proceed with caution.
Also, if you enable this feature it might be a good idea to install a database optimization plugin to keep WPP's database tables at an optimal performance level. If your site is running MySQL version 5.7 or greater, you might want to give WP Optimize a try.
From version 3.2.0, WordPress Popular Posts introduces Data Sampling - a feature that allows the plugin to track only subset of your traffic and report on the tendencies detected in that sample set.
Why would I want WPP to store only a subset of my traffic instead of the whole thing?
As you may already know, WPP stores every single visit you get on the database. For small / medium sites that's fine but on high-traffic sites this may cause performance issues (including database lockdowns) due to the constant database write operations done by WPP.
How does Data Sampling work?
Every time someone visits one of your posts / pages, WPP will generate random number between 1 and N, being N the sample rate. If the random number turns out to be 1, then the views count of that post / page will be incremented by N.
The general idea is that in theory it should take N tries to hit number 1 (the probability of that is 1/N). In the long run, it'll increase the views count value by 1 for each visit without constantly querying the database.
But wouldn't that have an impact on the accuracy of the statistics?
Yes, the count may be off at first but the more visits that come through the more accurate this will be overall.
What is 'Sample Rate' for?
Please check How does Data Sampling work? to learn what it's for.
The default value is 100, recommended for sites with 125k / 250k visits per day. For sites with low / medium traffic, lowering the sample rate is recommended: the lower it is the more accurate the views count will be, but it'll also mean increasing the frequency of database writes.
How do I enable / disable Data Sampling?
Go to Settings > WordPress Popular Posts > Tools, under the Data section you'll find the Data Sampling option.