-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Emil Koutanov
committed
Jan 29, 2024
1 parent
ef30877
commit fbdc86e
Showing
6 changed files
with
127 additions
and
5 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 |
---|---|---|
@@ -1,6 +1,8 @@ | ||
{ | ||
"cSpell.words": [ | ||
"Backpresure", | ||
"Schedulable" | ||
"EPYC", | ||
"Schedulable", | ||
"unscheduling" | ||
] | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
using System; | ||
using System.Threading.Tasks; | ||
using BenchmarkDotNet; | ||
using BenchmarkDotNet.Attributes; | ||
|
||
namespace Actors.Benchmarks; | ||
#nullable enable | ||
|
||
public class EchoBenchmark | ||
{ | ||
class SendPings(int pings) | ||
{ | ||
public int Pings { get; } = pings; | ||
|
||
public TaskCompletionSource Completion { get; } = new TaskCompletionSource(); | ||
} | ||
|
||
class Ping {} | ||
|
||
class Pong {} | ||
|
||
class PingActor : Actor | ||
{ | ||
internal PongActor? Opponent { get; set; } | ||
|
||
private int remainingMessages; | ||
|
||
private SendPings? sendPings; | ||
|
||
protected override Task Perform(Inbox inbox) | ||
{ | ||
switch (inbox.Receive()) | ||
{ | ||
case SendPings message: | ||
this.sendPings = message; | ||
this.remainingMessages = sendPings.Pings; | ||
Opponent!.Send(new Ping()); | ||
break; | ||
|
||
case Pong message: | ||
remainingMessages--; | ||
if (remainingMessages > 0) | ||
{ | ||
Opponent!.Send(new Ping()); | ||
} | ||
else | ||
{ | ||
sendPings!.Completion.SetResult(); | ||
} | ||
break; | ||
|
||
default: | ||
throw new NotSupportedException(); | ||
} | ||
return Task.CompletedTask; | ||
} | ||
} | ||
|
||
class PongActor : Actor | ||
{ | ||
internal PingActor? Opponent { get; set; } | ||
|
||
protected override Task Perform(Inbox inbox) | ||
{ | ||
switch (inbox.Receive()) | ||
{ | ||
case Ping message: | ||
Opponent!.Send(new Pong()); | ||
break; | ||
|
||
default: | ||
throw new NotSupportedException(); | ||
} | ||
return Task.CompletedTask; | ||
} | ||
} | ||
|
||
private readonly PingActor pingActor = new(); | ||
private readonly PongActor pongActor = new(); | ||
|
||
[GlobalSetup] | ||
public void Setup() | ||
{ | ||
pingActor.Opponent = pongActor; | ||
pongActor.Opponent = pingActor; | ||
} | ||
|
||
[Params(1_000)] | ||
public int numMessages; | ||
|
||
[Benchmark] | ||
public async Task StartAndWait() | ||
{ | ||
var sendPings = new SendPings(numMessages); | ||
pingActor.Send(sendPings); | ||
await sendPings.Completion.Task; | ||
} | ||
} |
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