Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[IMPROVED] Reduce allocations in writeMsgRecord #6576

Merged
merged 1 commit into from
Feb 25, 2025

Conversation

neilalexander
Copy link
Member

@neilalexander neilalexander commented Feb 24, 2025

The following changes are all to reduce GC pressure:

  • The hdr array looked like it should be stack-allocated but was actually always escaping to the heap because of the highwayhash writer, so instead of allocating a ton of those, just preallocate space on the underlying cache buffer instead (since that has already escaped to the heap);
  • Reuse the memory of the last checksum instead of allocating unnecessarily there too, and use stringToBytes for the subject, avoiding a further copy.

Signed-off-by: Neil Twigg neil@nats.io

@neilalexander neilalexander requested a review from a team as a code owner February 24, 2025 17:49
Copy link
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

@neilalexander
Copy link
Member Author

Looks like TestJetStreamClusterConsumerLeak is unhappy with this change, although the amount seems to vary quite a bit (appears to vary with how much RAM the system has — the result is much worse on my 128GB RAM machine than it is in the 32GB CI worker, but fails either way).

Signed-off-by: Neil Twigg <neil@nats.io>
@neilalexander neilalexander changed the title Use block pools for write-through caches, reduce allocations in writeMsgRecord Reduce allocations in writeMsgRecord Feb 24, 2025
@neilalexander
Copy link
Member Author

I've backed out one of the changes as I think it may change baseline memory usage and I want to spend more time on that one before committing to it.

@derekcollison
Copy link
Member

ok let's keep watching and testing. The pools work but can cause memory growth quite quickly in this situation vs what was there before.

@derekcollison derekcollison self-requested a review February 24, 2025 19:36
@neilalexander
Copy link
Member Author

Indeed, the other remaining changes in this PR will still reduce allocations and GC pressure in the meantime.

Copy link
Member

@wallyqs wallyqs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@wallyqs wallyqs changed the title Reduce allocations in writeMsgRecord [IMPROVED] Reduce allocations in writeMsgRecord Feb 24, 2025
Copy link
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 8d438fe into main Feb 25, 2025
5 checks passed
@derekcollison derekcollison deleted the neil/writecachepool branch February 25, 2025 13:04
neilalexander added a commit that referenced this pull request Feb 25, 2025
Includes the following:

- #6574
- #6568
- #6575
- #6576

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

3 participants