From c34525bf1e558ad5a65269f5a274b33ce7503322 Mon Sep 17 00:00:00 2001 From: Gregorius Soedharmo <arkatufus@yahoo.com> Date: Sat, 13 Jan 2024 03:21:23 +0700 Subject: [PATCH] Fix cluster sharding benchmark --- .../Akka.Benchmarks/Configurations/Configs.cs | 21 +++++++++++-------- .../Sharding/ShardingInfrastructure.cs | 14 +++++++------ 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/src/benchmark/Akka.Benchmarks/Configurations/Configs.cs b/src/benchmark/Akka.Benchmarks/Configurations/Configs.cs index b8afd531f15..28353207e6c 100644 --- a/src/benchmark/Akka.Benchmarks/Configurations/Configs.cs +++ b/src/benchmark/Akka.Benchmarks/Configurations/Configs.cs @@ -37,16 +37,19 @@ public string GetValue(Summary summary, BenchmarkCase benchmarkCase, SummaryStyl var benchmarkAttribute = benchmarkCase.Descriptor.WorkloadMethod.GetCustomAttribute<BenchmarkAttribute>(); var totalOperations = benchmarkAttribute?.OperationsPerInvoke ?? 1; - if (summary.HasReport(benchmarkCase)) - { - var report = summary[benchmarkCase]; - var nsPerOperation = report.ResultStatistics.Mean; - var operationsPerSecond = 1 / (nsPerOperation / 1e9); - - return operationsPerSecond.ToString("N2"); // or format as you like - } + if (!summary.HasReport(benchmarkCase)) + return "<not found>"; + + var report = summary[benchmarkCase]; + var statistics = report?.ResultStatistics; + if(statistics is null) + return "<not found>"; - return "<not found>"; + var nsPerOperation = statistics.Mean; + var operationsPerSecond = 1 / (nsPerOperation / 1e9); + + return operationsPerSecond.ToString("N2"); // or format as you like + } } diff --git a/src/benchmark/Akka.Cluster.Benchmarks/Sharding/ShardingInfrastructure.cs b/src/benchmark/Akka.Cluster.Benchmarks/Sharding/ShardingInfrastructure.cs index be5ee9f05bf..09ca6f99f9c 100644 --- a/src/benchmark/Akka.Cluster.Benchmarks/Sharding/ShardingInfrastructure.cs +++ b/src/benchmark/Akka.Cluster.Benchmarks/Sharding/ShardingInfrastructure.cs @@ -33,11 +33,11 @@ public ResolveResp(string entityId, Address addr) public Address Addr { get; } } - public ShardedEntityActor() + public ShardedEntityActor(string entityId) { - Receive<ShardingEnvelope>(e => + Receive<Resolve>(_ => { - Sender.Tell(new ResolveResp(e.EntityId, Cluster.Get(Context.System).SelfAddress)); + Sender.Tell(new ResolveResp(entityId, Cluster.Get(Context.System).SelfAddress)); }); ReceiveAny(o => Sender.Tell(o)); @@ -248,10 +248,12 @@ public static Config CreateDDataConfig(bool rememberEntities = false) public static IActorRef StartShardRegion(ActorSystem system, string entityName = "entities") { - var props = Props.Create(() => new ShardedEntityActor()); var sharding = ClusterSharding.Get(system); - return sharding.Start(entityName, _ => props, ClusterShardingSettings.Create(system), - new ShardMessageExtractor()); + return sharding.Start( + typeName: entityName, + entityPropsFactory: id => Props.Create(() => new ShardedEntityActor(id)), + settings: ClusterShardingSettings.Create(system), + messageExtractor: new ShardMessageExtractor()); } } }