dotnet / orleans

Cloud Native application framework for .NET
https://docs.microsoft.com/dotnet/orleans
MIT License
10.08k stars 2.03k forks source link

SiloRoleBasedPlacementAttribute usage example #8573

Open flaik-wayne opened 1 year ago

flaik-wayne commented 1 year ago

Hi, I would like to upgrade orleans to latest. But we are making use of ExcludedGrainTypes in order to run a database access grain on silo zero only (it's a long story, don't ask).

I have done a lot of searching regarding SiloRoleBasedPlacementAttribute, and I can see the tests, but I am unclear about how to actually use it. One would presume that certain silos would need to be assigned a Role in order to participate in this.

I have a suspicion that eg. the grain identity "testhost" (see https://github.com/dotnet/orleans/blob/075df202679e8e620f698cede7e97c52ec639b20/test/DefaultCluster.Tests/SiloRoleBasedPlacementDirectorTests.cs#L37) is actually the hostname of the silo which should host the grain?

If so, does that mean that SiloRoleBasedPlacement works something like a stateless worker, or is it stateful but only one grain of that type is allowed per silo?

A bit confused, would really appreciate any pointers. Thanks :)

AzharB178 commented 6 months ago

Have you managed to figure out how the Silo role is assigned? I'm aiming to use role-placed placement but my grains are not stateless and I need multiple per silo

flaik-wayne commented 6 months ago

No, I never did. I suspect it either has to do with the host name, or it is otherwise intimately tied to the silo membership table. I spent a while trying to figure it out from the source but never really could understand what was going on.

I got the impression that it was only useful for placing one grain per silo, but of course I don’t know for sure as I didn’t work it out. The orleans unit/integration tests implied this to me as I believe the grain id must be equal to the destination silo id (whether that is the host name of the silo or something else, like I said, I don’t know).

My workaround was to create separate builds of my application, and only include the implementation of certain grains in certain builds (and thus on certain silos). Then the normal placement strategy is forced to place the grains on silos which have an implementation for that grain.

Look up the docs for orleans heterogeneous silos. https://learn.microsoft.com/en-us/dotnet/orleans/host/heterogeneous-silos