Skip to content

Only encode & send advisories when there is interest#6341

Merged
derekcollison merged 1 commit intomainfrom
neil/advisoryinterest
Jan 8, 2025
Merged

Only encode & send advisories when there is interest#6341
derekcollison merged 1 commit intomainfrom
neil/advisoryinterest

Conversation

@neilalexander
Copy link
Copy Markdown
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 neil@nats.io

@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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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.

Domain: o.srv.getOpts().JetStreamDomain,
}

j, err := json.Marshal(e)
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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?

Signed-off-by: Neil Twigg <neil@nats.io>
Copy link
Copy Markdown
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
@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