Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[RFC][Mesenger] Add support for reseting container services between 2 messages #43001

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

Closed
ovrflo opened this issue Sep 13, 2021 · 2 comments · Fixed by #43003
Closed

[RFC][Mesenger] Add support for reseting container services between 2 messages #43001

ovrflo opened this issue Sep 13, 2021 · 2 comments · Fixed by #43003
Labels
RFC RFC = Request For Comments (proposals about features that you want to be discussed)

Comments

@ovrflo
Copy link
Contributor

ovrflo commented Sep 13, 2021

Hello,

Sorry for being a bit late to this party. I just saw that #41163 got merged into 5.4 and I think it needs a bit more polish. The main issue I found with it is that IMHO it's way too agressive. If reset_on_message is enabled on a transport, the services in ServicesResetter (which are quite a few) will get reset

while (true) {
  // worker tick
  foreach (transport) {
    if (message) {
      reset (success/failed)
      reset again (worker running) <-- actually, this would throw
    }
  }
  if (idle) {
    reset again
  }
  usleep

Isn't this too aggresive? While resetting after each message (success/failure) makes some sense (though there's an argument to be made for a userland implementation), resetting multiple times per worker tick can't be all right. It also reset on each tick if idle. Depending on the configuration, it can happen multiple times per second.

ServicesResetter was meant for resetting state on request boundaries. It was never meant to hide memory leaks. Sure, it does help cover the memory leaks, but covering them is not a viable long term solution.

The original PR pointed out at least 2 legitimate issues: The FingersCrossedHandler keeps on flushing logs after a single error and the Profiler infrastructure is leaking memory. While the monolog issue should be fixed, I don't find the Profiler argument convincing. I do believe the profiler should not leak memory, but I think the Profiler should do its own housekeeping in a messenger context.

Another issue with the current implementation is the fact the it subscribes to WorkerRunningEvent and then it calls getReceiverName() on it. WorkerRunningEvent::getReceiverName() does not exist. That's because WorkerRunningEvent doesn't extend AbstractWorkerMessageEvent (which ResetServicesListener::resetServices() expects).

Last but not least, there's the semantic issue -- right now, the configuration reset_on_message is misleading.

Some ideas that would improve the situation would be:

  • reset the services only on message handled (success or failed)
  • maybe even reset on idle, but do it a lot less often (and toggleable separately, or at least make it clear to the developer that reset_on_message_also_resets_on_idle)
  • just like there is cache.app and a cache.system, maybe the ServicesResetter should have separate service groups for app and system. The framework would do its own housekeeping, while userland that has no other choice would tag their services to get reset as well as part of the app group)
  • I know it's a long shot, but if we extended the profiler to work for CLI usecases (like messenger), it would give us a chance to mitigate some of the leaks. The profiler would collect() the data and the Collectors (like TraceableEventDispatcher) would have their buffers cleared.

So... what do you guys think?
/cc @lyrixx (please forgive me 😁 )

@carsonbot carsonbot added the RFC RFC = Request For Comments (proposals about features that you want to be discussed) label Sep 13, 2021
@lyrixx
Copy link
Member

lyrixx commented Sep 13, 2021

Hello, Thanks for taking time to review the PR.

reset the services only on message handled (success or failed)

As you can see, the subscription on WorkerRunningEvent was added very late to the PR.
I think you are right, so I'll open a new PR to remove it 👍🏼

maybe even reset on idle, but do it a lot less often (and toggleable separately, or at least make it clear to the developer that reset_on_message_also_resets_on_idle)

I'm not sure it's really needed. Actually I don't have issues when the controller is idle. So let's drop this feature completely
(This option should not hide leak in the first place, I agree with you)

just like there is cache.app and a cache.system, maybe the ServicesResetter should have separate service groups for app and system. The framework would do its own housekeeping, while userland that has no other choice would tag their services to get reset as well as part of the app group)

That's another topic. If you think it could be really useful, please open a new RFC (in the DIC / Kernel section)

@ovrflo
Copy link
Contributor Author

ovrflo commented Sep 13, 2021

Thank you so much for your prompt response!

Indeed, I saw the Idle listener was added late in the PR and I agree it's not needed. It's only "needed" because of the Profiler infrastructure leaking constantly in CLI.

Removing the idle listener fixes the core issues with this uhm... issue :)

The other points are maybe appropriate for future RFCs, as you pointed out :)

Nonetheless, if you deem it appropriate, I would welcome keeping this issue open a little while longer for some more thoughts on the ideas. If not, let me know so I start drafting them 👍

@fabpot fabpot closed this as completed in 9d12f14 Sep 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
RFC RFC = Request For Comments (proposals about features that you want to be discussed)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants