blenderfreaky
blenderfreaky

Reputation: 768

protobuf-net.Grpc Flow/Congestion Control

I'm working on a program which will asynchronously load large amounts of data from a server via gRPC (both ends use protobuf-net.Grpc).

While I can simply throw large amounts of data at the client via IAsyncEnumerable, I sometimes want to prioritize sending certain parts earlier (where the priorities are determined on the fly, and not know at the start, kind of like sending a video stream and skipping ahead).

If I were to send data and wait for a response every time I'd be leaving a lot of bandwidth unused. The alternative would be throwing tons of data at the client, which could cause network congestion and delay prioritized packets by an indefinite amount.

Can I somehow use HTTPS/2s / TCPs flow/congestion control for myself here? Or will I need to implement a basic flow/congestion control system on top of gRPC?

To be slightly more precise: I'd like to send as much data as possible without filling up any internal buffers, causing delays down the line.

Upvotes: 2

Views: 261

Answers (1)

Jay Zhu
Jay Zhu

Reputation: 1672

Once data is written into the gRPC write buffer, there is no way to take it back unless you destroy the connection and reconnect.

Your requirements are:

  1. make best use of network bandwidth
  2. do not let large messages block causing too much latency for other priority messages.

A likely approach is to chunk the large message into smaller chunks (think about the similar concept as MTU in TCP), and write them to the gRPC streaming connection, interleaved with priority messages in between. On the receiver side, you have to maintain a buffer to re-assemble those chunks back into large messages. You may have to design some kind of metadata for those chunked messages so they can be put back together. gRPC stream connection guarantees delivery and order so the implementation should be relatively straightforward.

This way, you can still rely on the TCP for network congestion control, and gRPC/HTTP for flow control, but should get your priority messages through faster. Of course, the size of each chunk message needs to be tuned to best fit your scenario.

Upvotes: 0

Related Questions