If you’re running an Adobe Commerce Cloud (formerly known as Magento) store, you know how important it is to keep your store running smoothly. One of the key processes that keeps your store up-to-date is indexing. Indexing ensures that your product data, prices, and other information are current and accurate. However, as your store grows, indexing can become slower, especially if you have a large catalog or frequent updates.
The good news is that Adobe Commerce Cloud provides a way to speed up indexing by using a feature called MAGE_INDEXER_THREADS_COUNT. In this blog, we’ll explain what this feature is, why it’s useful, and how you can set it up in your Adobe Commerce Cloud environment.
In adobe commerce, you can either add an environment variable to the env.php file or use the environment variable MAGE_INDEXER_THREADS_COUNT when running the reindex command in parallel mode. The number of threads used for the reindex procedure is determined by this variable.
What is MAGE_INDEXER_THREADS_COUNT?
MAGE_INDEXER_THREADS_COUNT
is an environment variable that allows you to control how many threads (or processes) are used during indexing. By default, Adobe Commerce runs indexing tasks one at a time, which can be slow for large stores. By increasing the thread count, you can split the indexing workload across multiple threads, making the process faster and more efficient.
For example, if you set MAGE_INDEXER_THREADS_COUNT
to 4, Adobe Commerce will use 4 threads to process indexing tasks simultaneously. This can significantly reduce the time it takes to complete indexing.
Why Should You Use MAGE_INDEXER_THREADS_COUNT?
Here are some benefits of using this feature:
- Better Resource Utilization: If your server has multiple CPU cores, increasing the thread count allows you to take full advantage of your hardware.
- Faster Indexing: By using multiple threads, indexing tasks are completed much quicker, especially for large catalogs.
- Improved Store Performance: Faster indexing means your store’s data is updated sooner, ensuring customers see the most accurate information.
How to Set MAGE_INDEXER_THREADS_COUNT in Adobe Commerce Cloud
1. Edit the .magento.env.yaml File
Locate the .magento.env.yaml
file in your project’s root directory (or create it if it doesn’t exist).
Add the MAGE_INDEXER_THREADS_COUNT
variable under the env
section in the stage
> deploy
phase.
stage:
deploy:
env:
variables:
MAGE_INDEXER_THREADS_COUNT: 4
Replace 4
with your desired thread count (e.g., based on your Cloud infrastructure’s CPU cores).
2. Commit and Push Changes
- Commit the updated
.magento.env.yaml
file to your Git repository. - Push the changes to trigger a redeployment of your Adobe Commerce Cloud environment.
Example .magento.env.yaml
stage:
deploy:
env:
variables:
MAGE_INDEXER_THREADS_COUNT: 4
# Other variables (optional)
CRON_CONSUMERS_RUNNER: true
CONFIG__DEFAULT__WEB__SECURE__USE_IN_FRONTEND: 1
3. Validate after deployment using ece-tools
php ./vendor/bin/ece-tools cloud:config:validate
Bonus Trick
You can run command manually via below parameter
MAGE_INDEXER_THREADS_COUNT=3 php -f bin/magento indexer:reindex catalogsearch_fulltext
Best Practices for Using MAGE_INDEXER_THREADS_COUNT
- Match Thread Count to CPU Cores: Set the thread count to match the number of CPU cores available on your server. For example, if your server has 4 CPU cores, set
MAGE_INDEXER_THREADS_COUNT
to 4. - Monitor Performance: After increasing the thread count, monitor your server’s performance to ensure it’s not overloading the CPU or memory.
- Test in Staging First: If you’re unsure about the optimal thread count, test different values in your staging environment before applying them to production.
Example Use Case
Imagine you run an online store with 50,000 products. Every time you update prices or inventory, the indexing process takes over an hour to complete. By setting MAGE_INDEXER_THREADS_COUNT
to 4, you can reduce the indexing time to just 15-20 minutes, ensuring your store’s data is updated quickly and efficiently.
Conclusion
Using MAGE_INDEXER_THREADS_COUNT
is a simple yet powerful way to speed up indexing in Adobe Commerce Cloud. By optimizing the number of threads used during indexing, you can improve your store’s performance and provide a better experience for your customers.
If you haven’t already, try adding this setting to your .magento.env.yaml
file and see the difference it makes. And remember, always test changes in a staging environment before applying them to your live store.
Happy indexing! 🚀
You may also like,
Adobe Commerce Security: CSP, Escaping, Form Keys, Sanitization, reCAPTCHA, Input Validation
How to Create New Commands in Magento 2 CLI
Fastly : How to set basic authentication for a specific page in Magento 2
Leave a Comment