Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Akka.Persistence: improve AsyncWriteJournal and PersistentActor performance #6432

Merged
merged 7 commits into from
Feb 22, 2023

Conversation

Aaronontheweb
Copy link
Member

@Aaronontheweb Aaronontheweb commented Feb 22, 2023

Changes

Fixes #5522

@F0b0s has already eliminated a ton of allocations from the journal - I'm addressing some more based on @to11mtm 's feedback.

Checklist

For significant changes, please ensure that the following have been completed (delete if not relevant):

Latest dev Benchmarks

Include data from the relevant benchmark prior to this change here.

This PR's Benchmarks

Include data from after this change here.

@Aaronontheweb
Copy link
Member Author

JournalWriteBenchmarks

dev Benchmarks

BenchmarkDotNet=v0.13.2, OS=Windows 10 (10.0.19044.2604/21H2/November2021Update)
AMD Ryzen 7 1700, 1 CPU, 16 logical and 8 physical cores
.NET SDK=7.0.100
  [Host]     : .NET 7.0.0 (7.0.22.51805), X64 RyuJIT AVX2
  Job-RHZXXN : .NET 7.0.0 (7.0.22.51805), X64 RyuJIT AVX2

InvocationCount=1  UnrollFactor=1  
Method PersistentActors WriteMsgCount Mean Error StdDev Median Gen0 Gen1 Allocated
WriteToPersistence 1 100 489.1 μs 44.12 μs 128.7 μs 508.1 μs - - 145.61 KB
WriteToPersistence 10 100 1,289.8 μs 62.97 μs 175.5 μs 1,279.5 μs - - 1416.34 KB
WriteToPersistence 100 100 30,953.0 μs 943.54 μs 2,722.3 μs 30,163.0 μs 2000.0000 1000.0000 13980.24 KB

This PR

BenchmarkDotNet=v0.13.2, OS=Windows 10 (10.0.19044.2604/21H2/November2021Update)
AMD Ryzen 7 1700, 1 CPU, 16 logical and 8 physical cores
.NET SDK=7.0.100
  [Host]     : .NET 7.0.0 (7.0.22.51805), X64 RyuJIT AVX2
  Job-SDRCEZ : .NET 7.0.0 (7.0.22.51805), X64 RyuJIT AVX2

InvocationCount=1  UnrollFactor=1  
Method PersistentActors WriteMsgCount Mean Error StdDev Median Gen0 Gen1 Allocated
WriteToPersistence 1 100 521.7 μs 45.74 μs 132.0 μs 535.2 μs - - 147.91 KB
WriteToPersistence 10 100 1,754.9 μs 210.71 μs 611.3 μs 1,580.8 μs - - 1411.19 KB
WriteToPersistence 100 100 29,833.8 μs 725.73 μs 2,093.9 μs 29,651.6 μs 2000.0000 1000.0000 13893.84 KB

@Aaronontheweb
Copy link
Member Author

Got rid of the value delegates - that seemed to hurt more than help.

BenchmarkDotNet=v0.13.2, OS=Windows 10 (10.0.19044.2604/21H2/November2021Update)
AMD Ryzen 7 1700, 1 CPU, 16 logical and 8 physical cores
.NET SDK=7.0.100
  [Host]     : .NET 7.0.0 (7.0.22.51805), X64 RyuJIT AVX2
  Job-PWUWVX : .NET 7.0.0 (7.0.22.51805), X64 RyuJIT AVX2

InvocationCount=1  UnrollFactor=1  
Method PersistentActors WriteMsgCount Mean Error StdDev Median Gen0 Gen1 Allocated
WriteToPersistence 1 100 444.4 μs 46.21 μs 134.8 μs 443.2 μs - - 148.09 KB
WriteToPersistence 10 100 1,322.2 μs 102.98 μs 290.5 μs 1,197.5 μs - - 1413.47 KB
WriteToPersistence 100 100 30,274.7 μs 732.28 μs 2,041.3 μs 29,870.2 μs 2000.0000 1000.0000 13956.02 KB

@Aaronontheweb
Copy link
Member Author

Eliminated some additional .ToArray calls that should be unnecessary (unless the Akka.Persistence API contract is wrong, in which case we should require something more robust like IReadOnlyList<T>.)

BenchmarkDotNet=v0.13.2, OS=Windows 10 (10.0.19044.2604/21H2/November2021Update)
AMD Ryzen 7 1700, 1 CPU, 16 logical and 8 physical cores
.NET SDK=7.0.100
  [Host]     : .NET 7.0.0 (7.0.22.51805), X64 RyuJIT AVX2
  Job-AKPKTM : .NET 7.0.0 (7.0.22.51805), X64 RyuJIT AVX2

InvocationCount=1  UnrollFactor=1  
Method PersistentActors WriteMsgCount Mean Error StdDev Median Gen0 Gen1 Allocated
WriteToPersistence 1 100 449.6 μs 48.75 μs 143.0 μs 441.4 μs - - 145.92 KB
WriteToPersistence 10 100 1,262.3 μs 75.83 μs 207.6 μs 1,172.6 μs - - 1383.5 KB
WriteToPersistence 100 100 29,764.8 μs 769.96 μs 2,221.5 μs 29,278.7 μs 2000.0000 1000.0000 13679.48 KB

@Aaronontheweb Aaronontheweb marked this pull request as ready for review February 22, 2023 20:05
@@ -162,26 +168,25 @@ protected override bool AroundReceive(Receive receive, object message)
/// <returns>TBD</returns>
protected override Task<IImmutableList<Exception>> WriteMessagesAsync(IEnumerable<AtomicWrite> messages)
{
var trueMsgs = messages.ToArray();
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

work-around for serialization problems caused by the MNTR Cluster.Sharding specs that use this journal impl.

Copy link
Contributor

@Arkatufus Arkatufus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@Arkatufus Arkatufus enabled auto-merge (squash) February 22, 2023 21:02
@Aaronontheweb Aaronontheweb merged commit 32b832b into akkadotnet:dev Feb 22, 2023
@Aaronontheweb Aaronontheweb deleted the fix-5522-journal-perf branch February 22, 2023 21:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[PERF] Reduce Akka.Persistence.Journal allocations + overhead
2 participants