Distributed collections in Orleans
I am exploring how to implement distributed collections for objects in Orleans. I imagine this functionality could be useful for a few scenarios, e.g.
- Scale existing systems with lots of code that cannot be completely reimplemented in grains.
- Hold and query large collections on the server side which reduces load on a client.
- Querying collections of grains, maybe in combination with index building [2].
So far I have identified the following main goals important for my Orleans-based project:
- Introduce some parallelism for list operations by using a large number of ContainerGrains hosting items.
- Exact storage location of items should not be dealt with by the user (not completely implemented).
- Allow efficient communication between objects hosted within a distributed collection (not implemented).
- Support LINQ-like queries on such a collection (way to go).
I implemented a prototype with some very limited functionality of distributed collections and would be happy to discuss its approaches [1].
I would like to hear what your requirements for a distributed collection are. Is it interesting to you to deal with not only collections of grains but collections of plain old objects as well? Do you care about consistency a lot?
Deprecated [1] https://github.com/bwanner/Orleans.Collections [2] Related issue: https://github.com/dotnet/orleans/issues/602
Update: See https://github.com/dotnet/orleans/issues/1412#issuecomment-193702118 for latest update on concept and implementation status.
Benjamin terrific! Would love to see it in action. When you feel comfortable you can make a PR here. Thanks
Related work Orleans.Consensus. Cross-referencing https://github.com/dotnet/orleans/issues/447 and https://github.com/dotnet/orleans/issues/446 for some ideas on silo locality (of these, don't pay attention to all that is written in #446 and the issue from which it stems from).
@bwanner , I think it is definitely an interesting idea. We generally like designs that built on top of Orleans (stack design). Our internal stream pub-sub is built this way, Orleans.Consensus, Orleans.Activities and more.
I would start with supporting some simple collections, like DistbutedDictionary, where you can lookup the key not by scanning all partitioning but by directly routing to the right one. The routing can be either done via static mapping (hash based or range based), or via intermediate routing grain. Same with List.
https://github.com/OrleansContrib would be a good place to host it initially. As others will start using it, you will get more concrete feedback and will be able to evolve the model.
I would say that the key thing is to have at least one concrete usage scenario, and build the system targeting at least one production usage (while of course still not losing the sight of generality).
Added a prototypical implementation of containers to OrleansContrib/Orleans.Containers.
Moved away from the collection term a bit and introduced the notion of containers:
A container serves as storage for an object and has the responsibility of executing functions on that object. If one adds an object to a container it becomes the object's owned and returns a ContainerHostedElement<T>. This reference can be used to access that object within the container.
This concept different to regular C# collections where collections are just storing a reference to an object and the object is located on the globally accessible heap. Also C# collections are supposed to implement IEnumerable which is not a concept necessarily aligned with Orleans principles.
The project is not documented well, but the examples should give a feeling for what it is trying to achieve. Feedback is highly appreciated :)
Have you considered the use of IAsyncEnumerable?
I'm new to Orleans and am trying to work out how to deal with collections of grains e.g. A UserGrain may contain many BlogPostGrain's and this requires filtering, sorting, paging, searching. What is the recommended approach?
Bump. Would be nice to see an example of recommended way to deal with collections.
I'm a bit late to the party here, but I too am curious to know what is the recommended way of dealing with collections (e.g. a collection of User Grains to populate a list/table in a UI, that can be filtered, paged and sorted)
I'd love to see some updates on this. For example, I'm curious to know what would be the best practice to handle a huge collection of items, where each one can eventually be used as the state for a grain. Think about a list of game servers. A grain could be used to act as proxy between the client and the underlying items and provide some paging/querying functionality. The client can then pull a "page", perhaps pick one of the servers and act on it. What would be the preferred approach? I can think of two options:
- use a separate repository class injected into the ArchiveGrain.
- have the ArchiveGrain return pages of ItemGrain directly