Skip to content

[DoctrineMessenger] [WIP] Postgres LISTEN/NOTIFY improvement proposition for better handling of time limit, multi-queue worker and delayed tasks #47666

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

Open
wants to merge 2 commits into
base: 7.3
Choose a base branch
from

Conversation

d-ph
Copy link

@d-ph d-ph commented Sep 22, 2022

Q A
Branch? 6.2 for features
Bug fix? no
New feature? yes
Deprecations? yes
Tickets Fix #46862
License MIT
Doc PR todo
  • fix the tests as they have not been updated yet
  • submit changes to the documentation
  • document the BC breaks
  • finish the code
  • gather feedback for my changes

This PR at present contains a code change that covers the improvement proposition no. 1, mentioned in #46862.

The code change spans 2 projects:

  1. Symfony: this PR.
  2. DoctrineBundle: d-ph/DoctrineBundle@ae224f3 (not PR'd yet).

Comments:

  1. I tested it in my small project and it works better than I expected. Obviously this is subjective, but perhaps worthwhile to mention.
  2. The biggest conceptual change is that the new implementation forbids starting a Messenger Worker for queues that are (1) a mixture of postgres and non-postgres, and (2) if the postgres queues use different pg_notify options that are relevant to the implementation (e.g. the pg_notify timeout, or the db table name used by the queue). I'd say that the requirement is not a problem, since it's rare for devs to use a mixture of backend queue solutions, and even if they do use them, then it's still just a matter of starting the Worker with different set of queues.
  3. The PostgreSqlWaitForPgNotifyOnIdleListener::registerPostgreSqlConnectionCandidate() is an annoying necessity stemming from the fact that there is no way to retrieve the Symfony\Component\Messenger\Bridge\Doctrine\Transport\Connection out of DoctrineReceiver and DoctrineTransport. If a getter is added to both of this classes, then the ::registerPostgreSqlConnectionCandidate() may be removed, which I would recommend doing if that's ok. It would also remove the necessity of injecting PostgreSqlWaitForPgNotifyOnIdleListener to DoctrineTransportFactory.
  4. Symfony\Component\Messenger\Bridge\Doctrine\Transport\Connection::$queueEmptiedAt is removed. This is a nice side effect of the proposed code change, since the variable was related to an obscure postgres implementation detail.
  5. PostgreSqlConnection now doesn't override the get() function, which perhaps is a plus.
  6. PostgreSqlWaitForPgNotifyOnIdleListener::choosePgNotifyTimeout() is awaiting the "improvement proposition no. 2" implementation, which I'd say is the "killer feature" of the related github ticket.
  7. PostgreSqlConnection::'check_delayed_interval' option is no longer used, and will become deprecated. It's expected to be replaced with "improvement proposition no. 2".

@carsonbot
Copy link

Hey!

I think @deguif has recently worked with this code. Maybe they can help review this?

Cheers!

Carsonbot

@nicolas-grekas nicolas-grekas modified the milestones: 6.2, 6.3 Nov 5, 2022
@christian-kolb
Copy link

@nicolas-grekas Even though this is includes a logic change, shouldn't it be considered a bug fix as at multiple queues (which just means prioritizing messages) is kind of broken at the moment?
@d-ph I'm having the same issue in my project and would love to use this fix. Any way I can support you on it?

@d-ph
Copy link
Author

d-ph commented Nov 14, 2022

Hi Christian,

Any way I can support you on it?

I'm waiting for someone to say "yes/ok" to the points: 2, 3 (to allow an addition of the getter), 6 (to include the "additional" improvement in the scope of this PR), and 7. When I get an approval (or at least an interest in principle), then I'll go ahead and complete this PR (but I might have some further questions about unit testing, and online documentation). So if it's in your ability to obtain this, then please do.

The PR contains a running and working code (but note the "sibling" PR for DoctrineBundle), however at present it only includes the code for problem 1, mentioned in #46862. Feel free to fork the 2 git repositories, and install them via composer in your app. The code is obviously not unit-tested, so it may break between Messenger minor/major updates, but it does work at present.

Not much else I can say in that regard. At the very least, I'm not going to invest my time in finishing this PR, if I don't see any interest from the Symfony maintainers. I might at some point write a separate Postgres(Messenger)Transport with the changes mentioned in the github ticket, just for my own use.

@christian-kolb
Copy link

@d-ph Unfortunately that's not going to be me as I'm not part of that group. But @nicolas-grekas marked it for the next milestone. Isn't that kind of an confirmation?

@d-ph
Copy link
Author

d-ph commented Nov 16, 2022

Chris,

I'm not going to play a "what the poet meant" regarding milestones assignment.

I don't think I ask for much, considering the fact that I'm going to be doing the heavy-lifting.

@christian-kolb
Copy link

I'm sorry. That wasn't meant as a push but rather as "I just realized, did you see that". I also don't know what it means ether, and hoped you might.
You're definitively not asking for too much.
@nicolas-grekas Can you confirm the scope that is tackled here and that this approach would be merged and supported?

@bendavies
Copy link
Contributor

this PR needs to take #47209 into account

…es with custom consumption priorities. Replay symfony#47209 on top of this code change.
@nicolas-grekas nicolas-grekas modified the milestones: 6.3, 6.4 May 23, 2023
@nicolas-grekas nicolas-grekas modified the milestones: 6.4, 7.1 Nov 15, 2023
@christian-kolb
Copy link

@nicolas-grekas This PR was moved to different milestones twice, but the author is still waiting on a confirmation / guidance from you before finalizing the PR. Otherwise I guess this will be moved to the next milestone again 😞

@christian-kolb
Copy link

@nicolas-grekas @fabpot This PR was moved to different milestones again, but the author is still waiting on a confirmation / guidance from you before finalizing the PR. Otherwise I guess this will be moved to the next milestone again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
7 participants