Skip to content

Commit

Permalink
Optimize consumer messages sequences for multiple subjects (#4129)
Browse files Browse the repository at this point in the history
If consumer with multiple subjects encountered a sequnece of messages in
a row from the same subject, it tried to load messages from other
subjects in some cases.
This checks for that scenario and optimizes it by early returning.

I added a temporary instrumentation to check for how many times fetching
new messages is called, and it seems that it cuts those calls according
to assumptions. Though it being internal, it's really hard to show that
in test.

Signed-off-by: Tomasz Pietrek <tomasz@nats.io>
  • Loading branch information
Jarema committed May 4, 2023
2 parents 9fa724c + 7c1c4ea commit 69fb3db
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions server/consumer.go
Expand Up @@ -3295,6 +3295,11 @@ func (o *consumer) getNextMsg() (*jsPubMsg, uint64, error) {
o.updateSkipped(uint64(filter.currentSeq))
}
}

// If we're sure that this filter has continuous sequence of messages, skip looking up other filters.
if nextSeq == sseq && err != ErrStoreEOF {
break
}
}

}
Expand Down

0 comments on commit 69fb3db

Please sign in to comment.