-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Automatic passivation for sharding #3718
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
settings, | ||
_extractEntityId, | ||
_extractShard, | ||
new LeastShardAllocationStrategy(10, 3), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ClusterSharding.DefaultShardAllocationStrategy()
seems to be accessible from here in the JVM (see #L69)
@@ -617,14 +624,28 @@ internal static class Shards | |||
} | |||
} | |||
|
|||
public static void PassivateCompleted<TShard>(this TShard shard, Shard.EntityStopped evt) where TShard: IShard | |||
private static void PassivateIdleEntities<TShard>(this TShard shard) where TShard : IShard |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My first implementation was easier to the eye and more in line with the JVM, but probably less performant:
var deadline = DateTime.Now.Ticks - shard.Settings.PassivateIdleEntityAfter.Ticks;
var refsToPassivate = shard.LastMessageTimestamp.Where(s => s.Value < deadline).Select(s => shard.RefById[s.Key]).ToArray();
if (refsToPassivate.Any())
{
shard.Log.Debug($"Passivating [{refsToPassivate.Length}] idle entities");
refsToPassivate.ForEach(entity => Passivate(shard, entity, shard.HandOffStopMessage));
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
08fe424
to
cdc4110
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In principle, it's good to go - nice that you've optimized this LINQ part to something that actually has sense in .NET :)
@@ -617,14 +624,28 @@ internal static class Shards | |||
} | |||
} | |||
|
|||
public static void PassivateCompleted<TShard>(this TShard shard, Shard.EntityStopped evt) where TShard: IShard | |||
private static void PassivateIdleEntities<TShard>(this TShard shard) where TShard : IShard |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
@@ -660,26 +681,61 @@ internal static class Shards | |||
} | |||
else | |||
{ | |||
if (shard.MessageBuffers.TryGetValue(id, out var buffer)) | |||
// TODO |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TODO what?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nada. Missed this one before pushing...
cdc4110
to
fd03bd7
Compare
LGTM |
Port #25765