Skip to content

cached ShardIds generated by HashCodeMessageExtractor - #5216

Merged
Aaronontheweb merged 1 commit into
akkadotnet:devfrom
Aaronontheweb:sharding/hashcodemessageextractor-perf
Aug 19, 2021
Merged

Aaronontheweb merged 1 commit into
akkadotnet:devfrom
Aaronontheweb:sharding/hashcodemessageextractor-perf

Conversation

@Aaronontheweb

Copy link
Copy Markdown
Member

Since the number of possible shards is bounded at startup, we can avoid allocating a string each time we route a message by pre-calculating them in the constructor of the HashCodeMessageExtractor.

This improvement reduces all allocations and reduces latency by 50%.

Before

BenchmarkDotNet=v0.13.1, OS=Windows 10.0.19041.1165 (2004/May2020Update/20H1)
AMD Ryzen 7 1700, 1 CPU, 16 logical and 8 physical cores
.NET SDK=5.0.302
  [Host]     : .NET Core 3.1.17 (CoreCLR 4.700.21.31506, CoreFX 4.700.21.31502), X64 RyuJIT
  DefaultJob : .NET Core 3.1.17 (CoreCLR 4.700.21.31506, CoreFX 4.700.21.31502), X64 RyuJIT

Method Mean Error StdDev Median Gen 0 Allocated
RouteShardEnvelope 49.05 ns 0.397 ns 0.372 ns 49.02 ns 0.0076 32 B
RouteTypedMessage 45.76 ns 0.952 ns 1.425 ns 44.86 ns 0.0076 32 B

After

BenchmarkDotNet=v0.13.1, OS=Windows 10.0.19041.1165 (2004/May2020Update/20H1)
AMD Ryzen 7 1700, 1 CPU, 16 logical and 8 physical cores
.NET SDK=5.0.302
  [Host] : .NET Core 3.1.17 (CoreCLR 4.700.21.31506, CoreFX 4.700.21.31502), X64 RyuJIT

Toolchain=InProcessEmitToolchain  
Method Mean Error StdDev Allocated
RouteShardEnvelope 24.05 ns 0.096 ns 0.080 ns -
RouteTypedMessage 28.55 ns 0.171 ns 0.160 ns -

@Aaronontheweb

Copy link
Copy Markdown
Member Author

Doesn't make a huge impact in the aggregate benchmarks, however:

BenchmarkDotNet=v0.13.1, OS=Windows 10.0.19041.1165 (2004/May2020Update/20H1)
AMD Ryzen 7 1700, 1 CPU, 16 logical and 8 physical cores
.NET SDK=5.0.302
  [Host]     : .NET Core 3.1.17 (CoreCLR 4.700.21.31506, CoreFX 4.700.21.31502), X64 RyuJIT
  Job-MBAVSR : .NET Core 3.1.17 (CoreCLR 4.700.21.31506, CoreFX 4.700.21.31502), X64 RyuJIT

InvocationCount=1  UnrollFactor=1  
Method StateMode MsgCount Mean Error StdDev
SingleRequestResponseToLocalEntity Persistence 10000 115.776 ms 2.2927 ms 4.6834 ms
StreamingToLocalEntity Persistence 10000 4.884 ms 0.2643 ms 0.7191 ms
SingleRequestResponseToRemoteEntity Persistence 10000 4,199.020 ms 30.7013 ms 27.2159 ms
StreamingToRemoteEntity Persistence 10000 505.833 ms 10.0748 ms 14.7676 ms
SingleRequestResponseToLocalEntity DData 10000 113.480 ms 2.2588 ms 4.7645 ms
StreamingToLocalEntity DData 10000 4.785 ms 0.3805 ms 1.0918 ms
SingleRequestResponseToRemoteEntity DData 10000 4,189.848 ms 78.5903 ms 80.7064 ms
StreamingToRemoteEntity DData 10000 499.897 ms 8.4260 ms 7.4695 ms

@Arkatufus Arkatufus left a comment

Copy link
Copy Markdown
Contributor

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) August 19, 2021 18:58
@Aaronontheweb
Aaronontheweb merged commit e38295b into akkadotnet:dev Aug 19, 2021
@Aaronontheweb
Aaronontheweb deleted the sharding/hashcodemessageextractor-perf branch August 19, 2021 19:34
@Aaronontheweb

Copy link
Copy Markdown
Member Author

Part of #5203

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.

2 participants