Skip to content

Conversation

Arkatufus
Copy link
Contributor

@Arkatufus Arkatufus commented May 13, 2025

Changes

Modernize DistributedPubSub code

  • Make DistributedPubSubMediator use IWithTimers instead of using the scheduler
  • Make TopicLike (base class for Topic and Group) use IWithTimers instead of using the scheduler
  • Use pattern matching
  • Use deconstructor
  • Make static codes inlined

Checklist

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

Latest dev Benchmarks

OSVersion: Microsoft Windows NT 6.2.9200.0
ProcessorCount: 24
ClockSpeed: 0 MHZ
Actor Count: 48
Messages sent/received per client: 200000 (2e5)
Is Server GC: True
Thread count: 52

Num clients Total [msg] Msgs/sec Total [ms] Start Threads End Threads
1 200000 626960 319.91 52 60
5 1000000 624610 1601.04 65 78
10 2000000 619579 3228.24 82 83
15 3000000 605694 4953.33 87 115
20 4000000 612839 6527.07 119 110
25 5000000 588028 8503.92 115 108
30 6000000 606797 9888.46 112 108

This PR's Benchmarks

OSVersion: Microsoft Windows NT 6.2.9200.0
ProcessorCount: 24
ClockSpeed: 0 MHZ
Actor Count: 48
Messages sent/received per client: 200000 (2e5)
Is Server GC: True
Thread count: 55

Num clients Total [msg] Msgs/sec Total [ms] Start Threads End Threads
1 200000 892858 224.80 55 64
5 1000000 716333 1396.07 69 78
10 2000000 685401 2918.60 82 82
15 3000000 628536 4773.54 86 97
20 4000000 615385 6500.14 101 96
25 5000000 643916 7765.54 97 93
30 6000000 610005 9836.05 93 112

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.

Overall looks good but I left you some more perf feedback on the gossip side of things.

throw new ArgumentException($"The cluster member [{_cluster.SelfAddress}] doesn't have the role [{_settings.Role}]");

//Start periodic gossip to random nodes in cluster
_gossipCancelable = Context.System.Scheduler.ScheduleTellRepeatedlyCancelable(_settings.GossipInterval, _settings.GossipInterval, Self, GossipTick.Instance, Self);
Copy link
Member

Choose a reason for hiding this comment

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

LGTM (should probably keep the comment though)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the comment was moved to the PreStart() override where we start the periodic timer

{
var nodes = state.Members
.Where(m => m.Status != MemberStatus.Joining && IsMatchingRole(m))
.Where(m => m.Status != MemberStatus.Joining && IsMatchingRole(m, _role))
Copy link
Member

Choose a reason for hiding this comment

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

Was this a bug before?

Copy link
Contributor Author

@Arkatufus Arkatufus May 14, 2025

Choose a reason for hiding this comment

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

No, it wasn't a bug. We access the _settings.Role property inside the IsMatchingRole method before, now it is a static method

Copy link
Member

Choose a reason for hiding this comment

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

Got it

private void HandleGossip()
{
var node = SelectRandomNode(_nodes.Except(new[] { _cluster.SelfAddress }).ToArray());
var node = SelectRandomNode(_nodes.Except([_cluster.SelfAddress]).ToArray());
Copy link
Member

Choose a reason for hiding this comment

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

You might be able to make this work without allocating a list - have SelectRandomNode take an IEnumerable and just apply the random value to .Skip instead of the indexer

Copy link
Member

Choose a reason for hiding this comment

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

That'll also save you the trouble of fully evaluating the list

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll give that a try

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 - we decided that the gossip optimization wasn't worth the complexity it introduces

@Aaronontheweb Aaronontheweb merged commit 1e0ca6b into akkadotnet:dev May 14, 2025
11 checks passed
@Arkatufus Arkatufus added this to the 1.5.42 milestone May 21, 2025
This was referenced Oct 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants