-
Notifications
You must be signed in to change notification settings - Fork 1
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
1decda7
commit c817835
Showing
5 changed files
with
119 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 |
---|---|---|
@@ -0,0 +1,76 @@ | ||
using BenchmarkDotNet.Attributes; | ||
using Fluss; | ||
using Fluss.Authentication; | ||
using Fluss.Events; | ||
using Fluss.ReadModel; | ||
using Microsoft.Extensions.DependencyInjection; | ||
|
||
namespace Benchmark; | ||
|
||
[SimpleJob] | ||
[MemoryDiagnoser] | ||
public class Bench | ||
{ | ||
[IterationSetup] | ||
public void Setup() | ||
{ | ||
var sc = new ServiceCollection(); | ||
sc.AddEventSourcing(); | ||
sc.AddPoliciesFrom(typeof(Bench).Assembly); | ||
|
||
_sp = sc.BuildServiceProvider(); | ||
} | ||
|
||
ServiceProvider _sp = null!; | ||
|
||
[Benchmark] | ||
public async Task<int> PublishEventsAndRead() | ||
{ | ||
var sum = 0; | ||
for (var j = 0; j < 1000; j++) | ||
{ | ||
await _sp.GetSystemUserUnitOfWorkFactory().Commit(async unitOfWork => { | ||
for (var i = 0; i < 50; i++) | ||
{ | ||
await unitOfWork.Publish(new TestEvent(1)); | ||
await unitOfWork.Publish(new TestEvent(2)); | ||
} | ||
}); | ||
|
||
var unitOfWork = _sp.GetSystemUserUnitOfWork(); | ||
var readModel1 = await unitOfWork.GetReadModel<TestReadModel, int>(1); | ||
var readModel2 = await unitOfWork.GetReadModel<TestReadModel, int>(2); | ||
sum += readModel1.GotEvents + readModel2.GotEvents; | ||
} | ||
|
||
return sum; | ||
} | ||
} | ||
|
||
public class AllowAllPolicy : Policy { | ||
public ValueTask<bool> AuthenticateEvent(EventEnvelope envelope, IAuthContext authContext) | ||
{ | ||
return ValueTask.FromResult(true); | ||
} | ||
|
||
public ValueTask<bool> AuthenticateReadModel(IReadModel readModel, IAuthContext authContext) | ||
{ | ||
return ValueTask.FromResult(true); | ||
} | ||
} | ||
|
||
public record TestEvent(int Id) : Event; | ||
|
||
public record TestReadModel : ReadModelWithKey<int> | ||
{ | ||
public int GotEvents { get; private init; } | ||
|
||
protected override TestReadModel When(EventEnvelope envelope) | ||
{ | ||
return envelope.Event switch | ||
{ | ||
TestEvent testEvent when testEvent.Id == Id => this with { GotEvents = GotEvents + 1 }, | ||
_ => this, | ||
}; | ||
} | ||
} |
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,19 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="BenchmarkDotNet" Version="0.14.0" /> | ||
<PackageReference Include="Enterprize1.BenchmarkDotNet.GitCompare" Version="0.0.1" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\Fluss\Fluss.csproj" /> | ||
</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,4 @@ | ||
using Benchmark; | ||
using BenchmarkDotNet.Running; | ||
|
||
BenchmarkRunner.Run<Bench>(); |
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