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 #9558 · grpc/grpc-java

Conversation

@sergiitk

@sergiitk sergiitk commented Sep 21, 2022 •
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).

Note: this reintroduces #7532, addressing the subtle issue (ref b/155940949) with CompositeByteBuf.component() indexes getting out of sync, which results in the merge operation producing broken buffers.

Sorry, something went wrong.

Uh oh!

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

All reactions
@sergiitk
netty: create adaptive cumulator
64043e7
@sergiitk
sergiitk force-pushed the netty-adaptive-cumulator-redo-4 branch from ac6beff to 47a89ed Compare September 21, 2022 17:42
sergiitk added 2 commits September 21, 2022 10:45
@sergiitk
netty: document adaptive cumulator tests, add corner cases
888e536
@sergiitk
make ADAPTIVE_CUMULATOR static
75ea060
@sergiitk
sergiitk force-pushed the netty-adaptive-cumulator-redo-4 branch from 47a89ed to 0bdaa6f Compare September 21, 2022 17:48
@sergiitk
NettyAdaptiveCumulator lint: disambiguate variable names, add docs
c0afb4e
@sergiitk
sergiitk force-pushed the netty-adaptive-cumulator-redo-4 branch 3 times, most recently from 04c60b7 to 528f823 Compare September 21, 2022 18:04
@sergiitk
Test and fix the issue with CompositeByteBuf.component() indexes
30d014e
@sergiitk
sergiitk force-pushed the netty-adaptive-cumulator-redo-4 branch from 528f823 to 30d014e Compare September 21, 2022 18:05
@sergiitk
sergiitk marked this pull request as ready for review September 21, 2022 20:15
@sergiitk
sergiitk requested a review from ejona86 September 21, 2022 20:15
ejona86
ejona86 approved these changes Sep 21, 2022
View reviewed changes
Comment thread netty/src/main/java/io/grpc/netty/GrpcHttp2ConnectionHandler.java Resolved

Uh oh!

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

@sergiitk sergiitk changed the title netty: create adaptive cumulator (redo attempt 4) netty: Create adaptive cumulator Sep 27, 2022
@sergiitk sergiitk changed the title netty: Create adaptive cumulator netty: create adaptive cumulator Sep 27, 2022
This was referenced Sep 27, 2022
netty: create adaptive cumulator (redo) #8241
Closed
netty: create adaptive cumulator (redo attempt 2) #8853
Closed
netty: create adaptive cumulator (redo attempt 3) #9378
Closed
CompositeByteBuf.component() returns ByteBuf duplicates without adjusting the indexes netty/netty#12844
Closed
@sergiitk
Address the feedback, document the index correction trick
11eb4cc
@sergiitk
sergiitk enabled auto-merge (squash) September 28, 2022 01:57
@sergiitk
sergiitk merged commit eaf8b28 into grpc:master Sep 28, 2022
@sergiitk
sergiitk deleted the netty-adaptive-cumulator-redo-4 branch September 28, 2022 17:20
larry-safran pushed a commit to larry-safran/grpc-java that referenced this pull request Oct 6, 2022
@sergiitk @larry-safran
netty: create adaptive cumulator (grpc#9558)
2d48915
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).

Note: this reintroduces grpc#7532, addressing the subtle issue (ref b/155940949) with `CompositeByteBuf.component()` indexes getting out of sync, which results in the merge operation producing broken buffers.
@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Dec 28, 2022
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.

2 participants

@sergiitk @ejona86
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.