-
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.
Perf optimize
ActorSelection
(#4962)
* added memory metrics to `ActorSelection` benchmarks * added ActorSelection benchmark * ramped up the iteration counts * validate that double wildcard can't be used outside of leaf node * improve allocations on create * minor cleanup * create emptyRef only when needed via local function * made `Iterator` into `struct` * approved public API changes
- Loading branch information
1 parent
8d03165
commit 3f232d8
Showing
6 changed files
with
103 additions
and
15 deletions.
There are no files selected for viewing
62 changes: 62 additions & 0 deletions
62
src/benchmark/Akka.Benchmarks/Actor/ActorSelectionBenchmark.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,62 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Net.NetworkInformation; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Akka.Actor; | ||
using Akka.Benchmarks.Configurations; | ||
using BenchmarkDotNet.Attributes; | ||
using BenchmarkDotNet.Engines; | ||
|
||
namespace Akka.Benchmarks.Actor | ||
{ | ||
[Config(typeof(MicroBenchmarkConfig))] // need memory diagnosis | ||
public class ActorSelectionBenchmark | ||
{ | ||
[Params(10000)] | ||
public int Iterations { get; set; } | ||
private TimeSpan _timeout; | ||
private ActorSystem _system; | ||
private IActorRef _echo; | ||
|
||
// cached selection for measuring .Tell / .Ask performance | ||
private ActorSelection _actorSelection; | ||
|
||
[GlobalSetup] | ||
public void Setup() | ||
{ | ||
_timeout = TimeSpan.FromMinutes(1); | ||
_system = ActorSystem.Create("system"); | ||
_echo = _system.ActorOf(Props.Create(() => new EchoActor()), "echo"); | ||
_actorSelection = _system.ActorSelection("/user/echo"); | ||
} | ||
|
||
[Benchmark] | ||
public async Task RequestResponseActorSelection() | ||
{ | ||
for(var i = 0; i < Iterations; i++) | ||
await _actorSelection.Ask("foo", _timeout); | ||
} | ||
|
||
[Benchmark] | ||
public void CreateActorSelection() | ||
{ | ||
for (var i = 0; i < Iterations; i++) | ||
_system.ActorSelection("/user/echo"); | ||
} | ||
|
||
[GlobalCleanup] | ||
public void Cleanup() | ||
{ | ||
_system.Terminate().Wait(); | ||
} | ||
|
||
public class EchoActor : UntypedActor | ||
{ | ||
protected override void OnReceive(object message) | ||
{ | ||
Sender.Tell(message); | ||
} | ||
} | ||
} | ||
} |
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
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
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
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
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