fbpx
Want To Add Extra Images Per Product Variation For Free? Download Now

Variation swatches plugin is using up web server’s PHP resources

Justin Mazur

Hi,

Noticed my web server’s response time slowed way down after I installed the Variation Swatches for WooCommerce plugin. I inspected my logs and found a bunch of slow PHP operations that can be traced back to the plugin. Would you please have a look and see if you can tell me what’s happening and whether there’s any way I can fix this?

Let’s look at one example, there are many more like it. After noticing that my performance metrics declined, I investigated and found that PHP-FPM was being very heavily used and running out of resources. I logged any PHP operations that took longer than 7 seconds and found a whole bunch associated with the swatches plugin.

This is from the PHP log:

[22-Oct-2023 08:29:15] WARNING: [pool www] child 34518, script ‘/var/www/html/sico/index.php’ (request: “GET /index.php?_locale=user”) executing too slow (12.463129 sec), logging

This is the same event from the NGINX access log:

172.31.21.42 - - [22/Oct/2023:08:29:15 -0400] "GET /wp-json/woo-variation-swatches/v1/archive-product/13013?_locale=user HTTP/1.1" 200 1630 "https://swansislandcompany.com/product-category/sale/" "Mozilla/5.0 (iPhone; CPU iPhone OS 16_6 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) GSA/284.0.569260749 Mobile/15E148 Safari/604.1"

And this is the strack trace from the slow PHP query log:

[22-Oct-2023 08:29:15] [pool www] pid 34518
script_filename = /var/www/html/sico/index.php
[0x00007f1a8d815550] mysqli_query() /var/www/html/sico/wp-includes/class-wpdb.php:2459
[0x00007f1a8d8154e0] _do_query() /var/www/html/sico/wp-includes/class-wpdb.php:2346
[0x00007f1a8d815400] query() /var/www/html/sico/wp-content/plugins/w3-total-cache/DbCache_WpdbNew.php:235
[0x00007f1a8d815390] default_query() /var/www/html/sico/wp-content/plugins/w3-total-cache/DbCache_WpdbInjection.php:54
[0x00007f1a8d815320] query() /var/www/html/sico/wp-content/plugins/w3-total-cache/DbCache_WpdbNew.php:122
[0x00007f1a8d8152b0] query() /var/www/html/sico/wp-content/plugins/w3-total-cache/DbCache_WpdbNew.php:408
[0x00007f1a8d815210] query() /var/www/html/sico/wp-content/plugins/w3-total-cache/DbCache_WpdbInjection_QueryCaching.php:201
[0x00007f1a8d8150e0] query() /var/www/html/sico/wp-content/plugins/w3-total-cache/DbCache_WpdbNew.php:122
[0x00007f1a8d815070] query() /var/www/html/sico/wp-includes/class-wpdb.php:3046
[0x00007f1a8d814fa0] get_row() /var/www/html/sico/wp-includes/class-wp-post.php:243
[0x00007f1a8d814ef0] get_instance() /var/www/html/sico/wp-includes/post.php:1030
[0x00007f1a8d814e40] get_post() /var/www/html/sico/wp-content/plugins/woo-variation-swatches-pro/includes/class-woo-variation-swatches-pro-archive-page.php:286
[0x00007f1a8d814d60] get_product_thumbnail_image() /var/www/html/sico/wp-content/plugins/woo-variation-swatches-pro/includes/class-woo-variation-swatches-pro-archive-page.php:631
[0x00007f1a8d814cb0] get_available_variation() /var/www/html/sico/wp-content/plugins/woo-variation-swatches-pro/includes/class-woo-variation-swatches-pro-archive-page.php:690
[0x00007f1a8d814bb0] get_available_variations() /var/www/html/sico/wp-content/plugins/woo-variation-swatches-pro/includes/class-woo-variation-swatches-pro-rest-api.php:259
[0x00007f1a8d814ad0] archive_product_variations_for_response() /var/www/html/sico/wp-includes/rest-api/class-wp-rest-server.php:1194
[0x00007f1a8d8149f0] respond_to_request() /var/www/html/sico/wp-includes/rest-api/class-wp-rest-server.php:1041
[0x00007f1a8d814900] dispatch() /var/www/html/sico/wp-includes/rest-api/class-wp-rest-server.php:431
[0x00007f1a8d814740] serve_request() /var/www/html/sico/wp-includes/rest-api.php:418
[0x00007f1a8d8146a0] rest_api_loaded() /var/www/html/sico/wp-includes/class-wp-hook.php:310

Looks like the plugin is trying to load swatch images on a WooCommerce archive page (https://swansislandcompany.com/product-category/sale/)?

Should I enable swatch preloading on archive pages?

Why is the swatch plugin executing rest-api calls just to load swatches?

Thanks for your help...really need to fix this issue. I've temporarily boosted my web server's resources so customers are driven away by lousy site performance but that's not a great solution.


Hakik Zaman

Hi Edward,

Thanks for getting back to us. How many approximate variations do you have with each product?

Hope to hear from you soon.

Thank You

Hakik Zaman

Hi Edward,

Please change the value like this: https://paste.pics/PQ0BN

Then flush all the caches like- browser cache, caching plugin cache, and server-side cache.

If you have no idea regarding server-side cache flushing, please contact your hosting support.

They can flush it for you.

Thank You

Justin Mazur

Thanks–it wouldn’t let me enter “12” only multiples of 5 it looks like. So I entered 15 and flushed caches.

Can you please explain the difference between loading by API vs. html? I understand what an API is but why would you need to make an API call to load a swatch?

Also, should I check the “Enable archive page swatches preloader” checkbox on the “Archive/Shop” tab of the plugin settings?

Hakik Zaman

Hi Edward,

Initially, our plugin loads data using HTML in the 1.1 series.

But we have some customers who have 1400 variations with each product.

So, it takes a long time to load if there are several products on the archive page.

To minimize this critical situation, we had to release version 2.0.

In this version, all the swatches will load by firing the API call.

But, if someone has only 4-15 variations it is kind of over-engineering to call them using API.

So I have suggested you change the value there. So now, the API call will not run where it will get 15 variations.

But if one product has 16 variations, then the API call will be fired.

Also, should I check the “Enable archive page swatches preloader” checkbox on the “Archive/Shop” tab of the plugin settings?

It is not mandatory to enable the preloader. But you can enable it to let your user know something is happening, please, wait till it loads.

I hope the above explanation will help you to understand the scenario.

Thank You

Justin Mazur

Thanks for the explanation. Definitely don’t need to be making those API calls on my site.

I’ll check the site performance now and see if it’s improved.

Hakik Zaman

Hi Edward,

Thanks for understanding. Sure, please let me know how it goes.

By the way, we really get excited & honored when you use our plugin on your site.

If you found my support helpful, could you please leave your valuable review here: https://wordpress.org/support/plugin/woo-variation-swatches/reviews/?filter=5

Your rating keeps us inspired.

Thank You

Justin Mazur

Hello Hakik,

Circling back here because I’m still struggling with your plugin consuming large amounts of CPU resources on my web server.

Definitely being caused by having “Show swatches on archive / shop page.” selected. It’s spiking the CPU and it’s also more than doubling the page load time.

What can be done to fix this? Does it matter if I have the “enable swatches preloader” enabled? I can’t really see a difference.

We’re at the point here where we might have to find a different solution for archive page swatches. A little impact is tolerable but this is causing problems and probably costing us conversions.

Would welcome any ideas you have on improving this situation. Even if I could defer some of the scripts initiated by the plugin until after the “above the fold” page content is in place and, ideally, the page is interactive. Not good having customers (especially on mobile) waiting many seconds before they can interact with the page. Many will just leave.

Thanks,

Ed

 

Hakik Zaman

Hi Justin,

What is your current setup of the Archive Variation Threshold?

Hope to hear from you soon.

Thank You

Justin Mazur

See above in this thread–it’s set to 15. That helped reduce a huge amount of Ajax calls that were being made before, but the archive page swatches still seem to be using a lot of PHP processing. Any ideas how to reduce that?

I see there’s a new feature labelled ” Use variation swatches block to display swatches on archive for Block Themes”

Wondering if going that route would help.

Hakik Zaman

Hi Justin,

Unfortunately, that option will not work for you. Please contact your hosting and ask them if they have Redis Cache facilities or not. If they have it, please ask them to enable it for your site. If still, that doesn’t help, unfortunately, there is no workaround to reduce it further.

If you are not still happy enough after applying 15 at Archive Variation Threshold and Redis Object Cache, then you can claim a refund.

Please let me know your thoughts.

Thank You

Justin Mazur

OK, thanks, let me see if I can improve things with caching.