From 81488036219cf0f5c21e5cc09c2ae76c265107b9 Mon Sep 17 00:00:00 2001 From: Aaron Stannard Date: Fri, 3 Oct 2025 17:46:04 -0500 Subject: [PATCH] `ShardedDaemonSets`: randomize starting worker index (#7857) avoids hot-spots by making sure that not all `DaemonMessageRouter`s start routing messages to the same first entity at the start of the list. --- .../cluster/Akka.Cluster.Sharding/ShardedDaemonProcess.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/contrib/cluster/Akka.Cluster.Sharding/ShardedDaemonProcess.cs b/src/contrib/cluster/Akka.Cluster.Sharding/ShardedDaemonProcess.cs index 9d8b3230d31..9b3ca930a0b 100644 --- a/src/contrib/cluster/Akka.Cluster.Sharding/ShardedDaemonProcess.cs +++ b/src/contrib/cluster/Akka.Cluster.Sharding/ShardedDaemonProcess.cs @@ -12,6 +12,7 @@ using Akka.Annotations; using Akka.Event; using Akka.Routing; +using Akka.Util; using Akka.Util.Internal; namespace Akka.Cluster.Sharding @@ -110,6 +111,9 @@ public DaemonMessageRouter(string[] entityIds, IActorRef shardingRef) if (_entityIds.Length == 0) throw new ArgumentException("At least one entityId must be provided", nameof(entityIds)); _shardingRef = shardingRef; + + // pick a random index to start with to avoid hot-spot formation + _index = ThreadLocalRandom.Current.Next(_entityIds.Length); } protected override void OnReceive(object message)