0

I'm studying some features of http2, one of them is Flow Control and want to understand that How can I implement it.

If can, give me an example or demo. Thanks.

Nguyễn Văn Phong
  • 13,506
  • 17
  • 39
  • 56

1 Answers1

3

I implemented HTTP/2 in Jetty (a Java HTTP and WebSocket server), so I can point you to how it has been implemented in Jetty - but you can look at other open source projects that implement HTTP/2 and look how they have done it.

The Jetty implementation is based around class FlowControlStrategy.

There are two implementations, one naive (SimpleFlowControlStrategy) and one more efficient (BufferingFlowControlStrategy).

In both cases the FlowControlStrategy receives events from the HTTP/2 implementation, in particular:

  1. when a DATA frame is sent to the other peer
  2. when a WINDOW_UPDATE frame is received from the other peer
  3. when a DATA frame is received from the other peer
  4. when the received data is consumed by the application

In case of data sent to the other peer, the "send" flow control window is decreased; when a WINDOW_UPDATE frame is received from the other peer the "send" flow control window is increased.

Similarly, when data is received the "receive" flow control window is decreased; when the application consumes the received data, the "receive" flow control window is increased - and possibly a WINDOW_UPDATE frame is sent to the other peer to signal that it can send more data.

The HTTP/2 implementation needs to check these two flow control windows and stop sending data when the "send" flow control window reaches zero (or negative); and fail the connection if it receives data when the "receive" flow control window is zero (or negative). Upon receiving a a WINDOW_UPDATE frame, the HTTP/2 implementation needs to resume sending data.

This is the basic of how flow control in HTTP/2 should be implemented. Depending on the technology used and the implementation details, there are many more things to take care of such as data queuing, data copying, thread safety, etc. but you can address those while you are writing the implementation.

Have fun!

sbordet
  • 16,856
  • 1
  • 50
  • 45
  • Thanks for your answer. I'm currently working on .net framework/.net core.Could you give some recommendations or ideas to I can i achieved ? – Nguyễn Văn Phong Dec 21 '18 at 10:27
  • Further details can be found in the [specification](https://tools.ietf.org/html/rfc7540#section-5.2). More details would require multiple questions and multiple answers, and StackOverflow is not the right platform for long discussions. Feel free to join the [Jetty mailing list](https://www.eclipse.org/jetty/mailinglists.html) and post a question there. – sbordet Dec 21 '18 at 14:44
  • Thanks you very much. BTW do you know how to implement this one on HTTP1/HTTP1.1. If ca. please give me key word to research or demo about this. Tks. https://ibb.co/H7y13pM – Nguyễn Văn Phong Dec 22 '18 at 11:26
  • 1
    HTTP/1.1 does not need flow control implemented because it relies on TCP flow control. – sbordet Dec 22 '18 at 15:39