-
Notifications
You must be signed in to change notification settings - Fork 10
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
1 parent
ae93a37
commit 0d59f13
Showing
34 changed files
with
640 additions
and
204 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
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
26 changes: 26 additions & 0 deletions
26
src/Akka.Persistence.EventStore.Benchmarks/Akka.Persistence.EventStore.Benchmarks.csproj
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,26 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\Akka.Persistence.EventStore.Tests\Akka.Persistence.EventStore.Tests.csproj" /> | ||
<ProjectReference Include="..\Akka.Persistence.EventStore\Akka.Persistence.EventStore.csproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="BenchmarkDotNet" /> | ||
<PackageReference Include="FluentAssertions" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<None Update="benchmark.conf"> | ||
<CopyToOutputDirectory>Always</CopyToOutputDirectory> | ||
</None> | ||
</ItemGroup> | ||
|
||
</Project> |
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,15 @@ | ||
namespace Akka.Persistence.EventStore.Benchmarks; | ||
|
||
internal static class Const | ||
{ | ||
public const int TotalMessages = 3000000; | ||
public const int TagLowerBound = 2 * (TotalMessages / 3); | ||
public const string Tag10 = "Tag1"; | ||
public const string Tag100 = "Tag2"; | ||
public const string Tag1000 = "Tag3"; | ||
public const string Tag10000 = "Tag4"; | ||
public const int Tag10UpperBound = TagLowerBound + 10; | ||
public const int Tag100UpperBound = TagLowerBound + 100; | ||
public const int Tag1000UpperBound = TagLowerBound + 1000; | ||
public const int Tag10000UpperBound = TagLowerBound + 10000; | ||
} |
69 changes: 69 additions & 0 deletions
69
src/Akka.Persistence.EventStore.Benchmarks/EventStoreBenchmarkFixture.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,69 @@ | ||
using Akka.Actor; | ||
using Akka.Configuration; | ||
using Akka.Persistence.EventStore.Tests; | ||
using FluentAssertions.Extensions; | ||
|
||
namespace Akka.Persistence.EventStore.Benchmarks; | ||
|
||
public static class EventStoreBenchmarkFixture | ||
{ | ||
private static EventStoreContainer? _eventStoreContainer; | ||
|
||
public static async Task<ActorSystem> CreateActorSystem(string name, Config? extraConfig = null) | ||
{ | ||
var config = ConfigurationFactory.ParseString(await File.ReadAllTextAsync("benchmark.conf")) | ||
.WithFallback(extraConfig ?? "") | ||
.WithFallback(Persistence.DefaultConfig()) | ||
.WithFallback(EventStorePersistence.DefaultConfiguration); | ||
|
||
return ActorSystem.Create(name, config); | ||
} | ||
|
||
public static async Task Initialize() | ||
{ | ||
_eventStoreContainer = new EventStoreContainer(); | ||
await _eventStoreContainer.InitializeAsync(); | ||
|
||
await File.WriteAllTextAsync( | ||
"benchmark.conf", | ||
$$""" | ||
akka.persistence.journal { | ||
plugin = akka.persistence.journal.eventstore | ||
eventstore { | ||
connection-string = "{{_eventStoreContainer.ConnectionString}}" | ||
event-adapters { | ||
event-tagger = "{{typeof(EventTagger).AssemblyQualifiedName}}" | ||
} | ||
event-adapter-bindings { | ||
"System.Int32" = event-tagger | ||
} | ||
} | ||
} | ||
akka.persistence.query.journal.eventstore { | ||
write-plugin = akka.persistence.journal.eventstore | ||
} | ||
"""); | ||
|
||
var sys = await CreateActorSystem("Initializer", """ | ||
akka.persistence.journal { | ||
eventstore { | ||
auto-initialize = true | ||
} | ||
} | ||
"""); | ||
|
||
var initializer = sys.ActorOf(Props.Create(() => new InitializeDbActor()), "INITIALIZER"); | ||
|
||
await initializer.Ask<InitializeDbActor.Initialized>( | ||
InitializeDbActor.Initialize.Instance, | ||
20.Minutes()); | ||
} | ||
|
||
public static async Task Dispose() | ||
{ | ||
if (_eventStoreContainer is not null) | ||
await _eventStoreContainer.DisposeAsync(); | ||
} | ||
} |
76 changes: 76 additions & 0 deletions
76
src/Akka.Persistence.EventStore.Benchmarks/EventStoreTagBenchmark.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,76 @@ | ||
using Akka.Actor; | ||
using Akka.Persistence.EventStore.Query; | ||
using Akka.Persistence.Query; | ||
using Akka.Streams; | ||
using BenchmarkDotNet.Attributes; | ||
using FluentAssertions; | ||
|
||
namespace Akka.Persistence.EventStore.Benchmarks; | ||
|
||
[Config(typeof(MicroBenchmarkConfig))] | ||
public class EventStoreTagBenchmark | ||
{ | ||
private IMaterializer? _materializer; | ||
private IReadJournal? _readJournal; | ||
|
||
private ActorSystem? _sys; | ||
|
||
[GlobalSetup] | ||
public async Task Setup() | ||
{ | ||
_sys = await EventStoreBenchmarkFixture.CreateActorSystem("system"); | ||
_materializer = _sys.Materializer(); | ||
_readJournal = _sys.ReadJournalFor<EventStoreReadJournal>("akka.persistence.query.journal.eventstore"); | ||
} | ||
|
||
[GlobalCleanup] | ||
public async Task Cleanup() | ||
{ | ||
if (_sys is not null) | ||
await _sys.Terminate(); | ||
} | ||
|
||
[Benchmark] | ||
public async Task QueryByTag10() | ||
{ | ||
var events = new List<EventEnvelope>(); | ||
var source = ((ICurrentEventsByTagQuery)_readJournal!).CurrentEventsByTag(Const.Tag10, NoOffset.Instance); | ||
await source.RunForeach( | ||
msg => { events.Add(msg); }, | ||
_materializer); | ||
events.Select(e => e.SequenceNr).Should().BeEquivalentTo(Enumerable.Range(2000001, 10)); | ||
} | ||
|
||
[Benchmark] | ||
public async Task QueryByTag100() | ||
{ | ||
var events = new List<EventEnvelope>(); | ||
var source = ((ICurrentEventsByTagQuery)_readJournal!).CurrentEventsByTag(Const.Tag100, NoOffset.Instance); | ||
await source.RunForeach( | ||
msg => { events.Add(msg); }, | ||
_materializer); | ||
events.Select(e => e.SequenceNr).Should().BeEquivalentTo(Enumerable.Range(2000001, 100)); | ||
} | ||
|
||
[Benchmark] | ||
public async Task QueryByTag1000() | ||
{ | ||
var events = new List<EventEnvelope>(); | ||
var source = ((ICurrentEventsByTagQuery)_readJournal!).CurrentEventsByTag(Const.Tag1000, NoOffset.Instance); | ||
await source.RunForeach( | ||
msg => { events.Add(msg); }, | ||
_materializer); | ||
events.Select(e => e.SequenceNr).Should().BeEquivalentTo(Enumerable.Range(2000001, 1000)); | ||
} | ||
|
||
[Benchmark] | ||
public async Task QueryByTag10000() | ||
{ | ||
var events = new List<EventEnvelope>(); | ||
var source = ((ICurrentEventsByTagQuery)_readJournal!).CurrentEventsByTag(Const.Tag10000, NoOffset.Instance); | ||
await source.RunForeach( | ||
msg => { events.Add(msg); }, | ||
_materializer); | ||
events.Select(e => e.SequenceNr).Should().BeEquivalentTo(Enumerable.Range(2000001, 10000)); | ||
} | ||
} |
97 changes: 97 additions & 0 deletions
97
src/Akka.Persistence.EventStore.Benchmarks/EventStoreWriteBenchmark.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,97 @@ | ||
using Akka.Actor; | ||
using BenchmarkDotNet.Attributes; | ||
|
||
namespace Akka.Persistence.EventStore.Benchmarks; | ||
|
||
[Config(typeof(MicroBenchmarkConfig))] | ||
public class EventStoreWriteBenchmark | ||
{ | ||
private ActorSystem? _sys; | ||
|
||
[GlobalSetup] | ||
public async Task Setup() | ||
{ | ||
_sys = await EventStoreBenchmarkFixture.CreateActorSystem("system"); | ||
} | ||
|
||
[GlobalCleanup] | ||
public async Task Cleanup() | ||
{ | ||
if (_sys is not null) | ||
await _sys.Terminate(); | ||
} | ||
|
||
[Benchmark] | ||
public async Task Write10Events() | ||
{ | ||
var writeEventsActor = _sys!.ActorOf(Props.Create(() => new WriteEventsActor(Guid.NewGuid().ToString()))); | ||
|
||
for (var i = 0; i < 10; i++) | ||
{ | ||
await writeEventsActor.Ask<WriteEventsActor.Responses.WriteEventsResponse>( | ||
new WriteEventsActor.Commands.WriteEvents(1)); | ||
} | ||
} | ||
|
||
[Benchmark] | ||
public async Task Write100Events() | ||
{ | ||
var writeEventsActor = _sys!.ActorOf(Props.Create(() => new WriteEventsActor(Guid.NewGuid().ToString()))); | ||
|
||
for (var i = 0; i < 100; i++) | ||
{ | ||
await writeEventsActor.Ask<WriteEventsActor.Responses.WriteEventsResponse>( | ||
new WriteEventsActor.Commands.WriteEvents(1)); | ||
} | ||
} | ||
|
||
[Benchmark] | ||
public async Task Write10EventsBatched() | ||
{ | ||
var writeEventsActor = _sys!.ActorOf(Props.Create(() => new WriteEventsActor(Guid.NewGuid().ToString()))); | ||
|
||
await writeEventsActor.Ask<WriteEventsActor.Responses.WriteEventsResponse>( | ||
new WriteEventsActor.Commands.WriteEvents(10)); | ||
} | ||
|
||
[Benchmark] | ||
public async Task Write100EventsBatched() | ||
{ | ||
var writeEventsActor = _sys!.ActorOf(Props.Create(() => new WriteEventsActor(Guid.NewGuid().ToString()))); | ||
|
||
await writeEventsActor.Ask<WriteEventsActor.Responses.WriteEventsResponse>( | ||
new WriteEventsActor.Commands.WriteEvents(100)); | ||
} | ||
|
||
private class WriteEventsActor : ReceivePersistentActor | ||
{ | ||
public static class Commands | ||
{ | ||
public record WriteEvents(int NumberOfEvents); | ||
} | ||
|
||
public static class Responses | ||
{ | ||
public record WriteEventsResponse; | ||
} | ||
|
||
public override string PersistenceId { get; } | ||
|
||
public WriteEventsActor(string id) | ||
{ | ||
PersistenceId = id; | ||
|
||
Command<Commands.WriteEvents>(cmd => | ||
{ | ||
var events = Enumerable.Range(1, cmd.NumberOfEvents).Select(_ => Guid.NewGuid()); | ||
|
||
PersistAll(events, _ => { }); | ||
|
||
DeferAsync("done", _ => | ||
{ | ||
Sender.Tell(new Responses.WriteEventsResponse()); | ||
}); | ||
}); | ||
} | ||
} | ||
} |
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,24 @@ | ||
using Akka.Persistence.Journal; | ||
|
||
namespace Akka.Persistence.EventStore.Benchmarks; | ||
|
||
public sealed class EventTagger : IWriteEventAdapter | ||
{ | ||
public string Manifest(object evt) => string.Empty; | ||
|
||
public object ToJournal(object evt) | ||
{ | ||
if (evt is not int i) | ||
return evt; | ||
|
||
return i switch | ||
{ | ||
<= Const.TagLowerBound => evt, | ||
<= Const.Tag10UpperBound => new Tagged(evt, new[] { Const.Tag10, Const.Tag100, Const.Tag1000, Const.Tag10000 }), | ||
<= Const.Tag100UpperBound => new Tagged(evt, new[] { Const.Tag100, Const.Tag1000, Const.Tag10000 }), | ||
<= Const.Tag1000UpperBound => new Tagged(evt, new[] { Const.Tag1000, Const.Tag10000 }), | ||
<= Const.Tag10000UpperBound => new Tagged(evt, new[] { Const.Tag10000 }), | ||
_ => evt, | ||
}; | ||
} | ||
} |
Oops, something went wrong.