Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

setup:upgrade is changing indexer mode to save from schedule slowing it down immensely #33386

Open
1 of 5 tasks
ioweb-gr opened this issue Jun 30, 2021 · 50 comments
Open
1 of 5 tasks
Labels
Area: Framework Area: Performance Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Priority: P2 A defect with this priority could have functionality issues which are not to expectations. Progress: ready for dev Reported on 2.4.x Indicates original Magento version for the Issue report. Reproduced on 2.4.x The issue has been reproduced on latest 2.4-develop branch Triage: Dev.Experience Issue related to Developer Experience and needs help with Triage to Confirm or Reject it

Comments

@ioweb-gr
Copy link
Contributor

ioweb-gr commented Jun 30, 2021

I have a fairly large catalog on a website and I've noticed that sometimes setup:upgrade takes a very very long time to complete. More than 30 minutes.
It's not always occuring which makes it hard to track but by carefully examining what is happening I noticed that the command is dropping and recreating the database triggers when the indexers are set on scheduled mode. However with the indexers on save mode, the backend takes a very long time to save products and especially categories.

So our only option on big catalogs is to use the indexers on schedule mode.

By examining further I went and forced a check on the mview_state table to see what script is changing the indexer mode during setup:upgrade and so the command threw an exception as expected when executing the following query

UPDATE `mview_state` SET `view_id` = ?, `mode` = ?, `status` = ?, `updated` = '2021-06-30 05:57:46', `version_id` = ? WHERE (state_id=5)
View.php:225, Magento\Framework\Mview\View->unsubscribe()
TriggerCleaner.php:63, Magento\Framework\Mview\TriggerCleaner->removeTriggers()
Installer.php:1726, Magento\Setup\Model\Installer->removeUnusedTriggers()
UpgradeCommand.php:145, Magento\Setup\Console\Command\UpgradeCommand->execute()
Command.php:255, Magento\Setup\Console\Command\UpgradeCommand->run()
Application.php:1009, Magento\Framework\Console\Cli->doRunCommand()
Application.php:273, Magento\Framework\Console\Cli->doRun()
Cli.php:115, Magento\Framework\Console\Cli->doRun()
Application.php:149, Magento\Framework\Console\Cli->run()
magento:36, {main}()

Then I was able to see that the functions
\Magento\Framework\Mview\View::unsubscribe
\Magento\Framework\Mview\View::subscribe

Are executed for all indexers regardless, which will trigger dropping and re-adding the database triggers.

However dropping a trigger and recreating in a fairly large database is taking a long time to complete causing significant downtime.

It seems I'm not the only one facing this issue https://magento.stackexchange.com/questions/330245/magento-2-indexers-sometimes-switchon-their-own-to-update-on-save-when-config

Preconditions (*)

  1. 2.4.1

Steps to reproduce (*)

  1. A fairly large catalog with lots of categories (over 5000) and products (over 60k with over 200 attributes)
  2. The indexers set on schedule mode.
  3. Execute setup:upgrade

Expected result (*)

  1. I expect that setup:upgrade finishes fast and doesn't recreate the triggers if it's not needed. If the trigger exists, it shouldn't drop and recreate it. Only If it does not exist should it create it.
  2. It should never change the mode from schedule to save. The user has put it for a reason there

Actual result (*)

  1. setup:upgrade is always recreating the triggers causing huge downtime during the command execution
  2. sometimes the indexers never revert back to the scheduled mode and stay on save mode

Additional Information


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”.
@m2-assistant
Copy link

m2-assistant bot commented Jun 30, 2021

Hi @ioweb-gr. Thank you for your report.
To help us process this issue please make sure that you provided the following information:

  • Summary of the issue
  • Information on your environment
  • Steps to reproduce
  • Expected and actual results

Please make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, please, add a comment to the issue:

@magento give me 2.4-develop instance - upcoming 2.4.x release

For more details, please, review the Magento Contributor Assistant documentation.

Please, add a comment to assign the issue: @magento I am working on this


⚠️ According to the Magento Contribution requirements, all issues must go through the Community Contributions Triage process. Community Contributions Triage is a public meeting.

🕙 You can find the schedule on the Magento Community Calendar page.

📞 The triage of issues happens in the queue order. If you want to speed up the delivery of your contribution, please join the Community Contributions Triage session to discuss the appropriate ticket.

🎥 You can find the recording of the previous Community Contributions Triage on the Magento Youtube Channel

✏️ Feel free to post questions/proposals/feedback related to the Community Contributions Triage process to the corresponding Slack Channel

@ioweb-gr
Copy link
Contributor Author

I'm not able to test this on the demo instance.

@engcom-November engcom-November self-assigned this Jul 6, 2021
@m2-assistant
Copy link

m2-assistant bot commented Jul 6, 2021

Hi @engcom-November. 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: 👇

  • 1. Verify that issue has all the required information. (Preconditions, Steps to reproduce, Expected result, Actual result).

    DetailsIf the issue has a valid description, the label Issue: Format is valid will be added to the issue automatically. Please, edit issue description if needed, until label Issue: 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 branch

    Details- Add the comment @magento give me 2.4-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.4-develop branch, please, add the label Reproduced 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.

@ioweb-gr
Copy link
Contributor Author

ioweb-gr commented Jul 18, 2021

Let me add more info here. I tracked down this post

https://maxchadwick.xyz/blog/lessons-learned-during-a-recent-magento-2-deploy

It seems that during operations which lock the tables, dropping the trigger or creating it has to actually wait for all database locks to disappear.

Looking further into the process I noticed that in my case it was trying to build the catalog price replica tables for the indexes which were locking the tables like this


 DELETE FROM `catalogrule_product_price_replica` WHERE (product_id NOT IN ((SELECT `crp`.`product_id` FROM `catalogrule_product_price`

Causing a lot of queries to wait during setup:upgrade making the downtime extremely high. Unfortunately even if you build the files in a different server the setup:upgrade procedure has to run on the production.

This should never ever happen and cause such unpredictable downtimes

This is what the end result in mytop looks like in such cases

image

@onlinebizsoft
Copy link

I think I have same issue. Will track this behavior and see

@ioweb-gr
Copy link
Contributor Author

I've seen it happen in 3 installations on 3 different servers and now before setup:upgrade I make sure all indexers are green to avoid the issue. I will report back if this stops occuring like this but it would be great if it can be verified

@ioweb-gr
Copy link
Contributor Author

ioweb-gr commented Aug 5, 2021

Just an update, while following this practice the downtimes have reduced significantly because the locks are staying for a smaller period. The issue still persists but is minified like this.

Basically I can verify that if the indexers are running on scheduled mode, the issue can happen with setup:upgrade if they have items in the backlog

@engcom-November engcom-November removed their assignment Aug 25, 2021
@engcom-Delta engcom-Delta self-assigned this Sep 1, 2021
@m2-assistant
Copy link

m2-assistant bot commented Sep 1, 2021

Hi @engcom-Delta. 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: 👇

  • 1. Verify that issue has all the required information. (Preconditions, Steps to reproduce, Expected result, Actual result).

    DetailsIf the issue has a valid description, the label Issue: Format is valid will be added to the issue automatically. Please, edit issue description if needed, until label Issue: 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 branch

    Details- Add the comment @magento give me 2.4-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.4-develop branch, please, add the label Reproduced 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.

@engcom-Delta engcom-Delta added Issue: needs update Additional information is require, waiting for response and removed Issue: ready for confirmation labels Sep 2, 2021
@engcom-Delta
Copy link
Contributor

Hi @ioweb-gr
it works fine on Magento 2.4-develop instance, I would request to try once again & confirm .Hence added the label ''Needs update'

Thanks

@ioweb-gr
Copy link
Contributor Author

ioweb-gr commented Sep 8, 2021

Hi, what do you mean it's working fine?

Let's take it one step at a time.

Did you verify that during setup upgrade triggers are dropped and recreated?

@engcom-Delta
Copy link
Contributor

Hi @ioweb-gr ,
We could not notice that during setup upgrade triggers are dropped & recreated.
Thanks

@ioweb-gr
Copy link
Contributor Author

@engcom-Delta

I see. Here's how to guarantee that you'll see triggers are dropped and recreated.

Step 1: Put all indexers in scheduled mode.
Step 2: Modify database table mview_state and add the following check

CHECK (mode = 'enabled')

Step 3: Execute setup upgrade

How does this guarantee you'll notice the issue?

First of all when indexers change mode from save to schedule and vice versa, triggers are created and dropped in order for the indexers to function.

By adding the above check, when setup:upgrade executes it's going to throw an exception because of a DB level constraint.

At that point you'll know for sure, that the mode on the indexer was changed from scheduled to save and that the setup:upgrade command tried to drop / recreate the triggers.

Could you give it a try?

@m2-assistant
Copy link

m2-assistant bot commented Sep 29, 2021

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: 👇

  • 1. Verify that issue has all the required information. (Preconditions, Steps to reproduce, Expected result, Actual result).

    DetailsIf the issue has a valid description, the label Issue: Format is valid will be added to the issue automatically. Please, edit issue description if needed, until label Issue: 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 branch

    Details- Add the comment @magento give me 2.4-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.4-develop branch, please, add the label Reproduced 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.

@engcom-Hotel
Copy link
Contributor

Hello @ioweb-gr,

We have tried to reproduce the issue in Magento 2.4-develop branch with the following data:

  • 10 Lakhs product
    image
  • 3053 Product Attributes
    image
  • Indexer is set on update on schdule

But for us the setup:upgrade not taking that much time. We have recorded a video related to that. Please have a look and let us know if we have missed anything:

video.mp4

Thanks

@ioweb-gr
Copy link
Contributor Author

Hi, that only means that you cannot simulate real conditions this way.

On our client's store we have around 60k products, 500 orders daily, 50-150 concurrent customers browsing the website at all times, 5 people doing data entry, multiple catalog price rules, 5 sources, 11 stocks etc etc.

The indexers are constantly having items on queue to reindex and while it's not always happening that setup:upgrade is extremely slow I have seen cases where it will take a long time (even 15minutes) contrary to the normal ones when it needs a few seconds.

Usually the queries running in the backend as showcased by mytop are related to MSI indexers running for stock or catalog rule pricing ones in our specific case.

The best way I found to replicate this is to actually have a reindexing process running on an amount of data, that will lock the tables and then try to do a setup:upgrade. Because the lock exists, the process will hang for an indefinite period of time until the lock is released.

But in spite of this side-effect, the underlying issue is still puzzling me.

If I've decided to set my indexers to schedule mode. Why would they need to change to work on save and then back to schedule during setup:upgrade? There's nothing to gain by that, it only adds time to the setup:upgrade process.

@hostep
Copy link
Contributor

hostep commented Jan 22, 2022

@kandy: maybe it helps if a senior developer could have a look here? The engcom squad seems to not understand this problem because I think they miss some deeper knowledge about this sort of complicated functionality of Magento.

@joeshelton-wagento
Copy link

Same issue here on a busy store.

@kadirakinkorkunc
Copy link

Any solution? @joeshelton-wagento @ioweb-gr

@ioweb-gr
Copy link
Contributor Author

ioweb-gr commented Feb 9, 2022

Not really, expecting Magento to confirm this is happening at the very least so a few more voices might help

@sdzhepa
Copy link
Contributor

sdzhepa commented Feb 17, 2022

After an internal discussion and based on multiple complaints we confirmed this issue.
For such type of issue is not trivial to describe simple(or end-user) steps to reproduce.

Also, it is hard to predict final performance results. Theoretically, numbers should be better
So, as Acceptance Criteria for this issue should be performance measurement before and after

Suggested approach

  1. Check triggers declaration -> update only if it changes
  2. Check referenced tables from the trigger body -> update trigger if table structure was changed

cc: @ioweb-gr @hostep
cc2: @engcom-Hotel @kandy @sidolov @akaplya

@ioweb-gr
Copy link
Contributor Author

@engcom-Hotel we are still seeing this in 2.4.6

@sanderjongsma
Copy link
Contributor

I can confirm it is still happening in 2.4.6

@engcom-Hotel
Copy link
Contributor

Let me reopen it for further investigation.

@engcom-Hotel engcom-Hotel reopened this Oct 12, 2023
@m2-community-project m2-community-project bot removed Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Reproduced on 2.4.x The issue has been reproduced on latest 2.4-develop branch Progress: done labels Oct 12, 2023
@engcom-Bravo engcom-Bravo added the Triage: Dev.Experience Issue related to Developer Experience and needs help with Triage to Confirm or Reject it label Oct 12, 2023
@Alexander-Khohklov
Copy link
Contributor

@magento I am working on this

@engcom-Hotel
Copy link
Contributor

According to this comment #33386 (comment) and multiple complaints related to this issue, we are reconfirming this issue.

Thanks

@engcom-Hotel engcom-Hotel added Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Reproduced on 2.4.x The issue has been reproduced on latest 2.4-develop branch labels Oct 13, 2023
@github-jira-sync-bot
Copy link

❌ Cannot export the issue. This GitHub issue is already linked to Jira issue(s): https://jira.corp.adobe.com/browse/AC-2423

@MaikJaek
Copy link

According to the release notes, this issue has been solved with Magento 2.4.6.:
image

@ioweb-gr
Copy link
Contributor Author

Apparently it's not working properly though

@bhouillon
Copy link

Hi,
Is there a quality patch already existing for this issue ?
We are facing it on 2.4.7-p2

@jonathanribas
Copy link

jonathanribas commented Aug 27, 2024

Hi, in order to battle this core issue, we use the following module for a while now without any issue:
https://github.com/pykettk/module-indexer-deploy-config

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Framework Area: Performance Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Priority: P2 A defect with this priority could have functionality issues which are not to expectations. Progress: ready for dev Reported on 2.4.x Indicates original Magento version for the Issue report. Reproduced on 2.4.x The issue has been reproduced on latest 2.4-develop branch Triage: Dev.Experience Issue related to Developer Experience and needs help with Triage to Confirm or Reject it
Projects
Status: Ready for Development
Development

No branches or pull requests