GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — netty: create adaptive cumulator by sergiitk · Pull Request #7532 · grpc/grpc-java

Conversation

@sergiitk

@sergiitk sergiitk commented Oct 19, 2020 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

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).

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

veblush reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
@sergiitk
sergiitk force-pushed the netty-adaptive-cumulator branch from 860ee7f to 0be7b25 Compare October 19, 2020 16:15
@sergiitk
netty: create adaptive cumulator
218f772
@sergiitk
sergiitk force-pushed the netty-adaptive-cumulator branch from 0be7b25 to 218f772 Compare October 19, 2020 16:30
@sergiitk
sergiitk marked this pull request as ready for review October 19, 2020 16:31
@sergiitk
minor spelling fixes
169c94d
@sergiitk
sergiitk requested a review from ejona86 October 26, 2020 17:05
@ejona86

ejona86 commented Oct 30, 2020

Copy link
Copy Markdown
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.

sergiitk, normanmaurer, njhill, Scottmitch, and veblush reacted with thumbs up emoji
All reactions
  • 👍 5 reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@normanmaurer

normanmaurer commented Oct 31, 2020

Copy link
Copy Markdown

This sounds interesting... keep us posted

sergiitk reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

ejona86
ejona86 approved these changes Nov 2, 2020
View reviewed changes
Comment thread netty/src/main/java/io/grpc/netty/NettyAdaptiveCumulator.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

sergiitk added 2 commits November 9, 2020 22:31
@sergiitk
pooled buffers cleanup safe release
fda5c77
@sergiitk
document unwrap, take care of leak-aware buffers
265b0f6
ejona86
ejona86 reviewed Nov 10, 2020
View reviewed changes
Comment thread netty/src/test/java/io/grpc/netty/NettyTestUtil.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

@sergiitk
Remove unwrap, handle buffer release in tests
0bfa0c3
ejona86
ejona86 approved these changes Nov 17, 2020
View reviewed changes
Comment thread netty/src/test/java/io/grpc/netty/NettyAdaptiveCumulatorTest.java
};

// Throws an error on adding incoming buffer.
throwingCumulator = new NettyAdaptiveCumulator(0) {

@ejona86 ejona86 Nov 17, 2020

Copy link
Copy Markdown
Member

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.

nit: normally this sort of thing we'd just do inline at the declaration and not in the @Before. This is fine though.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

sergiitk reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

@sergiitk sergiitk Nov 17, 2020

Copy link
Copy Markdown
Member Author

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'll get it fixed separately to not delay this.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@sergiitk
sergiitk merged commit 729175c into grpc:master Nov 17, 2020
@sergiitk
sergiitk deleted the netty-adaptive-cumulator branch November 17, 2020 23:05
@sergiitk
sergiitk restored the netty-adaptive-cumulator branch November 18, 2020 20:52
@sergiitk
sergiitk deleted the netty-adaptive-cumulator branch November 18, 2020 20:53
@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Jun 4, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Reviewers

@ejona86 ejona86 ejona86 approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@sergiitk @ejona86 @normanmaurer
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.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.