-
Notifications
You must be signed in to change notification settings - Fork 6
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
perf(sn): reuse buffer for ReplicateRequest unmarshaling #808
Open
ijsong
wants to merge
1
commit into
main
Choose a base branch
from
replicate_rpc_improvement
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
This file contains 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
ijsong
force-pushed
the
replicate_rpc_improvement
branch
from
June 8, 2024 14:32
d5f5e27
to
0e0a36e
Compare
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #808 +/- ##
==========================================
+ Coverage 68.09% 68.44% +0.35%
==========================================
Files 182 182
Lines 17899 17903 +4
==========================================
+ Hits 12188 12254 +66
+ Misses 4941 4863 -78
- Partials 770 786 +16 ☔ View full report in Codecov by Sentry. |
ijsong
force-pushed
the
replicate_rpc_improvement
branch
from
June 8, 2024 15:16
18c6632
to
770f7ef
Compare
hungryjang
reviewed
Jun 10, 2024
ijsong
force-pushed
the
replicate_rpc_improvement
branch
2 times, most recently
from
June 13, 2024 15:18
3060aa5
to
122afa5
Compare
ijsong
force-pushed
the
replicate_rpc_improvement
branch
2 times, most recently
from
June 14, 2024 12:34
6feab12
to
57f4a1a
Compare
ijsong
force-pushed
the
replicate_rpc_improvement
branch
from
June 15, 2024 06:57
57f4a1a
to
60a1a53
Compare
Improve unmarshaling performance by reusing buffers for ReplicateRequest in the backup replica. The protobuf message `github.com/kakao/varlog/proto/snpb.(ReplicateRequest)` has two slice fields—LLSN (`[]uint64`) and Data (`[][]byte`). The backup replica receives replicated log entries from the primary replica via the gRPC service `github.com/kakao/varlog/proto/snpb.(ReplicatorServer).Replicate`, which sends `ReplicateRequest` messages. Upon receiving a `ReplicateRequest`, the backup replica unmarshals the message, which involves growing slices for fields such as LLSN and Data. This growth causes copy overhead whenever the slice capacities need to expand. To address this, we introduce a new method, `ResetReuse`, for reusing slices instead of resetting them completely. The `ResetReuse` method shrinks the slice lengths while preserving their capacities, thus avoiding the overhead of reallocating memory. Example implementation: ```go type Message struct { Buffer []byte // Other fields } func (m *Message) Reset() { *m = Message{} } func (m *Message) ResetReuse() { s := m.Buffer[:0] *m = Message{} m.Buffer = s } ``` Risks: This approach has potential downsides. Since the heap space consumed by the slices is not reclaimed, the storage node's memory consumption may increase. Currently, there is no mechanism to shrink the heap usage. Additionally, this PR changes the generated code. The protobuf compiler can revert it, which is contrary to our intention. To catch this mistake, this PR includes a unit test (github.com/kakao/varlog/proto/snpb.TestReplicateRequest) to verify that the buffer backing the slices is reused. Resolves: #795 See also: #806
ijsong
force-pushed
the
replicate_rpc_improvement
branch
from
June 16, 2024 07:22
60a1a53
to
8ef1886
Compare
3 tasks
hungryjang
approved these changes
Jul 29, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What this PR does
Improve unmarshaling performance by reusing buffers for ReplicateRequest in the
backup replica.
The protobuf message
github.com/kakao/varlog/proto/snpb.(ReplicateRequest)
hastwo slice fields—LLSN (
[]uint64
) and Data ([][]byte
). The backup replicareceives replicated log entries from the primary replica via the gRPC service
github.com/kakao/varlog/proto/snpb.(ReplicatorServer).Replicate
, which sendsReplicateRequest
messages.Upon receiving a
ReplicateRequest
, the backup replica unmarshals the message,which involves growing slices for fields such as LLSN and Data. This growth
causes copy overhead whenever the slice capacities need to expand.
To address this, we introduce a new method,
ResetReuse
, for reusing slicesinstead of resetting them completely. The
ResetReuse
method shrinks the slicelengths while preserving their capacities, thus avoiding the overhead of
reallocating memory.
Example implementation:
Risks:
This approach has potential downsides. Since the heap space consumed by the
slices is not reclaimed, the storage node's memory consumption may increase.
Currently, there is no mechanism to shrink the heap usage.
Additionally, this PR changes the generated code. The protobuf compiler can
revert it, which is contrary to our intention. To catch this mistake, this PR
includes a unit test (github.com/kakao/varlog/proto/snpb.TestReplicateRequest)
to verify that the buffer backing the slices is reused.
Which issue(s) this PR resolves
Resolves: #795
See also: #806