-
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.
Merge pull request #1999 from Aaronontheweb/ask-benchmark
added Ask performance benchmark
- Loading branch information
Showing
2 changed files
with
61 additions
and
0 deletions.
There are no files selected for viewing
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,60 @@ | ||
using System; | ||
using Akka.Actor; | ||
using NBench; | ||
|
||
namespace Akka.Tests.Performance.Actor.Pattern | ||
{ | ||
/// <summary> | ||
/// Benchmark and performance test for <see cref="Ask"/> | ||
/// </summary> | ||
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<ActorIdentity>(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}"); | ||
} | ||
} | ||
} | ||
} |
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