Only encode & send advisories when there is interest#6341
Conversation
ba52614 to
0f7032f
Compare
server/consumer.go
Outdated
| o.acc.mu.RLock() | ||
| sl := o.acc.sl | ||
| o.acc.mu.RUnlock() | ||
| if !sl.HasInterest(subject) && !o.srv.hasGatewayInterest(o.acc.Name, subject) { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Maybe not too bad check each time..
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
I think I did this here on purpose..
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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>
0f7032f to
48c3c47
Compare
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