-
Notifications
You must be signed in to change notification settings - Fork 18
Create an easy way to kill all currently running message queue consumer processes #181
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
Comments
Another solution could be to have a configurable maximum wait timeout. If the timeout is exceeded, the consumer should perform the PoisonPill check, and then continue to wait for a new message. I'm not familiar enough with the message queue implementation though to know if this is technically possible, or how easy/difficult it will be to implement. |
Our common recommendation is to not introduce infrastructure code in Magento if it possible. For example, if you use Kubernetes job, you don't need any code in Magento, you can just delete job and start new after deployment. |
@kandy: Yes I agree, we shouldn't rely on server infrastructure on how to restart these processes. This ticket was created for this purpose. Magento should have an easy way to indicate to the consumer processes that they should self-destruct somehow. @FreekVandeursen: yes, that could be a solution, next to only performing the poison pill check after a new message was added to the queue, also check on regular (configurable?) intervals if the poison pill version was changed. But that interval can't be too high. Especially in deployment scenario's, you want the consumers to stop existing as fast as possible, so that newly deployed code (which is used by the MQ consumers) can be executed again as soon as the deploy is finished. |
Just accidentally stumbled over the Maybe it makes sense to take a look at that component to see if there are other interesting things they are doing? |
The symphony mechanism that stops the queue actually just puts into cache a flag that the queue consumer reads that will exit after next job is finished. https://github.com/symfony/messenger/blob/master/Command/StopWorkersCommand.php In theory the poison pull mechanism already does this just not in the way we need. the callback invoker checks for a change in the version This does reject the next item in the queue, then exit the process with an exit(0) I see a few choices here, we could just make a cli command that calls That would just put a new version into the DB making the processes kill themselves on the next message they process. The only issue I see with this is if you don't have a message for a long time after a deployment then your consumer will become more and more out of date. I could see a second option here, we could lock the queue, check it for any processing items and the moment that there are no longer any processing items, kill the consumer. |
Thanks for the feedback @Luwdo! The questions posed in this issue and in #180 have been thrown together and put into an architectural proposal already, which you can see over here: Feel free to leave comments or suggestions on that proposal (it's not because it is already accepted that it is perfect) |
Problem 2 is exactly my issue that I have been working on. I just finished a stopgap measure for our production sites and published it here: I do not see mention about moving the PIDs themselves to a standard folder under var |
Nice work! But be aware that the pid files have been removed in the latest version of Magento (version 2.3.3), by magento/magento2@1d9e07b, I think they are now using locking in the database to make sure no duplicated consumers spawn. |
We've just come across this issue (customer's complaining about exports not working), turns out it was the consumers running in the old deployment release directories and creating the files in the wrong root folders. Our fix for now is a quick |
@davidwindell: we do something like this: davidalger/capistrano-magento2#133 (comment) Magento should really implement something easy we can call with the command line, like proposed in https://github.com/magento/architecture/blob/master/design-documents/asynchronous-operations/consumer-processes-improvements.md#problem-2-deployment-problems (problem 2), but I and Magento devs haven't found time yet to implement that. |
Thanks so much @hostep this inspired me to replace the killall with:
In our Deploybot config 👍 |
I don't see any problem in this case? I mean we can let the consumer running until new message comes, do you see any problem with this? @hostep |
There's a pending PR with a solution for this BTW: magento/magento2#31495 @onlinebizsoft: so far we haven't seen big issues with this new solution (which we've patched into some of our shops), besides the process using a bunch of memory, but that's about it. |
Uh oh!
There was an error while loading. Please reload this page.
Hi folks
It would be great if we can have some easy way to stop all current message queue consumer processes running on the server.
We are having some problems in our deploy flow that old message queue consumer processes keep running using old code from memory even after new code has been deployed.
I know there is this new poison pill mechanism, where message queue consumer processes kill themselves if they notice some configuration has changed and if they have at least one new incoming message.
I would like to see something similar, where we can say to the message queues consumers that there is some new code deployed and they should stop themselves, in order to start up again using the new code.
The other problem is that this poison pill feature currently only kicks in after a new message was added to the queue. This could potentially take many week/months/years until this happens if a specific consumer is only used very infrequently. So that's not really ideal.
We are currently fixing it in our deploy flow, by finding all process id's in the
var/
directory, and killing them one by one with thekill
command.But I don't know how safe that is to do if a message is currently being processed as we kill that process. I don't know if the message queue consumer system in Magento can deal with that in a nice way or not?
So if we would have an option to say via command line that message queue consumers should kill themselves, that would be really great I think.
A potential idea would be to have a command which changes the poison pill version in the database and also sends a single dummy message in all the consumer queues which does nothing except to indicate to the consumer that it should kill itself.
Thoughts, other ideas?
Thanks!
The text was updated successfully, but these errors were encountered: