-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Messenger] Adds option to force indexes creation in Mysql platform for Doctrine transport #45007
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
Conversation
Hey! I see that this is your first PR. That is great! Welcome! Symfony has a contribution guide which I suggest you to read. In short:
Review the GitHub status checks of your pull request and try to solve the reported issues. If some tests are failing, try to see if they are failing because of this change. When two Symfony core team members approve this change, it will be merged and you will become an official Symfony contributor! I am going to sit back now and wait for the reviews. Cheers! Carsonbot |
Hey! I think @nikophil has recently worked with this code. Maybe they can help review this? Cheers! Carsonbot |
indeed, and sometime even as main backend for messenger as generaly all project do have a database but not a redis nor rabbitmq etc |
Can I do something to push forward this PR? Ci has failed for memory reason, not for code |
Confirming that with a large dataset in the table, this is just not usable... |
I'd prefer if this were not configurable. |
/cc @PalTamasWBA also in case you can help us make the best move here. |
Wouldn't that make it even worse? Requeueing would mean even more write attempts on a table which is already under stress due to locks. Basically, whenever this transport is used in a high-concurrency environment (which IMO should be discouraged), it starts exhibiting the needs of #42345; if you instead use it as a failed queue (which is what I and @gianiaz do), it's the opposite, the indexes become a must. [EDIT] IMHO this is a sensible approach; maybe you can decide to reverse the default and push for discouraging its use in high-concurrency environments, and suggest putting the value to |
The issue is not the transport, but MySQL, since eg PostgreySQL doesn't exhibit the behavior. |
An exception is raised, so probably the handling fails, and the retry/failed mechanisms of Messenger kicks in.
IMO we should proceed with a failed handling, and this PR acts as a differentiator between two main possible situations:
We definitely could. But depending on the context, if you leave the indexes you create a cascading failure scenario, with the retry/failed mechanism that makes the locking issue worse. So IMHO #42345 is still a valid approach, just not everywhere, and this PR provides the means to avoid that. |
I'm proposing #45888 instead, can you please have a look? |
…ks using soft-delete (nicolas-grekas) This PR was merged into the 4.4 branch. Discussion ---------- [Messenger] Add mysql indexes back and work around deadlocks using soft-delete | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | Fix #42868 | License | MIT | Doc PR | - #42345 removed some indexes because they create too many deadlocks when running many concurrent consumers. Yet, as reported in the linked issue, those indexes are useful when processing large queues (typically the failed messages queue). #45007 is proposing to add an option to force the indexes back, but I don't like it because it requires ppl to learn about the issue. I looked for a more seamless solution and here is my proposal. Instead of possibly triggering the deadlock during `ack()`/`reject()`, I propose to use a soft-delete there, and do the real delete in `get()`. This makes ack/reject safe because they don't alter any indexes anymore (the delete was), and this moves deadlock exceptions to the same function that creates the locks. This allows the retry mechanism in `DoctrineReceiver` to recover from at most 3 consecutive deadlock exceptions. There can be more, and in this case, the consumer will stop. But this should be much less likely. (yes, I did create a reproducer to work on this issue ;) ) Commits ------- 12271a4 [Messenger] Add mysql indexes back and work around deadlocks using soft-delete
After upgrading to 5.4 I've had a migration on messenger_messages caused by #42345.
Considering that:
1- doctrine_transport is often used for failed messages
2- with large tables we have degraded performance without indexes
3- get/findAll/count methods in Connection.php are using
createAvailableMessagesQueryBuilder
symfony/src/Symfony/Component/Messenger/Transport/Doctrine/Connection.php
Lines 304 to 312 in 9f5238d
available_at
andqueue_name
are used.I would like to specify that in my conditions a migration for removing indexes should not be created.
Can I help in porting it in 5.4 or you have your flow for porting?
Thank you