Skip to content

Commit

Permalink
added actor messaging pressure benchmark (#6147)
Browse files Browse the repository at this point in the history
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
Aaronontheweb committed Oct 8, 2022
1 parent 2032ff9 commit ef186a4
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 2 deletions.
@@ -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;
}
}
}
4 changes: 2 additions & 2 deletions src/benchmark/Akka.Benchmarks/Actor/FsmBenchmarks.cs
Expand Up @@ -118,9 +118,9 @@ public void Setup()
}

[GlobalCleanup]
public void CleanUp()
public async Task CleanUp()
{
_sys.Terminate().Wait();
await _sys.Terminate();
}

[Benchmark]
Expand Down

0 comments on commit ef186a4

Please sign in to comment.