-
Notifications
You must be signed in to change notification settings - Fork 0
perf(persistence): coalesce each AOF group-commit batch into one write #242
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚀 Performance & Scalability | 🟠 Major | 🏗️ Heavy lift
Per-batch heap allocation on the AOF write hot path.
The multi-message branch allocates a fresh
Vec::with_capacity(total)on everycommit_group_commit_batchcall, with no reuse across batches. This is the same I/O-driver hot path that the PerShard writer inwriter_task.rswas specifically reworked to use a reusable, cappedbatch_buffor (seewriter_task.rslines 1440-1442, 1516-1559) — this coalescing path lacks the equivalent optimization, allocating and dropping a new buffer per batch instead of reusing one across the writer's lifetime.Consider threading a caller-owned scratch buffer into
commit_group_commit_batch(mirroring thebatch_bufpattern already established for PerShard), so the TopLevel writer loop inwriter_task.rsalso amortizes this allocation the same way.As per coding guidelines,
src/**/*.rs: "Avoid hot-path allocations in command dispatch, protocol parsing, shard event loops, and I/O drivers: noBox::new(),Vec::new(),String::new(),Arc::new(),clone(),format!(), orto_string()in those paths; prefer preallocated buffers,SmallVec,itoa,write!, or borrowing."♻️ Sketch of a reusable-buffer signature change
pub fn commit_group_commit_batch<S: GroupCommitSink + ?Sized>( sink: &mut S, batch: &mut GroupCommitBatch, do_fsync: bool, + scratch: &mut Vec<u8>, ) -> CommitOutcome { match batch.data.len() { 0 => {} 1 => { if sink.write_all(msg_body(&batch.data[0])).is_err() { return ack_batch(batch, BatchAck::WriteFailed); } } _ => { - let total: usize = batch.data.iter().map(|m| msg_body(m).len()).sum(); - let mut buf = Vec::with_capacity(total); + scratch.clear(); for msg in &batch.data { - buf.extend_from_slice(msg_body(msg)); + scratch.extend_from_slice(msg_body(msg)); } - if sink.write_all(&buf).is_err() { + if sink.write_all(scratch).is_err() { return ack_batch(batch, BatchAck::WriteFailed); } + if scratch.capacity() > 1 << 20 { + *scratch = Vec::new(); + } } } ...🤖 Prompt for AI Agents
Source: Coding guidelines