Skip to content

Commit 5f8e39d

Browse files
ShardedDaemonSets: randomize starting worker index (#7857) (#7874)
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.
1 parent 1a5a82b commit 5f8e39d

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

src/contrib/cluster/Akka.Cluster.Sharding/ShardedDaemonProcess.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
using Akka.Annotations;
1313
using Akka.Event;
1414
using Akka.Routing;
15+
using Akka.Util;
1516
using Akka.Util.Internal;
1617

1718
namespace Akka.Cluster.Sharding
@@ -110,6 +111,9 @@ public DaemonMessageRouter(string[] entityIds, IActorRef shardingRef)
110111
if (_entityIds.Length == 0)
111112
throw new ArgumentException("At least one entityId must be provided", nameof(entityIds));
112113
_shardingRef = shardingRef;
114+
115+
// pick a random index to start with to avoid hot-spot formation
116+
_index = ThreadLocalRandom.Current.Next(_entityIds.Length);
113117
}
114118

115119
protected override void OnReceive(object message)

0 commit comments

Comments
 (0)