#237 – Slow Queries - > WP_Term_Query->get_terms() - Plugin: weeblramp

Posted in ‘weeblrAMP’
This is a public ticket. Everybody will be able to see its contents. Only enter usernames, passwords or any other sensitive information in the Private information field.
Friday, 18 December 2020 04:17 UTC
thaimed
 Hello

We are trying to optimize webpage speed and using the query monitor plugin.
For some reason its pointing the finger at weeblramp

Googling WP_Term_Query->get_terms() tells me that using object cache can help solve this which we already have but not sure if weeblramp handles things differently


Here is the slow response warning we get on every page

SELECT t.*, tt.*
FROM wp_terms AS t
INNER JOIN wp_term_taxonomy AS tt
ON t.term_id = tt.term_id
ORDER BY t.name ASC	

    WP_Term_Query->get_terms()

	Plugin: weeblramp 	3503 	0.1109
SELECT t.term_id, tt.parent, tt.count, tt.taxonomy
FROM wp_terms AS t
INNER JOIN wp_term_taxonomy AS tt
ON t.term_id = tt.term_id
ORDER BY t.name ASC	

    WP_Term_Query->get_terms()
    wp-includes/class-wp-term-query.php:727
    WP_Term_Query->query()
    wp-includes/class-wp-term-query.php:297
    get_terms()
    wp-includes/taxonomy.php:1225
    WblWordpress_Compat::get_terms()
    wp-content/plugins/weeblramp/vendor/weeblr/wblib/packages/wordpress/compat.php:32
    WeeblrampHelper_Terms->__construct()
    wp-content/plugins/weeblramp/helper/terms.php:40
    WblFactory->buildObject()
    wp-content/plugins/weeblramp/vendor/weeblr/wblib/packages/factory.php:165
    WeeblrampFactory->buildObject()
    wp-content/plugins/weeblramp/factory.php:97
    WblFactory->getObject()
    wp-content/plugins/weeblramp/vendor/weeblr/wblib/packages/factory.php:107
    WblFactory::getA()
    wp-content/plugins/weeblramp/vendor/weeblr/wblib/packages/factory.php:46
    WeeblrampClass_Route->setRewriteRules()
    wp-content/plugins/weeblramp/class/route.php:781
    WeeblrampHelper_Boot::init()
    wp-content/plugins/weeblramp/helper/boot.php:286
    do_action('init')
    wp-includes/plugin.php:484

	Plugin: weeblramp 	3503 	0.0598 



any recommendations on how we can fix or improve this issue?

Cheers
Friday, 18 December 2020 04:47 UTC
thaimed
btw forgot to mention. the site is alone on a dedicated VPS and 2GB ram using lightspeed for caching - ive upped all sorts of php settings max_input_vars , time etc etc but nothing works... the version of Weeblr is 1.12.6.787

if i disable WeeblrAmp plugin the slowQuery warning goes away.

obviously i dont want to disable Weeblr so just wondering how to tweek settings to get over this problem
Friday, 18 December 2020 08:37 UTC
wb_weeblrpress
Hi

WeeblrAMP itself does not run this query, it's used by WordPress inside of the get_terms() APi function call. Using caching on the result can help, I've done a quick test and on a test site, the number of calls to that function would be reduced from 8 to 6 per page load. So we can expect a tiny reduction of CPU use with that change.

I have made the change and you can download and install over that version from the development versions download area.

Beyond that, I'm not sure what can be done, we do need those queries to run.

Best regards

 
Monday, 21 December 2020 04:18 UTC
thaimed
Hello Thank you for your prompt reply. We did install the development version yesterday and so far it seems to not change anything. Im still seeing the same slowQueries for WeeblrPress

SELECT t.*, tt.*
FROM wp_terms AS t
INNER JOIN wp_term_taxonomy AS tt
ON t.term_id = tt.term_id
ORDER BY t.name ASC
WP_Term_Query->get_terms()
Plugin: weeblramp 3503 0.0801

SELECT t.term_id, tt.parent, tt.count, tt.taxonomy
FROM wp_terms AS t
INNER JOIN wp_term_taxonomy AS tt
ON t.term_id = tt.term_id
ORDER BY t.name ASC
WP_Term_Query->get_terms()
Plugin: weeblramp 3503 0.0719

Re:t's used by WordPress inside of the get_terms() APi function call. Using caching on the result can help - YEs from what im reading this is correct . Which is why the slowQueries does not appear when WeeblrAmp is disabled.

We are running Litespeed cache with Memcached for Object Cache which is why it does not trigger slowQueries ... but i dont think WeeblrPress uses the same objectCache ( i dont think its supposed to) and therefore has to call >get_terms() everytime resulting in an additional 3 seconds lagtime for page load.


RE:reduction of CPU - Honestly we are more concerned with load time not CPU utilization since its on a dedicated VPS. The slowQueries issue is basically taking a 3 second loadtime to 6 seconds which doesnt seem like much but based on the new Google rules is a lot and always results in poor metrics.

Is there anyway for weeblrAmp to either tap into the object cache or ignore completely? ( sorry not sure so just throwing ideas out )

cheers
Monday, 21 December 2020 10:05 UTC
wb_weeblrpress
Hi

We are running Litespeed cache with Memcached for Object Cache which is why it does not trigger slowQueries ... but i dont think WeeblrPress uses the same objectCache ( i dont think its supposed to)
I was not using ObjectCache, simply memoization, which roughly what ObjectCache does, except if you have Memcache or similar. In which case, the WP Object cache can store data between requests and that is a big gain. Regular setup without memcache or redis cannot do that.

The slowQueries issue is basically taking a 3 second loadtime to 6 seconds which doesnt seem like much but based on the new Google rules is a lot and always results in poor metrics.
Indeed that's very large - although it won't really have a significant impact on your SEO, it will certainly have one for your users.

So I looked again at that and have implemented caching through WP Transient, which really is the standard for caching. It means that your Memcache backend should now pick up those queries and store them.

- The data is stored for 12 hours.
- You can clear the cached data (that is, the weeblrAMP cached data) under the "System" tab of weeblrAMP configuration (scroll down til you see the Clear cache" option).
- Only the get_terms data is cached

You can download that updated version from the same Developement area as before.

Let me know how it goes.

Best regards

 
Tuesday, 22 December 2020 03:19 UTC
thaimed
wow wow wow!

What ever you did is working so far.
Slowqueries have dissappeared completely!


Please feel free to close this ticket and thank you again for your incredible response time + most importantly for the fix! 🍻

Tuesday, 22 December 2020 08:33 UTC
wb_weeblrpress
Hi

Glad it worked effectively!

Slowqueries have dissappeared completely!
Not entirely, you will geta few every 12 hours, when the cache expires and it needs to be updated. That should be only for one single request for one single user, and then you're good for 12 more hours but cannot be avoided really.

Please feel free to close this ticket and thank you again for your incredible response time + most importantly for the fix! 🍻
You had the right information, which is the most important here. Pinpointing the exact query would have been difficult for us as we don't have that particular issue on any test site (probably due to the number of terms I guess).

Once the issue is identified, it's not that hard to do something about it. There's not always a solution but in that case, there is. Note that if you did not have a memcache backend, the gain would be less because the data would be cached in the database. So the queries would be much much faster, but there would still be some database queries.

Anyway, glad it's sorted out now and thanks for the input. Closing this ticket now, feel free to open a new one as needed. If you do so, please mention this ticket number in the new one.

If you created any superadmin account for us, be sure to delete or block it now to avoid unnecessary risk in the future.


Best regards
 
This ticket is closed, therefore read-only. You can no longer reply to it. If you need to provide more information, please open a new ticket and mention this ticket's number.