(2.14) [IMPROVED] JetStream header indexing #7454
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When ingesting messages into a JetStream stream, the speed becomes limited if headers are set on a message due to needing to do all header checks. These header checks currently continuously re-scan the headers for different keys, instead of indexing these headers once and then being able to fetch the values quickly.
This PR proposes an improvement by indexing the headers once and using that throughout for stream ingest. Using an async publish benchmark with the only header of
k: v(just to contain headers and require the server to scan even if the server doesn't need to act on them), for both R1 and R3 there's a performance improvement between 12-26%. Using a R1 withPersistMode: async(async flush) even shows a performance improvement of ~39% (915k msgs/s -> 1.3M msgs/s).The current implementation of a pointer to
jsHdrIndex, the usage ofsync.Pooland referencing[]bytewas benchmarked and came out as the most performant when compared with amapto a range or[]byte, without returning a pointer, and when returning a range intohdrinstead of[]byte.Signed-off-by: Maurice van Veen [email protected]