Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Long polling + graceful shutdown #8893

gschuager started this conversation in General
Mar 4, 2024 · 1 comments · 2 replies
Discussion options

Hi, I am implementing something like this https://outcompute.com/2019/05/26/latency-adaptive-real-time-with-reactive-caching-on-microsoft-orleans/ based on the samples from 3.x branch.

Is there any way to receive a notification in a grain that the silo is requested to be shut down? I would like to use this to cancel the long-poll async waiting task as soon as possible in order to let the grain be deactivated and the silo shut down quickly.

I understand that OnDeactivateAsync won't get called until pending requests are completed (I tested this and it makes sense) and in this case I have the long-poll one preventing that.

You must be logged in to vote

Replies: 1 comment · 2 replies

Comment options

Hi, post author here.

We can receive such notifications from the ApplicationStopping token of the IHostApplicationLifetime service we can request from DI. This token will be raised upon a graceful shutdown request from the host itself and can be used to swiftly cancel any long-running work in the app. It's not an orleans specific feature.

To protect any task with this, we can write await myTask.WaitAsync(_lifetime.ApplicationStopping).
In hindsight I should have added that to the samples as lack thereof can cause a grain to delay graceful deactivation.

That is quite the old post by the way. I suggest reading about support for IAsyncEnumerable<T> in Orleans v7+ here #8416
This performs long-polling behind the scenes but is far more comfortable to use and can be adapted in various ways.

I have a couple of examples here including usage as an async queue, broadcast or rewindable stream.

The original pattern is still more powerful yet it's now overkill for most use cases.

You must be logged in to vote
2 replies
@gschuager
Comment options

Great! many thanks! will look into those topics

@gschuager
Comment options

I've been doing some experiments with IAsyncEnumerable and it seems to be a good fit to stream data from one grain to another, but as far as I can tell, I am missing the back-pressure handling part.

The context is that I eventually need to deliver state updates to a web application. I plan to use Signalr, and I see that it supports streaming via IAsyncEnumerable, but the sever would be pushing updates at its own peace instead of the client requesting them when it is ready to handle them.

Is there any way around this without using client initiated polling?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.