-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Upgrading to symfony/messenger 6.4+ causes major CPU spike (min 2x load) because of unnecessary gc_collect_cycles() on every message #59788
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
Have the same issue on all versions 6.4.0 (php 8.2, 8.4) and higher (7.* included). On latest 6.3.* (php 8.1) all is fine. |
This comment has been minimized.
This comment has been minimized.
For your temporary hack, prefer using this https://github.com/cweagans/composer-patches its better imho :) Also, try opening a PR to make this gc call optional perhaps if you are sure its your culprit here? I use messenger but with amqp (prod) and doctrine (dev) and l didnt spotted this (or at least my devops teamate) |
Sharing hacks isn't very useful. They will stay forever and will mislead readers, even after a solution is found. So, this call has been added in #52253. I don't know a GC strategy that'd work for everybody, so we might need to make this optional. Another idea: have an optional (userland ?) event listener that implements the required logic to call the GC. |
@nicolas-grekas I am fine reverting it. I can handle this in my codebase in another way that doesn't require it to be in core. |
Instead of making the Worker class itself trigger the GC, I suggest implementing (in core) a middleware triggering it. Then, projects wanting to trigger the GC between each message can enable the middleware with 1 line in their config. |
Let's remove the call on 6.4/7.2 and improve on 7.3 thanks to #60018 |
@nicolas-grekas I will submit a PR to revert the change. |
…er each message is handled" (jwage) This PR was merged into the 6.4 branch. Discussion ---------- [Messenger] Revert " Add call to `gc_collect_cycles()` after each message is handled" This reverts commit b0df65a. Reverting changes introduced in #52253 because of the issue reported here #59788 Commits ------- fc9c551 Revert "[Messenger] Add call to `gc_collect_cycles()` after each message is handled"
Symfony version(s) affected
6.4.0 - 7.*
Description
Use gc_collect_cycles() after every message. Works exactly when connected symfony/messenger and symfony/redis-messenger
How to reproduce
Tested with
php 8.1.8 + symfony/messenger 6.4.* + (symfony/redis-messenger 6.3.* or 6.4.* )
php 8.4.3 + symfony/messenger 7.0.* + symfony/redis-messenger 7.0.*
You won't see the difference with one handler running. Therefore, I recommend running this all on an external environment in many instances. I have so many messages that I need to run 17 handlers at the same time.
For check that everything is fine on 6.3.* version:
Install symfony/messenger 6.3.* and symfony/redis-messenger 6.3.*
$this->messageBus->dispatch(new TestMessage());
And run bin/console messenger:consume test_message_worker (many instances)
Result CPU you can see on picture with mark P1
Deploy and run bin/console messenger:consume test_message_worker (many instances)
Result CPU you can see on picture with mark P2
6. Now upgrade packages symfony/messenger and symfony/redis-messenger to 6.4.0 (or 6.4.*). In fact, updating symfony/redis-messenger does not cause problems as long as the symfony/messenger package is <6.4.
And remove gc_collect_cycles() from our handler. We already have it in Worker class line 120.
Deploy and run bin/console messenger:consume test_message_worker (many instances)
Result CPU you can see on picture with mark P3
As you see P2 and P3 has same CPU results. And this result is higher than before on 6.3.*
Paragraph 5 were added to show what exactly gc_collect_cycles() affects performance
Possible Solution
Perhaps add a new option to the messenger:consume command to ignore this behavior?
Additional Context
No response
The text was updated successfully, but these errors were encountered: