-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added actor messaging pressure benchmark (#6147)
purpose of this benchmark is not to measure processing time - it's meant to measure allocation pressure created by Akka.NET infrastructure: * `Envelope`s * `Mailbox` and `MessageDispatcher` overhead * `ActorCell` and `ActorBase` invocation overhead Ideally the memory pressure, given a `const string` as messaging input, should be close to zero - but between mailbox queue segment allocations, delegate + closure allocations, and probably some boxing we know that's not the case. Purpose of this benchmark is to measure that impact across threads.
- Loading branch information
1 parent
4b1a746
commit bf273d9
Showing
2 changed files
with
93 additions
and
2 deletions.
There are no files selected for viewing
91 changes: 91 additions & 0 deletions
91
src/benchmark/Akka.Benchmarks/Actor/ActorMessagingMemoryPressureBenchmark.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
// //----------------------------------------------------------------------- | ||
// // <copyright file="ActorMessagingMemoryPressureBenchmark.cs" company="Akka.NET Project"> | ||
// // Copyright (C) 2009-2022 Lightbend Inc. <http://www.lightbend.com> | ||
// // Copyright (C) 2013-2022 .NET Foundation <https://github.com/akkadotnet/akka.net> | ||
// // </copyright> | ||
// //----------------------------------------------------------------------- | ||
|
||
using System; | ||
using System.Threading.Tasks; | ||
using Akka.Actor; | ||
using Akka.Benchmarks.Configurations; | ||
using Akka.Routing; | ||
using BenchmarkDotNet.Attributes; | ||
|
||
namespace Akka.Benchmarks.Actor | ||
{ | ||
[Config(typeof(MicroBenchmarkConfig))] | ||
public class ActorMessagingMemoryPressureBenchmark | ||
{ | ||
#region Classes | ||
public sealed class StopActor | ||
{ | ||
private StopActor(){} | ||
public static readonly StopActor Instance = new StopActor(); | ||
} | ||
|
||
public sealed class MyActor : ReceiveActor | ||
{ | ||
public MyActor() | ||
{ | ||
Receive<StopActor>(str => | ||
{ | ||
Context.Stop(Self); | ||
Sender.Tell(str); | ||
}); | ||
|
||
Receive<string>(str => | ||
{ | ||
Sender.Tell(str); | ||
}); | ||
} | ||
} | ||
#endregion | ||
|
||
private ActorSystem _sys; | ||
private IActorRef _actorEntryPoint; | ||
|
||
private const string Msg = "hit"; | ||
|
||
[Params(100_000)] | ||
public int MsgCount { get; set; } | ||
|
||
[Params(10, 100)] | ||
public int ActorCount { get; set; } | ||
|
||
[GlobalSetup] | ||
public void Setup() | ||
{ | ||
_sys = ActorSystem.Create("Bench", @"akka.log-dead-letters = off"); | ||
} | ||
|
||
[GlobalCleanup] | ||
public async Task CleanUp() | ||
{ | ||
await _sys.Terminate(); | ||
} | ||
|
||
[IterationCleanup] | ||
public void PerInvokeCleanup() | ||
{ | ||
_actorEntryPoint.GracefulStop(TimeSpan.FromSeconds(5)).Wait(); | ||
} | ||
|
||
[IterationSetup] | ||
public void PerInvokeSetup() | ||
{ | ||
_actorEntryPoint = _sys.ActorOf(Props.Create<MyActor>().WithRouter(new BroadcastPool(ActorCount))); | ||
} | ||
|
||
[Benchmark] | ||
public Task PushMsgs() | ||
{ | ||
for (var i = 0; i < MsgCount; i++) | ||
{ | ||
_actorEntryPoint.Tell(Msg); | ||
} | ||
|
||
return Task.CompletedTask; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters