orleans icon indicating copy to clipboard operation
orleans copied to clipboard

[Question] Do streams or timers keep a grain alive?

Open zeinali0 opened this issue 2 years ago • 3 comments

As I know grain(s) have an idle timeout which mean runtime would deactivate them after idle activation. My question is Would streams or timers keep an grain active? Like a timer with shorter period than grain idle timeout

zeinali0 avatar Jan 14 '24 08:01 zeinali0

timer itself can't be used to postpone the deactivation of otherwise idle activations, but if you ping activation timer (delaydeactivation) from method called by the timer, than it could work.

both streams and reminders do restart deactivation timer. but both of them are persistent so even if your destination grain was not active, it would be activated to deliver stream message or reminder.

slawomirpiotrowski avatar Jan 14 '24 15:01 slawomirpiotrowski

Thanks. I think this information missed in docs, that what exactly keep a grain alive

And also, Is there anyway to prevent stream(s) restart deactivation timer? I have a case in which my GrainA get activate by user requests and Get latest state of GrainB and also subscribe to GrainB events to keep the state up to date but i don't want the stream keep GrainA alive I just want to it be alive as long as user requesting to it.

zeinali0 avatar Jan 28 '24 09:01 zeinali0

It's not missing, it's here: https://learn.microsoft.com/en-us/dotnet/orleans/host/configuration-guide/activation-garbage-collection#how-activation-gc-works

As far as I know there is no way to prevent streams from restarting deactivation timer, but you can work around that by using short liveness deactivation for the grain and adjusting it by a longer time in all the methods called by user.

I am using similar approach in my caching grains: short liveness time and adjusting it from code (calling delaydeactivation) by a longer timespan whenever receiveXXX methods are called by cache user. this way notifications about changes in data cached by the cache are not causing the caching grain to live longer.

slawomirpiotrowski avatar Jan 29 '24 13:01 slawomirpiotrowski

Thanks for contacting us. We believe that the question you've raised has been answered. If you still feel a need to continue the discussion, feel free to reopen the issue and add your comments.