Skip to content

Commit 5c25340

Browse files
committed
Tweak actor creation
1 parent ebd2998 commit 5c25340

File tree

4 files changed

+22
-14
lines changed

4 files changed

+22
-14
lines changed

src/Akka.Persistence.Benchmarks/BenchmarkBase.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ public virtual async Task SetupAsync()
4040
"""
4141
akka {
4242
log-config-on-start = off
43-
stdout-loglevel = DEBUG
44-
loglevel = DEBUG
43+
stdout-loglevel = INFO
44+
loglevel = INFO
4545
log-dead-letters = off # no dead letters
4646
actor {
4747
debug {

src/Akka.Persistence.Benchmarks/Benchmarks/GroupPersistBenchmark.cs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,24 @@ public abstract class GroupPersistBenchmark: BenchmarkBase
1717
[Params(1, 100)]
1818
public override int BatchSize { get; set; }
1919

20-
protected override async Task GlobalSetupAsync()
20+
protected override Task GlobalSetupAsync()
2121
{
22-
_persistenceActors = Enumerable.Range(1, GroupSize)
23-
.Select(idx => ActorSystem!.ActorOf(Props.Create(() => new BenchActor($"GroupPersistPid_{idx}", TestMessageCount, null, BatchSize))))
24-
.ToArray();
25-
26-
await Task.WhenAll(_persistenceActors.Select(actor => actor.Ask<Done>(Start.Instance)));
22+
return Task.CompletedTask;
2723
}
2824

2925
[IterationSetup]
3026
public void IterationSetup()
3127
{
28+
_persistenceActors = Enumerable.Range(1, GroupSize)
29+
.Select(idx => ActorSystem!.ActorOf(Props.Create(() => new BenchActor($"GroupPersistPid_{idx}", TestMessageCount, null, BatchSize))))
30+
.ToArray();
31+
32+
Task.WhenAll(_persistenceActors.Select(actor => actor.Ask<Done>(Start.Instance))).Wait();
3233
}
3334

3435
protected override void IterationCleanup()
3536
{
37+
Task.WhenAll(_persistenceActors!.Select(actor => actor.GracefulStop(TimeSpan.FromSeconds(5)))).Wait();
3638
}
3739

3840
[Benchmark(OperationsPerInvoke = TotalMessageCount)]

src/Akka.Persistence.Benchmarks/Benchmarks/PersistBenchmark.cs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Threading.Tasks;
1+
using System;
2+
using System.Threading.Tasks;
23
using Akka.Actor;
34
using BenchmarkDotNet.Attributes;
45

@@ -13,21 +14,24 @@ public abstract class PersistBenchmark: BenchmarkBase
1314
[Params(1, 100)]
1415
public override int BatchSize { get; set; }
1516

16-
protected override async Task GlobalSetupAsync()
17+
protected override Task GlobalSetupAsync()
1718
{
18-
_persistenceActor =
19-
ActorSystem!.ActorOf(Props.Create(() => new BenchActor("SingleRecoveryPid", TestMessageCount, null, BatchSize)));
20-
21-
await _persistenceActor.Ask<Done>(Start.Instance, CompletionTimeout);
19+
return Task.CompletedTask;
2220
}
2321

2422
[IterationSetup]
2523
public void IterationSetup()
2624
{
25+
// Generate unique persistence ID for this iteration
26+
var pid = $"benchmark-{Guid.NewGuid()}";
27+
_persistenceActor = ActorSystem!.ActorOf(Props.Create(() => new BenchActor(pid, TestMessageCount, null, BatchSize)));
28+
29+
_persistenceActor.Ask<Done>(Start.Instance, CompletionTimeout).Wait();
2730
}
2831

2932
protected override void IterationCleanup()
3033
{
34+
_persistenceActor.GracefulStop(TimeSpan.FromSeconds(5));
3135
}
3236

3337
[Benchmark(OperationsPerInvoke = TestMessageCount)]

src/Akka.Persistence.Benchmarks/Configs/MacroBenchmarkConfig.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,14 @@ public MacroBenchmarkConfig()
2323
AddColumn(new CategoriesColumn());
2424
AddLogger(ConsoleLogger.Default);
2525

26+
/*
2627
// Safer affinity mask (optional; remove if not needed)
2728
var processorCount = Environment.ProcessorCount;
2829
var affinityMaskValue = processorCount == 64
2930
? ulong.MaxValue
3031
: (1UL << processorCount) - 1;
3132
var affinityMask = (IntPtr)affinityMaskValue;
33+
*/
3234

3335
AddJob(Job.LongRun
3436
.WithGcMode(new GcMode { Server = true, Concurrent = true })

0 commit comments

Comments
 (0)