Commit 8720b78
committed
minor symfony#52253 [Messenger] Add call to
This PR was squashed before being merged into the 6.4 branch.
Discussion
----------
[Messenger] Add call to `gc_collect_cycles()` after each message is handled
| Q | A
| ------------- | ---
| Branch? | 6.4
| Bug fix? | no
| New feature? | no
| Deprecations? | no
| License | MIT
I have been working on improving memory usage in my messenger worker queues and I had been chasing what I thought was a memory leak, but I haven't been able to find it. In my troubleshooting, I pushed a change to production which simply logs the result of `gc_status()` after each message is handled, and I noticed that it was taking a very long time for the automatic garbage collection to run. Additionally, each time it would finally run, the PHP algorithm internally would extend the threshold, making it take even longer to run the next time. So the number of objects in memory waiting to be collected would keep growing and the memory per process would grow. In my application, it is important for the memory for each worker process to stay relatively flat so that I can know how many worker processes I can fit on each worker server.
I added a call to `gc_collect_cycles()` in my application after each message is handled, and it seems to have improved things for me. I suppose it is still possible I have a memory leak, but I haven't been able to find it.
Here is a screenshot of memory usage from one of my worker servers after I deployed that change.

In my application, it takes < 1ms to call `gc_collect_cycles()` after each message is handled and that is satisfactory for me in order to keep memory usage lower.
If this is accepted, should we make it optionally enabled?
Commits
-------
b0df65a [Messenger] Add call to `gc_collect_cycles()` after each message is handledgc_collect_cycles() after each message is handled (jwage)File tree
2 files changed
+21
-0
lines changed- src/Symfony/Component/Messenger
- Tests
2 files changed
+21
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
578 | 578 | | |
579 | 579 | | |
580 | 580 | | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
581 | 600 | | |
582 | 601 | | |
583 | 602 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
118 | 118 | | |
119 | 119 | | |
120 | 120 | | |
| 121 | + | |
| 122 | + | |
121 | 123 | | |
122 | 124 | | |
123 | 125 | | |
| |||
0 commit comments