Skip to content

Commit a80ddd7

Browse files
Port scala akka PR #26816 to Akka.NET (#4511)
* Port scala akka PR #26816 to Akka.NET * Remove SynchronizationContext usage * Use internal dispatcher in other part of Akka.NET, update documentation * Port internal blocking dispatcher and default internal dispatcher for Akka.Stream * Add circular dispatcher alias reference checking, unroll recursion * Make ClusterSingletonManager and Proxy to use internal dispatchers * Update API approver list * Remove SynchronizationContext * Clean up Pigeon.conf config file Co-authored-by: Aaron Stannard <[email protected]>
1 parent 8b1d54b commit a80ddd7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+578
-115
lines changed

docs/articles/actors/dispatchers.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ system.ActorOf(Props.Create<MyActor>().WithDispatcher("my-dispatcher"), "my-acto
7070
Some dispatcher configurations are available out-of-the-box for convenience. You can use them during actor deployment, [as described above](#configuring-dispatchers).
7171

7272
* **default-dispatcher** - A configuration that uses the [ThreadPoolDispatcher](#threadpooldispatcher). As the name says, this is the default dispatcher configuration used by the global dispatcher, and you don't need to define anything during deployment to use it.
73+
* **internal-dispatcher** - To protect the internal Actors that is spawned by the various Akka modules, a separate internal dispatcher is used by default.
7374
* **task-dispatcher** - A configuration that uses the [TaskDispatcher](#taskdispatcher).
7475
* **default-fork-join-dispatcher** - A configuration that uses the [ForkJoinDispatcher](#forkjoindispatcher).
7576
* **synchronized-dispatcher** - A configuration that uses the [SynchronizedDispatcher](#synchronizeddispatcher).
@@ -174,3 +175,10 @@ The following configuration keys are available for any dispatcher configuration:
174175

175176
> [!NOTE]
176177
> The throughput-deadline-time is used as a *best effort*, not as a *hard limit*. This means that if a message takes more time than the deadline allows, Akka.NET won't interrupt the process. Instead it will wait for it to finish before giving turn to the next actor.
178+
179+
## Dispatcher aliases
180+
181+
When a dispatcher is looked up, and the given setting contains a string rather than a dispatcher config block,
182+
the lookup will treat it as an alias, and follow that string to an alternate location for a dispatcher config.
183+
If the dispatcher config is referenced both through an alias and through the absolute path only one dispatcher will
184+
be used and shared among the two ids.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ public ClusterSharding(ExtendedActorSystem system)
262262
{
263263
var guardianName = system.Settings.Config.GetString("akka.cluster.sharding.guardian-name");
264264
var dispatcher = system.Settings.Config.GetString("akka.cluster.sharding.use-dispatcher");
265-
if (string.IsNullOrEmpty(dispatcher)) dispatcher = Dispatchers.DefaultDispatcherId;
265+
if (string.IsNullOrEmpty(dispatcher)) dispatcher = Dispatchers.InternalDispatcherId;
266266
return system.SystemActorOf(Props.Create(() => new ClusterShardingGuardian()).WithDispatcher(dispatcher), guardianName);
267267
});
268268
}

src/contrib/cluster/Akka.Cluster.Sharding/reference.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ akka.cluster.sharding {
137137
coordinator-singleton = "akka.cluster.singleton"
138138

139139
# The id of the dispatcher to use for ClusterSharding actors.
140-
# If not specified default dispatcher is used.
140+
# If not specified, the internal dispatcher is used.
141141
# If specified you need to define the settings of the actual dispatcher.
142142
# This dispatcher for the entity actors is defined by the user provided
143143
# Props, i.e. this dispatcher is not used for the entity actors.

src/contrib/cluster/Akka.Cluster.Tools/Client/ClusterClientReceptionist.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ private IActorRef CreateReceptionist()
133133
{
134134
var name = _config.GetString("name");
135135
var dispatcher = _config.GetString("use-dispatcher", null);
136-
if (string.IsNullOrEmpty(dispatcher)) dispatcher = Dispatchers.DefaultDispatcherId;
136+
if (string.IsNullOrEmpty(dispatcher)) dispatcher = Dispatchers.InternalDispatcherId;
137137

138138
// important to use var mediator here to activate it outside of ClusterReceptionist constructor
139139
var mediator = PubSubMediator;

src/contrib/cluster/Akka.Cluster.Tools/Client/reference.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ akka.cluster.client.receptionist {
2424
response-tunnel-receive-timeout = 30s
2525

2626
# The id of the dispatcher to use for ClusterReceptionist actors.
27-
# If not specified default dispatcher is used.
27+
# If not specified, the internal dispatcher is used.
2828
# If specified you need to define the settings of the actual dispatcher.
2929
use-dispatcher = ""
3030

src/contrib/cluster/Akka.Cluster.Tools/PublishSubscribe/DistributedPubSub.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ private IActorRef CreateMediator()
102102
var name = _system.Settings.Config.GetString("akka.cluster.pub-sub.name");
103103
var dispatcher = _system.Settings.Config.GetString("akka.cluster.pub-sub.use-dispatcher", null);
104104
if (string.IsNullOrEmpty(dispatcher))
105-
dispatcher = Dispatchers.DefaultDispatcherId;
105+
dispatcher = Dispatchers.InternalDispatcherId;
106106

107107
return _system.SystemActorOf(
108108
Props.Create(() => new DistributedPubSubMediator(_settings))

src/contrib/cluster/Akka.Cluster.Tools/PublishSubscribe/reference.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ akka.cluster.pub-sub {
3030
max-delta-elements = 3000
3131

3232
# The id of the dispatcher to use for DistributedPubSubMediator actors.
33-
# If not specified default dispatcher is used.
33+
# If not specified, the internal dispatcher is used.
3434
# If specified you need to define the settings of the actual dispatcher.
3535
use-dispatcher = ""
3636

src/contrib/cluster/Akka.Cluster.Tools/Singleton/ClusterSingletonManager.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
using Akka.Actor;
1515
using Akka.Configuration;
1616
using Akka.Coordination;
17+
using Akka.Dispatch;
1718
using Akka.Event;
1819
using Akka.Pattern;
1920
using Akka.Remote;
@@ -604,7 +605,9 @@ public static Props Props(Props singletonProps, ClusterSingletonManagerSettings
604605
/// <returns>TBD</returns>
605606
public static Props Props(Props singletonProps, object terminationMessage, ClusterSingletonManagerSettings settings)
606607
{
607-
return Actor.Props.Create(() => new ClusterSingletonManager(singletonProps, terminationMessage, settings)).WithDeploy(Deploy.Local);
608+
return Actor.Props.Create(() => new ClusterSingletonManager(singletonProps, terminationMessage, settings))
609+
.WithDispatcher(Dispatchers.InternalDispatcherId)
610+
.WithDeploy(Deploy.Local);
608611
}
609612

610613
private readonly Props _singletonProps;

src/contrib/cluster/Akka.Cluster.Tools/Singleton/ClusterSingletonProxy.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
using System.Linq;
1212
using Akka.Actor;
1313
using Akka.Configuration;
14+
using Akka.Dispatch;
1415
using Akka.Event;
1516

1617
namespace Akka.Cluster.Tools.Singleton
@@ -70,7 +71,9 @@ public static Config DefaultConfig()
7071
/// <returns>TBD</returns>
7172
public static Props Props(string singletonManagerPath, ClusterSingletonProxySettings settings)
7273
{
73-
return Actor.Props.Create(() => new ClusterSingletonProxy(singletonManagerPath, settings)).WithDeploy(Deploy.Local);
74+
return Actor.Props.Create(() => new ClusterSingletonProxy(singletonManagerPath, settings))
75+
.WithDispatcher(Dispatchers.InternalDispatcherId)
76+
.WithDeploy(Deploy.Local);
7477
}
7578

7679
private readonly ClusterSingletonProxySettings _settings;

src/contrib/cluster/Akka.DistributedData/ReplicatorSettings.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public static ReplicatorSettings Create(Config config)
4343
throw ConfigurationException.NullOrEmptyConfig<ReplicatorSettings>();
4444

4545
var dispatcher = config.GetString("use-dispatcher", null);
46-
if (string.IsNullOrEmpty(dispatcher)) dispatcher = Dispatchers.DefaultDispatcherId;
46+
if (string.IsNullOrEmpty(dispatcher)) dispatcher = Dispatchers.InternalDispatcherId;
4747

4848
var durableConfig = config.GetConfig("durable");
4949
var durableKeys = durableConfig.GetStringList("keys");
@@ -63,7 +63,7 @@ public static ReplicatorSettings Create(Config config)
6363
{
6464
throw new ArgumentException($"`akka.cluster.distributed-data.durable.store-actor-class` is set to an invalid class {durableStoreType}.");
6565
}
66-
durableStoreProps = Props.Create(durableStoreType, durableConfig).WithDispatcher(durableConfig.GetString("use-dispatcher"));
66+
durableStoreProps = Props.Create(durableStoreType, durableConfig).WithDispatcher(dispatcher);
6767
}
6868

6969
// TODO: This constructor call fails when these fields are not populated inside the Config object:
@@ -212,7 +212,7 @@ private ReplicatorSettings Copy(string role = null,
212212
public ReplicatorSettings WithGossipInterval(TimeSpan gossipInterval) => Copy(gossipInterval: gossipInterval);
213213
public ReplicatorSettings WithNotifySubscribersInterval(TimeSpan notifySubscribersInterval) => Copy(notifySubscribersInterval: notifySubscribersInterval);
214214
public ReplicatorSettings WithMaxDeltaElements(int maxDeltaElements) => Copy(maxDeltaElements: maxDeltaElements);
215-
public ReplicatorSettings WithDispatcher(string dispatcher) => Copy(dispatcher: string.IsNullOrEmpty(dispatcher) ? Dispatchers.DefaultDispatcherId : dispatcher);
215+
public ReplicatorSettings WithDispatcher(string dispatcher) => Copy(dispatcher: string.IsNullOrEmpty(dispatcher) ? Dispatchers.InternalDispatcherId : dispatcher);
216216
public ReplicatorSettings WithPruning(TimeSpan pruningInterval, TimeSpan maxPruningDissemination) =>
217217
Copy(pruningInterval: pruningInterval, maxPruningDissemination: maxPruningDissemination);
218218
public ReplicatorSettings WithDurableKeys(IImmutableSet<string> durableKeys) => Copy(durableKeys: durableKeys);

0 commit comments

Comments
 (0)