diff --git a/src/Akka.sln b/src/Akka.sln index bf0782f7236..f549c34eeec 100644 --- a/src/Akka.sln +++ b/src/Akka.sln @@ -248,6 +248,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DDataStressTest", "examples EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Akka.Cluster.Benchmarks", "benchmark\Akka.Cluster.Benchmarks\Akka.Cluster.Benchmarks.csproj", "{3CEBB0AE-6A88-4C32-A1D3-A8FB1E7E236B}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Akka.ChildResolve", "benchmark\Akka.ChildResolve\Akka.ChildResolve.csproj", "{1AF11505-8B49-40AF-8059-E214B775AC94}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -1151,6 +1153,18 @@ Global {3CEBB0AE-6A88-4C32-A1D3-A8FB1E7E236B}.Release|x64.Build.0 = Release|Any CPU {3CEBB0AE-6A88-4C32-A1D3-A8FB1E7E236B}.Release|x86.ActiveCfg = Release|Any CPU {3CEBB0AE-6A88-4C32-A1D3-A8FB1E7E236B}.Release|x86.Build.0 = Release|Any CPU + {1AF11505-8B49-40AF-8059-E214B775AC94}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {1AF11505-8B49-40AF-8059-E214B775AC94}.Debug|Any CPU.Build.0 = Debug|Any CPU + {1AF11505-8B49-40AF-8059-E214B775AC94}.Debug|x64.ActiveCfg = Debug|Any CPU + {1AF11505-8B49-40AF-8059-E214B775AC94}.Debug|x64.Build.0 = Debug|Any CPU + {1AF11505-8B49-40AF-8059-E214B775AC94}.Debug|x86.ActiveCfg = Debug|Any CPU + {1AF11505-8B49-40AF-8059-E214B775AC94}.Debug|x86.Build.0 = Debug|Any CPU + {1AF11505-8B49-40AF-8059-E214B775AC94}.Release|Any CPU.ActiveCfg = Release|Any CPU + {1AF11505-8B49-40AF-8059-E214B775AC94}.Release|Any CPU.Build.0 = Release|Any CPU + {1AF11505-8B49-40AF-8059-E214B775AC94}.Release|x64.ActiveCfg = Release|Any CPU + {1AF11505-8B49-40AF-8059-E214B775AC94}.Release|x64.Build.0 = Release|Any CPU + {1AF11505-8B49-40AF-8059-E214B775AC94}.Release|x86.ActiveCfg = Release|Any CPU + {1AF11505-8B49-40AF-8059-E214B775AC94}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -1260,6 +1274,7 @@ Global {2E4B9584-42CC-4D17-B719-9F462B16C94D} = {73108242-625A-4D7B-AA09-63375DBAE464} {44B3DDD6-6103-4E8F-8AC2-0F4BA3CF6B50} = {C50E1A9E-820C-4E75-AE39-6F96A99AC4A7} {3CEBB0AE-6A88-4C32-A1D3-A8FB1E7E236B} = {73108242-625A-4D7B-AA09-63375DBAE464} + {1AF11505-8B49-40AF-8059-E214B775AC94} = {73108242-625A-4D7B-AA09-63375DBAE464} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {03AD8E21-7507-4E68-A4E9-F4A7E7273164} diff --git a/src/benchmark/Akka.ChildResolve/Akka.ChildResolve.csproj b/src/benchmark/Akka.ChildResolve/Akka.ChildResolve.csproj new file mode 100644 index 00000000000..489a1521007 --- /dev/null +++ b/src/benchmark/Akka.ChildResolve/Akka.ChildResolve.csproj @@ -0,0 +1,19 @@ + + + + Exe + netcoreapp3.1 + + + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + diff --git a/src/benchmark/Akka.ChildResolve/Program.cs b/src/benchmark/Akka.ChildResolve/Program.cs new file mode 100644 index 00000000000..0c0b2cd36d0 --- /dev/null +++ b/src/benchmark/Akka.ChildResolve/Program.cs @@ -0,0 +1,107 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Akka.Actor; +using Akka.Util.Internal; + +namespace Akka.ChildResolve +{ + public sealed class Child : UntypedActor + { + protected override void OnReceive(object message) + { + } + + protected override void PreStart() + { + if (Self.Path.Name.Length > 1) + { + // recursively create children using the previous name segments + var nextName = new string(Self.Path.Name.Skip(1).ToArray()); + Context.ActorOf(Props.Create(() => new Child()), nextName); + } + } + } + + public sealed class ActorWithChild : UntypedActor + { + public sealed class Get + { + public Get(string name) + { + Name = name; + } + + public string Name { get; } + } + + public sealed class Create + { + public Create(string name) + { + Name = name; + } + + public string Name { get; } + } + + protected override void OnReceive(object message) + { + switch (message) + { + case Get g: + { + var child = Context.Child(g.Name); + Sender.Tell(child); + break; + } + case Create c: + { + var child = Context.ActorOf(Props.Create(() => new Child()), c.Name); + Sender.Tell(child); + break; + } + default: + Unhandled(message); + break; + } + } + } + + class Program + { + static async Task Main(string[] args) + { + TimeSpan _timeout; + ActorSystem _system; + IActorRef _parentActor; + + ActorWithChild.Get _getMessage = new ActorWithChild.Get("food"); + ActorWithChild.Create _createMessage = new ActorWithChild.Create("food"); + + IActorContext _cell; + RepointableActorRef _repointableActorRef; + LocalActorRef _localActorRef; + + List _rpChildQueryPath = new List() { "food", "ood", "od" }; + List _lclChildQueryPath = new List() { "ood", "od", "d" }; + + + _timeout = TimeSpan.FromMinutes(1); + _system = ActorSystem.Create("system"); + _parentActor = _system.ActorOf(Props.Create(() => new ActorWithChild()), "parent"); + _localActorRef = (LocalActorRef)await _parentActor.Ask(_createMessage, _timeout); + + _cell = _parentActor.AsInstanceOf().Underlying.AsInstanceOf(); + _repointableActorRef = (RepointableActorRef)_parentActor; + + + foreach (var i in Enumerable.Range(0, 1_000_000)) + _cell.Child(_getMessage.Name); + + foreach (var i in Enumerable.Range(0, 100_000_000)) + _repointableActorRef.GetChild(_rpChildQueryPath); + } + } +} \ No newline at end of file