Skip to content

Specify the flow control behavior in BinderChannel protocol#258

Merged
sifmelcara merged 8 commits intogrpc:masterfrom
TaWeiTu:binder-transport-flow-control
Sep 27, 2021
Merged

Specify the flow control behavior in BinderChannel protocol#258
sifmelcara merged 8 commits intogrpc:masterfrom
TaWeiTu:binder-transport-flow-control

Conversation

@TaWeiTu
Copy link
Copy Markdown
Contributor

@TaWeiTu TaWeiTu commented Sep 2, 2021

The flow control mechanism is specified in the internal document but was not included in this proposal. Also, both documents didn't contain the description of the flag FLAG_MESSAGE_DATA_IS_PARTIAL, which is crucial when breaking larger message into smaller chunks for flow control purposes.

This PR copies the description of flow control mechanism in the internal document to the proposal, and explicitly introduce FLAG_MESSAGE_DATA_IS_PARTIAL and its usage. Additionally, the num bytes field in ACKNOWLEDGE_BYTES requests should be of type long (64 bits) instead of int (32 bits) judging from the implenmentation.


## Flow Control

BinderTransport now supports flow control, aiming to keep use of the process transaction buffer to at most 128k. Each transaction we send adds to an internal count of unacknowledged outbound data. If that exceeds 128k, we’ll stop sending transactions until we receive an acknowledgement message from the transport peer. Each transport sends an acknowledgement for each 16k received, which should avoid blocking the transport most of the time.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably worth to mention that we want to do this because Android binder implementation has an internal buffer with fixed size?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@sifmelcara sifmelcara changed the title L73: Specify the flow control behavior Specify the flow control behavior in BinderChannel protocol Sep 3, 2021
@sifmelcara
Copy link
Copy Markdown
Contributor

if i understand correctly amendments to accepted proposal should not include number in title and commit message

@sifmelcara sifmelcara requested a review from ejona86 September 6, 2021 04:14
* From either transport to its peer's binder. Reports reception of
transaction data for flow control.
transaction data for flow control. The "num bytes" field should contain
the sum of "data size" of the parcels received until now.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

version = int;
protocol extension flags = int;
num bytes = int;
num bytes = long;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh good catch, sorry about that!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No problem!

included.
* FLAG_MESSAGE_DATA_IS_PARCELABLE (0x40) - Indicates the message is a parcelable
object.
* FLAG_MESSAGE_DATA_IS_PARTIAL (0x80) - Indicates the message is partial and the receiver should continue reading.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Proposed change to make this clearer:
Where a message doesn't fit into a single transaction, the message will be sent in multiple transactions with this bit set on all but the final transaction of the message.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.


## Flow Control

Due to the limited binder buffer size of 1MB, BinderTransport now supports flow control, aiming to keep use of the process transaction buffer to at most 128k. Each transaction we send adds to an internal count of unacknowledged outbound data (here the count refers to the "data size" of the parcels). If that exceeds 128k, we’ll stop sending transactions until we receive an acknowledgement message from the transport peer. Each transport sends an acknowledgement for each 16k received, which should avoid blocking the transport most of the time.
Copy link
Copy Markdown
Contributor

@markb74 markb74 Sep 6, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"now supports flow control" -> "supports transport-level flow control"

The reason I say this is that we still need to support real stream-level flow control separately.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.


Due to the limited binder buffer size of 1MB, BinderTransport now supports flow control, aiming to keep use of the process transaction buffer to at most 128k. Each transaction we send adds to an internal count of unacknowledged outbound data (here the count refers to the "data size" of the parcels). If that exceeds 128k, we’ll stop sending transactions until we receive an acknowledgement message from the transport peer. Each transport sends an acknowledgement for each 16k received, which should avoid blocking the transport most of the time.

For message larger than the flow control window size, the transport can choose to split it into multiple chunks using the FLAG_MESSAGE_DATA_IS_PARTIAL flag.
Copy link
Copy Markdown
Contributor

@markb74 markb74 Sep 6, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's move this paragraph to a section above Flow Control, called "Large Messages".

Message splitting is only indirectly related to flow control, so including this here is kind of "mixing concerns".

You can say that we limit the amount of message data sent in a single transaction to 16k. Messages larger than that will be sent in multiple sequential transactions, with all but the last transaction having FLAG_MESSAGE_DATA_IS_PARTIAL set.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@TaWeiTu TaWeiTu force-pushed the binder-transport-flow-control branch from 2d5b172 to 7bf3001 Compare September 6, 2021 13:04
@sifmelcara
Copy link
Copy Markdown
Contributor

nit: 128k -> 128KB. 16k -> 16KB

@TaWeiTu
Copy link
Copy Markdown
Contributor Author

TaWeiTu commented Sep 6, 2021

nit: 128k -> 128KB. 16k -> 16KB

Done.


## Flow Control

Due to the limited binder buffer size of 1MB, BinderTransport supports
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider: "Due to the limited binder buffer size of 1MB" -> "Due to Android's limited per-process transaction buffer of 1MB"

Adds a bit more context and makes it clear this buffer size is out of our control.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Thanks for the review and suggestions!

@sifmelcara sifmelcara merged commit 4c4a06d into grpc:master Sep 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants