Repository navigation
netty: create adaptive cumulator - #7532
Merged
Merged
Conversation
sergiitk
force-pushed
the
netty-adaptive-cumulator
branch
from
October 19, 2020 16:15
860ee7f to
0be7b25
Compare
sergiitk
force-pushed
the
netty-adaptive-cumulator
branch
from
October 19, 2020 16:30
0be7b25 to
218f772
Compare
sergiitk
marked this pull request as ready for review
October 19, 2020 16:31
Member
|
FYI @Scottmitch @njhill . Note that this opens up opportunities for larger frame sizes. We would be interested to getting this into Netty, but we were going to be trying things out first. |
|
This sounds interesting... keep us posted |
ejona86
approved these changes
Nov 2, 2020
ejona86
reviewed
Nov 10, 2020
ejona86
approved these changes
Nov 17, 2020
| }; | ||
|
|
||
| // Throws an error on adding incoming buffer. | ||
| throwingCumulator = new NettyAdaptiveCumulator(0) { |
Member
There was a problem hiding this comment.
nit: normally this sort of thing we'd just do inline at the declaration and not in the @Before. This is fine though.
Member
Author
There was a problem hiding this comment.
I'll get it fixed separately to not delay this.
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
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Creates "Adaptive" cumulator: cumulate ByteBuf's by dynamically switching between merge and compose strategies.
This cumulator applies a heuristic to make a decision whether to track a reference to the buffer with bytes received from the network stack in an array ("zero-copy"), or to merge into the last component (the tail) by performing a memory copy.
It is necessary as a protection from a potential attack on the COMPOSITE_CUMULATOR. Consider a pathological case when an attacker sends TCP packages containing a single byte of data, and forcing the cumulator to track each one in a separate buffer. In this case we'll be paying a memory overhead for each buffer, as well as extra compute to read the cumulation.
Implemented heuristic establishes a minimal threshold for the total size of the tail and incoming buffer, below which they are merged. The sum of the tail and the incoming buffer is used to avoid a case where attacker alternates the size of data packets to trick the cumulator into always selecting compose strategy.
Merging strategy attempts to minimize unnecessary memory writes. When possible, it expands the tail capacity and only copies the incoming buffer into available memory. Otherwise, when both tail and the buffer must be copied, the tail is reallocated (or fully replaced) with a new buffer of exponentially increasing capacity (bounded to minComposeSize) to ensure runtime O(n^2) amortized to O(n).