WooCommerce is the most used webshop system in the world and its awesome! However, using WordPress as its application framework has some drawbacks. In particular, you might get a very slow WooCommerce with many products. When I point that out in client meetings, I inevitable get the same questions: How many products exactly result in a slow WooCommerce frontend/backend etc – and what can you do about it?
Besides all knowledge I have about server architecture, clean theming and WordPress coding, that question isn’t so easy to answer. That’s why I did set up my own little test app.
Slow WooCommerce with Many Products – The Test Environment
I’ve done all of the following tests on my local computer. It’s a Dell XPS 13 the following hardware:
- Intel Core i7-7500U
- 8GB LPDDR3 1866MHz
- 256GB PCIe Solid State Drive
Operating System and services:
- Ubuntu 14.04
- Apache 2.4.7
- MySql 5.5.54
- PHP 7.0.16
The WordPress installation I’m testing with is a clean install of:
- WordPress 4.7.2
- WooCommerce 2.6.14
- Twenty Seventeen Theme
No other plugins or code adjustments.
Furthermore, I wrote a small npm application, which incrementally adds products to WooCommerce by using the API. After each insertion of data, the application pauses five seconds, to give garbage collection and MySql a break and then performs some tests, like reading products from the WooCommerce API or requesting the “Shop”-page from the front-end, while measuring both request-time and the average of the MySql cpu and memory usage.
The inserted products are simple WooCommerce products, with auto-generated lorem-ipsum titles, description and a random price.
Checkout the test application on GitHub, feedback and contributions very welcome:
After cloning, go to the app folder and run
Then adjust the configuration parameters in index.js to your environment and run the application with a simple
After completing the test cycle, the test data is written to a benchmark csv file in the benchmark directory of the app directory.
There are three questions, I wanted to answer.
- Is WooCommerce really getting slower with many products and how much?
- Is it WooCommerce slowing down the performance or is it actually WordPress, which is slow?
- If we can confirm a slow WooCommerce with many products, why is that happening?
Besides these general questions, I was interested in two use-cases. The obvious one was request times for the WooCommerce front-end, because that’s impacting conversions and sales. The second one was the insertion speed of new products with a big database. That one is important, because most shops with around 10000 products and more, most likely have some kind of import process, which might add load to the entire server. Since we talking about imports, which can go on for hours, that’s quite relevant.
Slow WooCommerce performance with 50 000 Products?
In my first test I wanted to check a really huge product database, so I could get a full picture of what’s happening. After some tries and time calculations, I decided to run with 50 000 products, starting my test tool with the following environment variables (MySql and WP configuration in the index.js file).
MYSQL_PID=4333 ITERATIONS=500 POST_INSERT_CHUNK=100 npm start
CPU and Meta Table
After a good nights sleep, the test was finally through. What I could say from how my computer behaved during the test (noisy and warm), there had to be some CPU-usage, which you can see in the first image. The other two lines in the chart are the amount of added post in each step (confirming the test went as planned) and the size of the
As you see, is the size of the meta-table (yellow), rising much faster than the size of the products-table (green), which we will discuss later. The CPU-usage seems to increase logarithmic, slowly approaching the 100%.
Just to clarify: the CPU-usage is measured only when the requests are done, not during the insert product calls.
The next chart I’ve created, shows, how the CPU-usage affects the front-end request times. After every product insertion cycle, test requests where made to the shop-page, which is listing the first ten products and a single product page.
The overall development of the chart shows, that all the time, the single product page loading times are quite stable. The shop pages loading times increase directly from the beginning though. That’s what I would expect, because the shop-page queries the entire products table and needs to load meta data for at least ten products, while the single product page only needs to do that once.
Furthermore, we can see two quite obvious changes in the chart. Around 15 000 products (step 150) the CPU aproaches 50%, and we get a bigger variation in the loading times. Nonetheless, the single product times seem to be quite stable, but the shop-page times clearly increase. The same happens again, when the CPU-usage passes 70%, around 35 000 products.
The speed of adding new products obviously increases with the amount of products, which is expected. I didn’t expect such an increase, though. I would have thought, that you have to operate WooCommerce with many more products, to get from around 4 seconds per 100 products to much more than a minute.
For the last dip of increase time around 45 000 products I have no explanation. Might be that some resources were freed on my computer, not really sure, though.
Slow WooCommerce performance with 10 000 Products?
To double-check the previous results, I ran the same tests with only 10 000 products. I both wanted to see, if the test with lesser products would lead to the same conclusions and decrease test-time for further runs. Before this new test, I restored the initial database, from before the other test, than ran the following command:
MYSQL_PID=4333 ITERATIONS=100 POST_INSERT_CHUNK=100 npm start
The CPU-usage is rising, even with 10 000 products. It goes up to about 30%, which matches the 10 000 product value of the previous test. Meta-table and product count behave as expected.
Even the requests show the same picture. The shop-page request time seems to rise accordingly to the CPU-usage, which was the same in the 50 000 test, below the 15 000 products mark. The single product page loads steadily between 100 and 150ms.
The same goes for insertion speed, which shows a similar picture as above.
What Causes a Slow WooCommerce with Many Products
Now, one of my questions was, what causes slow WooCommerce queries and if the problem actually is related to WooCommerce? From experience with prior projects, I knew the answer already and had a quite good idea what the reason was. However, it’s always nice to confirm your assumptions with data.
Big Meta Table = Long Loading Times
My experience was, that WooCommerce performance problems with many posts are mainly related to the size of the meta table. As we have seen above, is the table growing quite fast when you add more products. After adding 50 000 products, it contained around 650 000 rows. To test if the meta-table assumption was accurate, I added a function to my application, which removes all WooCommerce meta-fields after each product insertion cycle. The following command runs the 10 000 test with that addition.
MYSQL_PID=4333 ITERATIONS=500 POST_INSERT_CHUNK=100 npm start
The CPU-chart already shows, that the idea seems to be correct. Without the big meta-table, the CPU-usage is slightly increasing, but almost stable, compared to before.
The requests-chart gives us the same impression. The shop-page request time follows the usage values and is stable between 80 and 100 milliseconds.
Only the insertion speed is painting another picture. Here we have no performance advantage at all, removing the meta-fields. I’ve added the grey line of instertion times from the previous test and it actually is almost identical. That was surprise, I have to admit, I thought there would be at least some difference.
So, that was fun. But is there something we can do about it? Shouldn’t we use WooCommerce for more than 15 000 products?
Yes, you should use WooCommerce, even for many products. But with the knowledge we gathered here, we are able to make some decisions early on, when building a shop, which should help us along the road.
Some tips to avoid slow WooCommerce:
- Check before you start building, how many products the shop will be selling, now and in the future.
- Avoid more meta-fields than absolutely necessary, that includes meta-fields on other post-types as well.
- As much as we love Advanced Custom Fields: for a big shop, you might want to skip on it. For every field you add to a product with ACF, you get 2 meta-fields in the database.
- Think about an eventual import process very early and test it several times, while building the shop. You need to know how much time it will take.
- Inform everyone about eventually long import sessions and the extra load on the servers they are causing.
- Use a good caching-plugin, which takes load form your server and frees resources for other stuff.
Even if you do everything right, at some point all precautions wont help. Then you have to think about widening you infrastructure. There are some tools which can help, like Elastic Search or Redis, and there are surely a hundred ways to code your way around WooCommerce limitations (e. g. two of my workarounds for the admin panel). And, last but not least, there is always the possibility of a bigger server or a more advanced architecture.