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

Improve bus for large numbers of similar subscriptions #27

Closed
wants to merge 3 commits into from

Conversation

Ulexus
Copy link
Member

@Ulexus Ulexus commented Mar 18, 2020

Previously, we created a new NATS subscription for each ARI
subscription, which is inefficient for large numbers of similar
subscriptions. (See Issue #26)

With this change, we now retain a single NATS subscription for any
number of ari subscriptions for which the same NATS subscription is
sufficient, regardless of where in the tree of ARI clients it may be.

To do this, we create a root-level (core) back-to-back event bus, with
the NATS subscription being bound to a stdbus ARI bus. All ari-proxy
clients subtend a new SubBus, which forwards all requests on to the core
ARI bus, registering them along the way. When the SubBus is closed, the
bound subscriptions will be closed, but the root-level bus itself will
stay in existence.

There is a remaining issue wherein long-running root-level ari-proxy
clients will accumulate NATS subscriptions and not have them terminate
even after all SubBuses are closed. This will need to be fixed in a
later patch, but it should not affect most uses, for now.

Fixes #26


This change is Reviewable

Ulexus added 2 commits March 18, 2020 15:46
Previously, we created a new NATS subscription for each ARI
subscription, which is inefficient for large numbers of similar
subscriptions.  (See Issue #26)

With this change, we now retain a single NATS subscription for any
number of ari subscriptions for which the same NATS subscription is
sufficient, regardless of where in the tree of ARI clients it may be.

To do this, we create a root-level (core) back-to-back event bus, with
the NATS subscription being bound to a stdbus ARI bus.  All ari-proxy
clients subtend a new SubBus, which forwards all requests on to the core
ARI bus, registering them along the way.  When the SubBus is closed, the
bound subscriptions will be closed, but the root-level bus itself will
stay in existence.

There is a remaining issue wherein long-running root-level ari-proxy
clients will accumulate NATS subscriptions and not have them terminate
even after all SubBuses are closed.  This will need to be fixed in a
later patch, but it should not affect most uses, for now.

Fixes #26
s.mu.RLock()
if !s.closed {
s.eventChan <- e
b.log.Error("failed to create bus wrapper", "key", key, "error", err)
Copy link
Contributor

Choose a reason for hiding this comment

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

You should unlock here before return?

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed; thanks

@Ulexus Ulexus deleted the branch master September 5, 2023 14:10
@Ulexus Ulexus closed this Sep 5, 2023
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.

Best practice regarding subscriptions
2 participants