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);

src/contrib/cluster/Akka.DistributedData/reference.conf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ akka.cluster.distributed-data {
2626
# the replicas. Next chunk will be transferred in next round of gossip.
2727
max-delta-elements = 1000
2828

29-
# The id of the dispatcher to use for Replicator actors. If not specified
30-
# default dispatcher is used.
29+
# The id of the dispatcher to use for Replicator actors.
30+
# If not specified, the internal dispatcher is used.
3131
# If specified you need to define the settings of the actual dispatcher.
3232
use-dispatcher = ""
3333

src/core/Akka.API.Tests/CoreAPISpec.ApproveCore.approved.txt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
[assembly: System.Runtime.CompilerServices.InternalsVisibleToAttribute("Akka.Benchmarks")]
22
[assembly: System.Runtime.CompilerServices.InternalsVisibleToAttribute("Akka.Cluster")]
3+
[assembly: System.Runtime.CompilerServices.InternalsVisibleToAttribute("Akka.Cluster.Sharding")]
34
[assembly: System.Runtime.CompilerServices.InternalsVisibleToAttribute("Akka.Cluster.TestKit")]
45
[assembly: System.Runtime.CompilerServices.InternalsVisibleToAttribute("Akka.Cluster.Tests")]
56
[assembly: System.Runtime.CompilerServices.InternalsVisibleToAttribute("Akka.Cluster.Tests.MultiNode")]
@@ -1841,12 +1842,13 @@ namespace Akka.Actor.Internal
18411842
public class ActorSystemImpl : Akka.Actor.ExtendedActorSystem
18421843
{
18431844
public ActorSystemImpl(string name) { }
1844-
public ActorSystemImpl(string name, Akka.Configuration.Config config, Akka.Actor.Setup.ActorSystemSetup setup) { }
1845+
public ActorSystemImpl(string name, Akka.Configuration.Config config, Akka.Actor.Setup.ActorSystemSetup setup, System.Nullable<Akka.Util.Option<Akka.Actor.Props>> guardianProps = null) { }
18451846
public override Akka.Actor.ActorProducerPipelineResolver ActorPipelineResolver { get; }
18461847
public override Akka.Actor.IActorRef DeadLetters { get; }
18471848
public override Akka.Dispatch.Dispatchers Dispatchers { get; }
18481849
public override Akka.Event.EventStream EventStream { get; }
18491850
public override Akka.Actor.IInternalActorRef Guardian { get; }
1851+
public Akka.Util.Option<Akka.Actor.Props> GuardianProps { get; }
18501852
public override Akka.Event.ILoggingAdapter Log { get; }
18511853
public override Akka.Actor.IInternalActorRef LookupRoot { get; }
18521854
public override Akka.Dispatch.Mailboxes Mailboxes { get; }
@@ -2452,9 +2454,10 @@ namespace Akka.Dispatch
24522454
}
24532455
public sealed class Dispatchers
24542456
{
2457+
public static readonly string DefaultBlockingDispatcherId;
24552458
public static readonly string DefaultDispatcherId;
24562459
public static readonly string SynchronizedDispatcherId;
2457-
public Dispatchers(Akka.Actor.ActorSystem system, Akka.Dispatch.IDispatcherPrerequisites prerequisites) { }
2460+
public Dispatchers(Akka.Actor.ActorSystem system, Akka.Dispatch.IDispatcherPrerequisites prerequisites, Akka.Event.ILoggingAdapter logger) { }
24582461
public Akka.Configuration.Config DefaultDispatcherConfig { get; }
24592462
public Akka.Dispatch.MessageDispatcher DefaultGlobalDispatcher { get; }
24602463
public Akka.Dispatch.IDispatcherPrerequisites Prerequisites { get; }
@@ -4838,6 +4841,7 @@ namespace Akka.Util
48384841
public static readonly Akka.Util.Option<T> None;
48394842
public Option(T value) { }
48404843
public bool HasValue { get; }
4844+
public bool IsEmpty { get; }
48414845
public T Value { get; }
48424846
public bool Equals(Akka.Util.Option<T> other) { }
48434847
public override bool Equals(object obj) { }

src/core/Akka.API.Tests/CoreAPISpec.ApproveStreams.approved.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ namespace Akka.Streams
1919
}
2020
public class static ActorAttributes
2121
{
22+
public static Akka.Streams.ActorAttributes.Dispatcher IODispatcher { get; }
2223
public static Akka.Streams.Attributes CreateDebugLogging(bool enabled) { }
2324
public static Akka.Streams.Attributes CreateDispatcher(string dispatcherName) { }
2425
public static Akka.Streams.Attributes CreateFuzzingMode(bool enabled) { }
@@ -140,12 +141,14 @@ namespace Akka.Streams
140141
public readonly int SyncProcessingLimit;
141142
public ActorMaterializerSettings(int initialInputBufferSize, int maxInputBufferSize, string dispatcher, Akka.Streams.Supervision.Decider supervisionDecider, Akka.Streams.StreamSubscriptionTimeoutSettings subscriptionTimeoutSettings, Akka.Streams.Dsl.StreamRefSettings streamRefSettings, bool isDebugLogging, int outputBurstLimit, bool isFuzzingMode, bool isAutoFusing, int maxFixedBufferSize, int syncProcessingLimit = 1000) { }
142143
public static Akka.Streams.ActorMaterializerSettings Create(Akka.Actor.ActorSystem system) { }
144+
public override bool Equals(object obj) { }
143145
public Akka.Streams.ActorMaterializerSettings WithAutoFusing(bool isAutoFusing) { }
144146
public Akka.Streams.ActorMaterializerSettings WithDebugLogging(bool isEnabled) { }
145147
public Akka.Streams.ActorMaterializerSettings WithDispatcher(string dispatcher) { }
146148
public Akka.Streams.ActorMaterializerSettings WithFuzzingMode(bool isFuzzingMode) { }
147149
public Akka.Streams.ActorMaterializerSettings WithInputBuffer(int initialSize, int maxSize) { }
148150
public Akka.Streams.ActorMaterializerSettings WithMaxFixedBufferSize(int maxFixedBufferSize) { }
151+
public Akka.Streams.ActorMaterializerSettings WithOutputBurstLimit(int limit) { }
149152
public Akka.Streams.ActorMaterializerSettings WithStreamRefSettings(Akka.Streams.Dsl.StreamRefSettings settings) { }
150153
public Akka.Streams.ActorMaterializerSettings WithSubscriptionTimeoutSettings(Akka.Streams.StreamSubscriptionTimeoutSettings settings) { }
151154
public Akka.Streams.ActorMaterializerSettings WithSupervisionStrategy(Akka.Streams.Supervision.Decider decider) { }

src/core/Akka.Cluster.Tests/ClusterConfigSpec.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public void Clustering_must_be_able_to_parse_generic_cluster_config_elements()
4545
settings.MinNrOfMembers.Should().Be(1);
4646
settings.MinNrOfMembersOfRole.Should().Equal(ImmutableDictionary<string, int>.Empty);
4747
settings.Roles.Should().BeEquivalentTo(ImmutableHashSet<string>.Empty);
48-
settings.UseDispatcher.Should().Be(Dispatchers.DefaultDispatcherId);
48+
settings.UseDispatcher.Should().Be(Dispatchers.InternalDispatcherId);
4949
settings.GossipDifferentViewProbability.Should().Be(0.8);
5050
settings.ReduceGossipDifferentViewProbability.Should().Be(400);
5151

src/core/Akka.Cluster/ClusterSettings.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public ClusterSettings(Config config, string systemName)
7070
MinNrOfMembers = clusterConfig.GetInt("min-nr-of-members", 0);
7171

7272
_useDispatcher = clusterConfig.GetString("use-dispatcher", null);
73-
if (String.IsNullOrEmpty(_useDispatcher)) _useDispatcher = Dispatchers.DefaultDispatcherId;
73+
if (string.IsNullOrEmpty(_useDispatcher)) _useDispatcher = Dispatchers.InternalDispatcherId;
7474
GossipDifferentViewProbability = clusterConfig.GetDouble("gossip-different-view-probability", 0);
7575
ReduceGossipDifferentViewProbability = clusterConfig.GetInt("reduce-gossip-different-view-probability", 0);
7676
SchedulerTickDuration = clusterConfig.GetTimeSpan("scheduler.tick-duration", null);

src/core/Akka.Cluster/Configuration/Cluster.conf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,8 @@ akka {
128128
# Disable with "off".
129129
publish-stats-interval = off
130130

131-
# The id of the dispatcher to use for cluster actors. If not specified
132-
# default dispatcher is used.
131+
# The id of the dispatcher to use for cluster actors.
132+
# If not specified, the internal dispatcher is used.
133133
# If specified you need to define the settings of the actual dispatcher.
134134
use-dispatcher = ""
135135

src/core/Akka.MultiNodeTestRunner.Shared/Akka.MultiNodeTestRunner.Shared.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
<TargetFrameworks>$(NetStandardLibVersion)</TargetFrameworks>
66
<EnableDefaultCompileItems>false</EnableDefaultCompileItems>
77
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
8+
<!-- FIX for "<GenerateTargetFrameworkAttribute>false</GenerateTargetFrameworkAttribute>..." build error with the latest VS2019 update-->
9+
<GenerateTargetFrameworkAttribute>false</GenerateTargetFrameworkAttribute>
10+
<!-- END FIX-->
811
</PropertyGroup>
912

1013
<ItemGroup>

src/core/Akka.Streams.Tests/Dsl/UnfoldResourceAsyncSourceSpec.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ public void A_UnfoldResourceAsyncSource_must_use_dedicated_blocking_io_dispatche
293293
var actorRef = refs.First(@ref => @ref.Path.ToString().Contains("unfoldResourceSourceAsync"));
294294
try
295295
{
296-
Utils.AssertDispatcher(actorRef, "akka.stream.default-blocking-io-dispatcher");
296+
Utils.AssertDispatcher(actorRef, ActorAttributes.IODispatcher.Name);
297297
}
298298
finally
299299
{

src/core/Akka.Streams.Tests/Dsl/UnfoldResourceSourceSpec.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ public void A_UnfoldResourceSource_must_use_dedicated_blocking_io_dispatcher_by_
211211
var actorRef = refs.First(@ref => @ref.Path.ToString().Contains("unfoldResourceSource"));
212212
try
213213
{
214-
Utils.AssertDispatcher(actorRef, "akka.stream.default-blocking-io-dispatcher");
214+
Utils.AssertDispatcher(actorRef, ActorAttributes.IODispatcher.Name);
215215
}
216216
finally
217217
{

0 commit comments

Comments
 (0)