diff --git a/src/core/Akka.Tests.Performance/Actor/Pattern/AskSpec.cs b/src/core/Akka.Tests.Performance/Actor/Pattern/AskSpec.cs new file mode 100644 index 00000000000..7928769194e --- /dev/null +++ b/src/core/Akka.Tests.Performance/Actor/Pattern/AskSpec.cs @@ -0,0 +1,60 @@ +using System; +using Akka.Actor; +using NBench; + +namespace Akka.Tests.Performance.Actor.Pattern +{ + /// + /// Benchmark and performance test for + /// + public class AskSpec + { + class EmptyActor : ReceiveActor + { + public EmptyActor() + { + ReceiveAny(o => Sender.Tell(o)); + } + } + + public const string AskThroughputCounterName = "AskReplies"; + private Counter _askThroughputCounter; + + private ActorSystem _sys; + private IActorRef _target; + private static readonly Identify Msg = new Identify(null); + private static readonly TimeSpan AskTimeout = TimeSpan.FromSeconds(1); + + [PerfSetup] + public void Setup(BenchmarkContext context) + { + _sys = ActorSystem.Create("AskSpec"); + _target = _sys.ActorOf(Props.Create(() => new EmptyActor())); + _askThroughputCounter = context.GetCounter(AskThroughputCounterName); + } + + [PerfBenchmark(Description = "Tests how quickly ICanTell.Ask operations can be performed, and with how much memory", RunMode = RunMode.Throughput, + RunTimeMilliseconds = 5000, NumberOfIterations = 3)] + [CounterMeasurement(AskThroughputCounterName)] + [MemoryMeasurement(MemoryMetric.TotalBytesAllocated)] + public void AskThroughput(BenchmarkContext context) + { + _target.Ask(Msg, AskTimeout).Wait(); + _askThroughputCounter.Increment(); + } + + [PerfCleanup] + public void TearDown(BenchmarkContext context) + { + var shutdownTimeout = TimeSpan.FromSeconds(5); + try + { + _sys?.Terminate().Wait(shutdownTimeout); + } + catch (Exception ex) + { + context.Trace.Error(ex, $"failed to shutdown actorsystem within {shutdownTimeout}"); + } + } + } +} diff --git a/src/core/Akka.Tests.Performance/Akka.Tests.Performance.csproj b/src/core/Akka.Tests.Performance/Akka.Tests.Performance.csproj index 7c718681ec4..a7f6e4bad23 100644 --- a/src/core/Akka.Tests.Performance/Akka.Tests.Performance.csproj +++ b/src/core/Akka.Tests.Performance/Akka.Tests.Performance.csproj @@ -49,6 +49,7 @@ +