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

Fix persistence allocations part 2. #6487

Merged
merged 2 commits into from
Mar 6, 2023

Conversation

F0b0s
Copy link
Contributor

@F0b0s F0b0s commented Mar 5, 2023

Changes

Next optimization of persistence allocation that was started in #5505
Now excessive object allocation was eliminated in Eventsourced class when using linked list. Benchmark shows kinda 10% lower memory usage.

Checklist

Latest dev Benchmarks

BenchmarkDotNet=v0.13.2, OS=macOS Monterey 12.5.1 (21G83) [Darwin 21.6.0]
Apple M1 2.40GHz, 1 CPU, 8 logical and 8 physical cores
.NET SDK=7.0.101
[Host] : .NET 7.0.1 (7.0.122.56804), X64 RyuJIT SSE4.2 DEBUG

Toolchain=InProcessEmitToolchain InvocationCount=1 UnrollFactor=1

Method PersistentActors WriteMsgCount Mean Error StdDev Gen0 Gen1 Allocated
WriteToPersistence 1 100 696.0 us 44.63 us 122.9 us - - 146.88 KB
WriteToPersistence 10 100 1,704.8 us 44.52 us 129.2 us - - 1420.27 KB
WriteToPersistence 100 100 23,525.9 us 458.53 us 657.6 us 2000.0000 1000.0000 13786.62 KB

This PR's Benchmarks

BenchmarkDotNet=v0.13.2, OS=macOS Monterey 12.5.1 (21G83) [Darwin 21.6.0]
Apple M1 2.40GHz, 1 CPU, 8 logical and 8 physical cores
.NET SDK=7.0.101
[Host] : .NET 7.0.1 (7.0.122.56804), X64 RyuJIT SSE4.2 DEBUG

Toolchain=InProcessEmitToolchain InvocationCount=1 UnrollFactor=1

Method PersistentActors WriteMsgCount Mean Error StdDev Median Gen0 Gen1 Allocated
WriteToPersistence 1 100 654.4 us 31.10 us 87.20 us 647.0 us - - 131.8 KB
WriteToPersistence 10 100 1,786.2 us 75.45 us 215.27 us 1,712.7 us - - 1287.63 KB
WriteToPersistence 100 100 23,127.9 us 454.94 us 637.76 us 23,165.5 us 2000.0000 1000.0000 12685.84 KB

@F0b0s F0b0s changed the title Fix persistence allocation part 2. Fix persistence allocations part 2. Mar 5, 2023
public bool Equals(WriteMessages other)
{
if (ReferenceEquals(other, null)) return false;
if (ReferenceEquals(this, other)) return true;

return Equals(ActorInstanceId, other.ActorInstanceId)
return ActorInstanceId == other.ActorInstanceId
Copy link
Member

Choose a reason for hiding this comment

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

good catch

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Rider highligths such cases

Copy link
Member

@Aaronontheweb Aaronontheweb left a comment

Choose a reason for hiding this comment

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

Have a question about changing the order of the stashing invocations on the persistent actors, but otherwise it looks good.

{
_journalBatch.Add(p);
}
_eventBatch = new LinkedList<IPersistentEnvelope>();
_eventBatch.Clear();
Copy link
Member

Choose a reason for hiding this comment

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

Nice catch.

src/core/Akka.Persistence/Eventsourced.cs Show resolved Hide resolved
@@ -341,7 +341,7 @@ private void HandleWriteMessages(WriteMessages message)
*/
var self = Self;
_resequencerCounter += message.Messages.Aggregate(1, (acc, m) => acc + m.Size);
var atomicWriteCount = message.Messages.OfType<AtomicWrite>().Count();
var atomicWriteCount = message.Messages.Count(x => x is AtomicWrite);
Copy link
Member

Choose a reason for hiding this comment

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

LGTM

Copy link
Member

@Aaronontheweb Aaronontheweb left a comment

Choose a reason for hiding this comment

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

LGTM

@Aaronontheweb Aaronontheweb enabled auto-merge (squash) March 6, 2023 15:14
@Aaronontheweb Aaronontheweb merged commit 149cc05 into akkadotnet:dev Mar 6, 2023
@F0b0s F0b0s deleted the fix_persistence_allocation_2 branch May 3, 2023 19:45
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.

3 participants