-
Notifications
You must be signed in to change notification settings - Fork 15.1k
KAFKA-10684; Avoid additional envelope copies during network transmission #9563
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
Show all changes
10 commits
Select commit
Hold shift + click to select a range
d6212fa
KAFKA-10684; Avoid additional envelope copies during network transmis…
hachikuji 3da0bfb
Generalize `SendBuilder` usage to apply to all generated types
hachikuji ef4723e
Add test cases for a couple buffer offset bugs
hachikuji a471979
Fix checkstyle and bug in data generator
hachikuji 2f25bf1
Add `SendBuilderTest` and remove unneeded classes
hachikuji 749a679
Use accumulator pattern for `MessageSize`
hachikuji 8f83f0f
Rename `MessageSize` to `MessageAccumulator`
hachikuji c1978e1
Set `_sizeBeforeBytes` only for tagged fields
hachikuji 84e0fa2
Create `_sizeBeforeArray` only when needed
hachikuji ec0a079
Remove TODO in `MessageDataGenerator`
hachikuji 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
60 changes: 60 additions & 0 deletions
60
clients/src/main/java/org/apache/kafka/common/protocol/MessageSizeAccumulator.java
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package org.apache.kafka.common.protocol; | ||
|
|
||
| /** | ||
| * Helper class which facilitates zero-copy network transmission. See {@link SendBuilder}. | ||
| */ | ||
| public class MessageSizeAccumulator { | ||
| private int totalSize = 0; | ||
| private int zeroCopySize = 0; | ||
|
|
||
| /** | ||
| * Get the total size of the message. | ||
| * | ||
| * @return total size in bytes | ||
| */ | ||
| public int totalSize() { | ||
| return totalSize; | ||
| } | ||
|
|
||
| /** | ||
| * Get the total "zero-copy" size of the message. This is the summed | ||
| * total of all fields which have either have a type of 'bytes' with | ||
| * 'zeroCopy' enabled, or a type of 'records' | ||
| * | ||
| * @return total size of zero-copy data in the message | ||
| */ | ||
| public int zeroCopySize() { | ||
| return zeroCopySize; | ||
| } | ||
|
|
||
| public void addZeroCopyBytes(int size) { | ||
| zeroCopySize += size; | ||
| totalSize += size; | ||
| } | ||
|
|
||
| public void addBytes(int size) { | ||
| totalSize += size; | ||
| } | ||
|
|
||
| public void add(MessageSizeAccumulator size) { | ||
| this.totalSize += size.totalSize; | ||
| this.zeroCopySize += size.zeroCopySize; | ||
| } | ||
|
|
||
| } |
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
103 changes: 0 additions & 103 deletions
103
clients/src/main/java/org/apache/kafka/common/protocol/RecordsReadable.java
This file was deleted.
Oops, something went wrong.
149 changes: 0 additions & 149 deletions
149
clients/src/main/java/org/apache/kafka/common/protocol/RecordsWritable.java
This file was deleted.
Oops, something went wrong.
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.
I'm thinking about how to simplify this process.
Could we reuse the method
void write(Writable writable, ObjectSerializationCache cache, short version)? Maybe we can create aWritableinstance but it does not write data to any output. Instead, it calculate the size of buffer according to input data.