Skip to content

Commit

Permalink
added child-resolve program
Browse files Browse the repository at this point in the history
  • Loading branch information
Aaronontheweb committed Sep 2, 2021
1 parent 6b590d7 commit 8cce9b7
Show file tree
Hide file tree
Showing 3 changed files with 141 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/Akka.sln
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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}
Expand Down
19 changes: 19 additions & 0 deletions src/benchmark/Akka.ChildResolve/Akka.ChildResolve.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\core\Akka\Akka.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies.net471" Version="1.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

</Project>
107 changes: 107 additions & 0 deletions src/benchmark/Akka.ChildResolve/Program.cs
Original file line number Diff line number Diff line change
@@ -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<string> _rpChildQueryPath = new List<string>() { "food", "ood", "od" };
List<string> _lclChildQueryPath = new List<string>() { "ood", "od", "d" };


_timeout = TimeSpan.FromMinutes(1);
_system = ActorSystem.Create("system");
_parentActor = _system.ActorOf(Props.Create(() => new ActorWithChild()), "parent");
_localActorRef = (LocalActorRef)await _parentActor.Ask<IActorRef>(_createMessage, _timeout);

_cell = _parentActor.AsInstanceOf<ActorRefWithCell>().Underlying.AsInstanceOf<ActorCell>();
_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);
}
}
}

0 comments on commit 8cce9b7

Please sign in to comment.