magento2
magento2 copied to clipboard
Very slow `catalogrule_product` index even when no catalog rule exists
On a Magento 2.4.3 instance:
- I don't have any catalog rule
- I have ~100k products, mostly configurable
- I have 4 websites
- Have almost all my indexes setup on scheduled mode
Preconditions (*)
Steps to reproduce (*)
- Add some ids (or update some product attributes) into
catalogrule_product_cl
table. - Run
indexer_update_all_views
CRON job.
Expected result (*)
- Product ids quantity should not have that big impact in index processing time.
- The index process should end in a reasonable time.
Actual result (*)
- Product ids quantity is brutally impacting execution time.
- Index process should end in a moment, when no catalog rule is set.
Please provide Severity assessment for the Issue as Reporter. This information will help during Confirmation and Issue triage processes.
- [ ] Severity: S0 - Affects critical data or functionality and leaves users without workaround.
- [ ] Severity: S1 - Affects critical data or functionality and forces users to employ a workaround.
- [ ] Severity: S2 - Affects non-critical data or functionality and forces users to employ a workaround.
- [ ] Severity: S3 - Affects non-critical data or functionality and does not force users to employ a workaround.
- [ ] Severity: S4 - Affects aesthetics, professional look and feel, “quality” or “usability”.
Hi @dudzio12. Thank you for your report. To speed up processing of this issue, make sure that you provided the following information:
- Summary of the issue
- Information on your environment
- Steps to reproduce
- Expected and actual results
Make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, Add a comment to the issue:
@magento give me 2.4-develop instance
- upcoming 2.4.x release
For more details, review the Magento Contributor Assistant documentation.
Add a comment to assign the issue: @magento I am working on this
To learn more about issue processing workflow, refer to the Code Contributions.
- Join Magento Community Engineering Slack and ask your questions in #github channel.
:warning: According to the Magento Contribution requirements, all issues must go through the Community Contributions Triage process. Community Contributions Triage is a public meeting.
:clock10: You can find the schedule on the Magento Community Calendar page.
:telephone_receiver: The triage of issues happens in the queue order. If you want to speed up the delivery of your contribution, join the Community Contributions Triage session to discuss the appropriate ticket.
:movie_camera: You can find the recording of the previous Community Contributions Triage on the Magento Youtube Channel
:pencil2: Feel free to post questions/proposals/feedback related to the Community Contributions Triage process to the corresponding Slack Channel
protected function doReindexByIds($ids)
{
$this->cleanProductIndex($ids);
/** @var Rule[] $activeRules */
$activeRules = $this->getActiveRules()->getItems();
foreach ($activeRules as $rule) {
$rule->setProductsFilter($ids);
$this->reindexRuleProduct->execute($rule, $this->batchCount);
}
foreach ($ids as $productId) {
$this->cleanProductPriceIndex([$productId]);
## I've added `if` statement as seen below and there is no need to reindex prices
## if only above cleaning cleans it correctly and no activeRule exists.
## That only sppeds up indexation process more that 10 times
if (count($activeRules) > 0) {
$this->reindexRuleProductPrice->execute($this->batchCount, $productId);
}
}
$this->reindexRuleGroupWebsite->execute();
}
I'll prepare PR and run some tests with that change implemented. It won't fix non optimal index, but will lock some unnecessary code execution.
Hi @engcom-Hotel. Thank you for working on this issue. In order to make sure that issue has enough information and ready for development, please read and check the following instruction: :point_down:
-
[ ] 1. Verify that issue has all the required information. (Preconditions, Steps to reproduce, Expected result, Actual result).
Details
If the issue has a valid description, the labelIssue: Format is valid
will be added to the issue automatically. Please, edit issue description if needed, until labelIssue: Format is valid
appears. -
[ ] 2. Verify that issue has a meaningful description and provides enough information to reproduce the issue. If the report is valid, add
Issue: Clear Description
label to the issue by yourself. -
[ ] 3. Add
Component: XXXXX
label(s) to the ticket, indicating the components it may be related to. -
[ ] 4. Verify that the issue is reproducible on
2.4-develop
branchDetails
- Add the comment@magento give me 2.4-develop instance
to deploy test instance on Magento infrastructure.
- If the issue is reproducible on2.4-develop
branch, please, add the labelReproduced on 2.4.x
.
- If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and stop verification process here! -
[ ] 5. Add label
Issue: Confirmed
once verification is complete. -
[ ] 6. Make sure that automatic system confirms that report has been added to the backlog.
Fixed by https://github.com/magento/magento2/pull/34785
The performance of this indexer appears to be incredibly slow, as it reindexes products one by one, instead of in batches. I've taken a quick look at the code involved, and I can't really see a good reason why this has been done.
The select builder used is here - https://github.com/magento/magento2/blob/0a834cce01c3d924d450c9a71123d9ac6de68b62/app/code/Magento/CatalogRule/Model/Indexer/RuleProductsSelectBuilder.php#L81-L109
A single product id is passed in, and used to restrict the query to that product, but the query would still work if multiple products were passed in and an IN
clause was used instead.
Similarly, the place that calls and then uses the query built by RuleProductsSelectBuilder
is here - https://github.com/magento/magento2/blob/0a834cce01c3d924d450c9a71123d9ac6de68b62/app/code/Magento/CatalogRule/Model/Indexer/ReindexRuleProductPrice.php#L88-L112
This creates a key value using the product id coming from the data the query returns, so it too would still work with multiple products.
Maybe I'm missing something here, but I think that changing these functions to take in an array of product ids instead of a single one (and then batching appropriately in IndexBuilder
) would dramatically reduce the amount of time required.
:white_check_mark: Jira issue https://jira.corp.adobe.com/browse/AC-10911 is successfully created for this GitHub issue.
:white_check_mark: Confirmed by @engcom-Hotel. Thank you for verifying the issue.
Issue Available: @engcom-Hotel, You will be automatically unassigned. Contributors/Maintainers can claim this issue to continue. To reclaim and continue work, reassign the ticket to yourself.