Skip to content

Add ability to observe the number of connections halibut opens for ea… - #717

Draft
pawelpabich wants to merge 4 commits into
mainfrom
pawel/halibut-per-sub-conns
Draft

Add ability to observe the number of connections halibut opens for ea…#717
pawelpabich wants to merge 4 commits into
mainfrom
pawel/halibut-per-sub-conns

Conversation

@pawelpabich

@pawelpabich pawelpabich commented Aug 17, 2026

Copy link
Copy Markdown

await IdentifyAsServerAsync(identity, cancellationToken);
await ProcessClientRequestsAsync(incomingRequestProcessor, cancellationToken);
break;
case RemoteIdentityType.Subscriber:

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I've moved the connection limit enforcement closer to the code that it applies to.

  1. There is no need to perform work for other types of remote identities
  2. We were executing IdentifyAsServerAsync even for the default switch case, which results in an exception. This shows how easy it is to make a mistake if code that is case-specific is applied to all cases.

/// <param name="currentCount">
/// The number of active TCP connections for this subscriptionId immediately after the change
/// </param>
public void ConnectionsCountChangedFor(Uri subscriptionId, int previousCount, int currentCount);

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I considrerd a pair of ConnectionOpendFor and ConnectionClosedFor methods but then we would keep yet another copy of <SubscriptionId, int> in the metric producer in the server. This might matter when the Server needs to deal with 20k of tentacles. Thoughts?

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.

Make it simpler for the caller is probably the best approach.

readonly HalibutTimeoutsAndLimits timeoutsAndLimits;
readonly IConnectionsObserver connectionsObserver;

Dictionary<Uri, StrongBox<int>> activeConnectionCountPerSubscriptionId = new();

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.

This looks like the information you want.

Maybe have a method that will give you back a copy of this dictionary upon request.


count.Value++;

connectionsObserver.ConnectionsCountChangedFor(subscriptionId, previousCount, count.Value);

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.

I guess this means we need to be super careful about what ConnectionsCountChangedFor does since slow code here will impact ALL connecting tentacles one after the other.

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