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

Only encode & send advisories when there is interest #6341

Merged
merged 1 commit into from
Jan 8, 2025

Conversation

neilalexander
Copy link
Member

This stops us from spending time & CPU cycles encoding advisory JSONs when there is no one listening for them.

Signed-off-by: Neil Twigg [email protected]

@neilalexander neilalexander force-pushed the neil/advisoryinterest branch from ba52614 to 0f7032f Compare January 7, 2025 18:31
@neilalexander neilalexander marked this pull request as ready for review January 7, 2025 18:52
@neilalexander neilalexander requested a review from a team as a code owner January 7, 2025 18:52
o.acc.mu.RLock()
sl := o.acc.sl
o.acc.mu.RUnlock()
if !sl.HasInterest(subject) && !o.srv.hasGatewayInterest(o.acc.Name, subject) {
Copy link
Member

Choose a reason for hiding this comment

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

Prefer us to hook updates for this somehow vs checking each time. Also if we know o.acc is not nil, can it go back to nil? Meaning safe to reference without a lock?

Copy link
Member

Choose a reason for hiding this comment

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

Maybe not too bad check each time..

Copy link
Member Author

Choose a reason for hiding this comment

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

I've checked and don't think o.acc can go back to being nil, so I've removed the lock. I don't think the check for interest is expensive enough to worry about for now given that we now have HasInterest which is non-allocating.

@@ -1605,13 +1623,8 @@ func (o *consumer) sendDeleteAdvisoryLocked() {
Domain: o.srv.getOpts().JetStreamDomain,
}

j, err := json.Marshal(e)
Copy link
Member

Choose a reason for hiding this comment

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

I think I did this here on purpose..

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm not sure it matters where the marshaling takes place, but if we can avoid doing it until after the interest check, that saves us some CPU time & allocs.

Copy link
Member

Choose a reason for hiding this comment

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

We should do it after the check for sure. But I need to recall why I put it there? Maybe use more cores?

Copy link
Member

@derekcollison derekcollison left a comment

Choose a reason for hiding this comment

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

LGTM

@derekcollison derekcollison merged commit baf0641 into main Jan 8, 2025
5 checks passed
@derekcollison derekcollison deleted the neil/advisoryinterest branch January 8, 2025 18:19
wallyqs added a commit that referenced this pull request Jan 9, 2025
#### Dependencies
- #6323
- #6324

####  Leafnode
- #6291

#### JetStream
- #6226
- #6235
- #6277
- #6279
- #6283
- #6289
- #6316
- #6317
- #6325
- #6326
- #6335
- #6338
- #6341
- #6344
- #6150
- #6351
- #6355

#### Tests
- #6278
- #6297
- #6300
- #6343
- #6329
- #6330
- #6331
- #6332
- #6334
- #6356
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