Skip to content

Commit

Permalink
[FIXED] When moving to direct addServiceImport, saw performance degra…
Browse files Browse the repository at this point in the history
…dation. (#5026)

Needed to explicitly set "to" to avoid extra work.

Caused performance hit on KV Get performance tests. Never released, so
internal.

Signed-off-by: Derek Collison <derek@nats.io>
  • Loading branch information
derekcollison committed Feb 1, 2024
2 parents 9aed117 + e841c03 commit 6e222a7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
9 changes: 7 additions & 2 deletions server/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -4089,6 +4089,12 @@ func getHeader(key string, hdr []byte) []byte {
return value
}

// For bytes.HasPrefix below.
var (
jsRequestNextPreB = []byte(jsRequestNextPre)
jsDirectGetPreB = []byte(jsDirectGetPre)
)

// processServiceImport is an internal callback when a subscription matches an imported service
// from another account. This includes response mappings as well.
func (c *client) processServiceImport(si *serviceImport, acc *Account, msg []byte) {
Expand All @@ -4110,8 +4116,7 @@ func (c *client) processServiceImport(si *serviceImport, acc *Account, msg []byt
var checkJS bool
shouldReturn := si.invalid || acc.sl == nil
if !shouldReturn && !isResponse && si.to == jsAllAPI {
subj := bytesToString(c.pa.subject)
if strings.HasPrefix(subj, jsRequestNextPre) || strings.HasPrefix(subj, jsDirectGetPre) {
if bytes.HasPrefix(c.pa.subject, jsDirectGetPreB) || bytes.HasPrefix(c.pa.subject, jsRequestNextPreB) {
checkJS = true
}
}
Expand Down
3 changes: 2 additions & 1 deletion server/jetstream.go
Original file line number Diff line number Diff line change
Expand Up @@ -654,7 +654,8 @@ func (a *Account) enableAllJetStreamServiceImportsAndMappings() error {

if !a.serviceImportExists(jsAllAPI) {
// Capture si so we can turn on implicit sharing with JetStream layer.
si, err := a.addServiceImport(s.SystemAccount(), jsAllAPI, _EMPTY_, nil)
// Make sure to set "to" otherwise will incur performance slow down.
si, err := a.addServiceImport(s.SystemAccount(), jsAllAPI, jsAllAPI, nil)
if err != nil {
return fmt.Errorf("Error setting up jetstream service imports for account: %v", err)
}
Expand Down

0 comments on commit 6e222a7

Please sign in to comment.