Repository navigation
Closed
Labels
Needs: attention 👋Needs: designIssues that need designNeeds: documentationarea-streamingCategory for Orleans streaming issuesenhancement
Milestone
Description
@gabikliot Confirmed in Gitter that currently it is not supported for StatelessWorker grains to subscribe to streams, but support for this scenario is desirable. Let's use this issue as a vehicle to flesh out more details and improve documentation. I'll add some tasks, feel free to propose better ones and I'll refine the list.
To paraphrase that of written earlier
So today we don't support StatelessWorker subscribing to a stream. It won't work. We should probably add an explicit throw in the code now. It has to do with our internal implementation. However, in general, we do need to support this scenario. Our first priority scenario was a large number of small streams, and the processing of them is basically sharded among large number or regular (statefull) grains. The goal is statefull processing. That's what we focused until now and that's what works now. The scenario you described with StatelessWorker will be more suitable for a small number (or even one) large stream and the goal would be stateless processing (for example, a stream of all msgs for all my events, just decode/decipher them and maybe forward for further statefull processing). So for now, just priority wise, we don't support stateless processing with StatelessWorker, but we should (and hopefully will in the future). Feel free to open an issue on GH for that. Maybe someone will take a lead and help implementing this. We can provide help with where the gaps are w.r.t. the current implementation.
- Gather relevant places of code to touch and perhaps some design rationale.
- Maybe documentation can be updated to give some details on how the stateless grains are addressed by the core – not excluding other details that come into mind. This might help those who would like to go into greater detail of the inner workings.
- Add initial test as OK this won't currently work and reverse it later. Should help "dabblers".
- Add a note documentation this scenario is not currently supported.
Reacted by Peter Herbel, Norman Harebottle III, Tequila Sunset, Nikita B., dzmitry-lahoda, Catalin Bocirnea, szingg, Wojtek Turowicz, Jonas Frost, Corstian Boerman and 2 more
Metadata
Metadata
Assignees
Labels
Needs: attention 👋Needs: designIssues that need designNeeds: documentationarea-streamingCategory for Orleans streaming issuesenhancement
Activity
gabikliot commentedon May 20, 2015
Added documentation here: http://dotnet.github.io/orleans/Orleans-Streams/Streams-Programming-APIs
Stateless Automatically Scaled-Out Processing.
rore commentedon May 25, 2015
+1 for this addition.
There's another use case for StatelessWorker subscription which I think can be very basic (I know we need it across the board) - for multiple readers / single writer pattern.
This is a common pattern when you have a resource that has high read access. You want the updates to go to a single statefull grain, but to scale reads you want those to be done via StatelessWorkers (that also function as a local-silo cache).
These readers needs to subscribe to revoke events from the writer. Doing that via observers is a problem (since you need to persist them etc.).
Orleans streams seems to be a perfect match for this. If only you could use them with StatelessWorkers...
gabikliot commentedon May 26, 2015
@rore, I think in your case you can't really use
StatelessWorkers. If I understand your case correctly, you need to reliably send "invalidate" command to all read replicas and make sure they all got it. You cannot do it withStatelessWorkers(unrelated to whether this is done with streams or direct grain messaging).StatelessWorkersare not addressable individually, and you can't know how much of them are. So you cannot address them all. You could maybe send a huge number of calls and "hope" at least one lands on each, but this is very fragile and even that won't guarantee you anything.I see 2 ways to solve your general problem, both don't involve
StatelessWorkers:Do it the way you are doing now, with a single write grain and a pool of read grains and managed the pool explicitly, via ids. Like you decide on 10 ids for 10 grains for that pool. No need for them to register anywhere, just use known ids 1...10. The readers just picks a random id out of the pol. The write will send invalidate to all of them. To get dynamic scaling, you basically rely on Orleans for short deactivation. Configure the readers to have a short 1 min deactivation, and write have a longer deactivation. So in the high read rate case all 10 grains will be in memory. But in the low period they will quickly be deactivated.
In general, in your case, since you are managing consistency of your data yourself, with explicit invalidate command, this whole problem is relatively easy.
We are looking internally on some kind of similar single write multiple reader case. The difference from your case is that we want to manage the consistency automatically, not based on application telling us when to invalidate. This is still in quite an early stage.
CCing: @nehmebilal, @remusrg.
rore commentedon May 26, 2015
Thanks @gabikliot . Two questions:
About your suggestion - part of the idea of using StatelessWorkers is that they are local on each silo, thus providing a local cache. Can this be done they way you suggest it? Can these grains be with local placement even if they are not StatelessWorkers?
Also, if the writer always sends the invalidation message to all reader grains, it means all 10 grains will be activated on an invalidation even if only one of them is actually alive. That introduces an overhead for invalidations.
About streaming - wouldn't allowing StatelessActors to subscribe be the solution to the problem of broadcasting messages to StatelessActors? (This is a problem that goes beyond this specific use case). That is - if StatelessActors could subscribe, I would be able to have an "invalidation" pub-sub stream that will be used to broadcast the invalidation to all subscribed StatelessWorkers. If that's not the case, what am I missing?
gabikliot commentedon May 26, 2015
Lets talk about
StatelessWorkershere and open a separate issue about replication. It is a big enough issue to deserve its own thread. OK? So please go ahead and open a new issue on replication with your case described and potential solutions.Back to
StatelessWorkers. What you are suggesting does make sense , but for a different abstraction.StatelessWorkers- the whole point is: you don't care which one, you don't send them commands to control their state, since they are Stateless.W.r.t. stream processing, I think
StatelessWorkerscan be used for scaling out stateless processing: http://dotnet.github.io/orleans/Orleans-Streams/Streams-Programming-APIs -> Stateless Automatically Scaled-Out ProcessingBut it is not even clear to me how
StatelessWorkerswill subscribe to a steam - each activation needs to subscribe, or one activation on behalf of all activations, or maybeStatelessWorkerswith stream can only be used with Implicit Stream Subscriptions. I don't know yet.But being able to send a broadcast msgs to all seems like introduces explicit management of them, which is against the nature of
Stateless.There is a different question about whether Orleans should provide an abstraction of a group of actors, how this abstraction is provided, ...lots of questions. But
StatelessWorkersis not that abstraction.rore commentedon May 26, 2015
I see your point, but if that's the case then I feel there's a fundamental building block that is missing.
What we usually need are Workers, the part of the "Stateless" we kind of ignore. The common need is to have grains of a certain type that are created locally, automatically and scaled when needed (we don't want to manage them explicitly, e.g. by known IDs).
These grains are not persistent, but they can potentially hold a local non-persistent state (which is some kind of data that you might need and don't want to bring on every call).
As for subscribing, I was thinking something like this - each StatelessWorker will subscribe on activation and will unsubscribe on deactivation. That way stream messages will only go to the existing activations and will not activate any StatelessWorker that was deactivated.
Why does that break the abstraction of the StatelessWorker? I don't see how it introduces explicit management.
veikkoeeva commentedon May 26, 2015
@rore I rephrase otherwise to check I understood correctly: You have a
MasterCachethat is an origin, a source of events to some well known stream. Let's say it's a cache stream with Id0. Then you would like to instantiate local, per-silo caches,PerSiloCachegrains, that have the exact same content as the master cache grain.To query these per-silo caches grain you call them with a well-known ID, say 0 (
PerSiloCacheFactory.GetGrain(0)). UponOnActivateAsyncthisPerSiloCacheretrieves data fromMasterCacheand subscribes to the aforementioned well known cache stream with stream ID0. UponDeactivateAsyncyou would unsubscribe from the well known cache stream.This way
MasterCachecould feed changes toPerSiloCachegrains and you wouldn't need to explicitly manage the caching and/or guess how many you would need.rore commentedon May 26, 2015
@veikkoeeva yes, exactly, and PerSiloCache are StatelessWorkers so they are scaled when needed.
veikkoeeva commentedon May 26, 2015
@rore I think this could work. There's another pattern that could also work, though not as scalable: Have a
Bootstrapperand instantiate there a[PreferLocalPlacement]grain with some well known ID, say, something derived from the silo ID. For this plan to work, there's a little snag, it's not exposed in Bootstrapper publicly at the moment (though it is known at the time). Though to get it, you could have a stateless grain, query the silo ID from there and use that then to instantiate the locally placed grain. Code organization-wise this is almost the same as the plan with stateless worker and if someone doesn't find holes in this, eventually streams would be supported in the stateless grains and you don't need that maximum scalability right now, refactoring later would be easy.As a side note, maybe it is OK to add
[Reentrant]too.gabikliot commentedon May 26, 2015
Guys, lets not combine 2 unrelated threads please, OK? Just makes later following and reasoning so hard.
This thread is about
StatelessWorkersusing streams.A different issue is replication and local placement optimization. Or like @rore wrote: "I see your point, but if that's the case then I feel there's a fundamental building block that is missing."
gabikliot commentedon May 26, 2015
@rore, about
StatelessWorkerabstraction with streams. First, lets assume we are talking about Explicit subscription, and not Implicit.So first the GRAIN has to subscribe, at least once. Otherwise, no activation of that grain will receive any stream event. So you send a control msg to this aStatelessWorkera grain, it subscribes once. Now you keep sending it stream events, more activations are created, they subscribe (but only their activation), then unsubscribe inside deactivate async. But the one global per grain subscription stays? How you unsubscribe from that?
This mixes 2 abstractions. I don't see how this can work.
I am really open to suggestion. I would love to make it work. I just don't currently see how.
Alternatively, we can say that
StatelessWorkercan only have implicit subscription. No need to subscribe a grain ever. In this case indeed the subscribe inside activation will be for this activation only. This can work I think.rore commentedon May 26, 2015
I don't see a problem with having a limitation that you can only use an implicit subscription.
I would be happy to understand, though, in what way is the implicit subscription different from explicit so that you don't have the same problem with the subscribing grain identity.
gabikliot commentedon May 26, 2015
With implicit subscription the grain is already subscribed, statically. You still need to call
SubscribeAsyncfromOnActivateAsync, but this is only attach theIAsyncObserver, not to do any actual grain subscription. In the future, when we add support for a grain code to directly implementIAsyncObserver, there will not be a need in this "attach theIAsyncObserver" call. So implicitly subscribed grain will just get the events, just like regular grain calls, without any calls toSubscribeAsync.For explicit subscription you do need to subscribe the grain.
Take a look here: http://dotnet.github.io/orleans/Orleans-Streams/Streams-Programming-APIs "Explicit and Implicit Subscriptions"
58 remaining items