简体   繁体   English

关于HTTP / 2 RFC实现的流控制问题

[英]Flow Control questions about HTTP/2 RFC Implementation

I'm building a http/2 client and I have a question about the rfc and how I should handle the implementation, particularly with respect to flow control. 我正在构建一个http / 2客户端,我对rfc以及如何处理实现有疑问,特别是在流量控制方面。

I understand that flow control uses a credit based window size system, but I'm a bit unsure about how to handle the scenario of a depleted window. 我知道流量控制使用基于信用的窗口大小系统,但我对如何处理耗尽窗口的情况有点不确定。

  1. Do I just block indefinitely until a WINDOW_UPDATE frame frees things up? 我是否只是无限期地阻塞,直到WINDOW_UPDATE帧释放了什么? Or what would a reasonable timeout be for this? 或者合理的超时是什么?

  2. When the window is depleted do I pause sending all frames? 当窗口耗尽时,我暂停发送所有帧吗? The RFC states that order of frames in a stream is significant especially for headers and data frames but it doesn't explicitly state that all frames should be paused while the window is depleted. RFC规定流中帧的顺序是重要的,特别是对于报头和数据帧,但它没有明确声明在窗口耗尽时应暂停所有帧。 This is a bit ambiguous to me as data frames are the only ones that count against window size. 这对我来说有点模棱两可,因为数据帧是唯一可以计算窗口大小的数据帧。 So should I block sending all frames or just headers/data? 那么我应该阻止发送所有帧或只是标题/数据? Is this answer different for the connection flow control context vs stream flow control context? 这个答案对于连接流控制上下文与流流控制上下文有什么不同?

There is a flow control window for all data frames in the connection and then one for each stream. 连接中的所有数据帧都有一个流控制窗口,然后每个流都有一个流控制窗口。

1.- If the connection window is exhausted, you pause sending DATA frames of any stream until you get a WINDOWS_UPDATE. 1.-如果连接窗口耗尽,则暂停发送任何流的DATA帧,直到获得WINDOWS_UPDATE。 You can implement a timeout. 您可以实现超时。 If the timeout expires, the only remedy that you have is to close the connection and try again. 如果超时到期,您唯一的补救措施是关闭连接并重试。

2.- If a stream connection window is exhausted, you pause only that stream. 2.-如果流连接窗口耗尽,则仅暂停该流。

In all the cases you pause only DATA frames. 在所有情况下,您只暂停DATA帧。 The other types of frames are not affected by flow control. 其他类型的帧不受流量控制的影响。

If you are implementing a client, as opposed to a server, you are more concerned with sending the WINDOW_UPDATE frames yourself. 如果您正在实现客户端而不是服务器,则您更关心自己发送WINDOW_UPDATE帧。 Unless you are doing a lot of POST and PUT, ie, sending data to the server. 除非你做了很多POST和PUT,即将数据发送到服务器。

In my experience as developer of an HTTP/2 server , I have found handy to manage HTTP/2 frames in groups that I call "trains". 根据我作为HTTP / 2服务器开发人员的经验,我发现在我称之为“train”的组中管理HTTP / 2帧非常方便。 For all frames except HEADERS, PUSH_PROMISE and CONTINUATION, a train is composed of just the frame. 对于除HEADERS,PUSH_PROMISE和CONTINUATION之外的所有帧,列车仅由帧组成。 For HEADERS and PUSH_PROMISE, a train is composed of that frame and any following CONTINUATION frames. 对于HEADERS和PUSH_PROMISE,列车由该帧和任何后续的CONTINUATION帧组成。 Then you put your trains in a priority queue with the following levels (first have highest priority): 然后将列车置于具有以下级别的优先级队列中(首先具有最高优先级):

  1. PING frames: you want the peer to accurately determine latency, therefore you process these frames as quickly as you receive them and you send the answer as soon as you can. PING帧:您希望对等体准确地确定延迟,因此您可以在收到这些帧时尽快处理这些帧,并尽快发送答案。
  2. SETTINGS, WINDOW_UPDATE, RST_STREAM, GO_AWAY SETTINGS,WINDOW_UPDATE,RST_STREAM,GO_AWAY
  3. PUSH_PROMISE and HEADERS trains. PUSH_PROMISE和HEADERS列车。 The HTTP/2 spec allows for two (actually three) types of HEADERS frames: the ones which are sent as HTTP headers proper and trailers. HTTP / 2规范允许两种(实际上是三种)HEADERS帧类型:作为HTTP头部发送的帧和预告片。 Here I'm talking about the first. 我在这里谈论的是第一个。
  4. DATA frames. 数据帧。 If you are implementing prioritization, you may want to further prioritize frames here. 如果要实现优先级,则可能需要在此处进一步确定框架的优先级。

and whenever the channel becomes available for sending, you send the highest priority trains in your priority queue. 每当通道可用于发送时,您将在优先级队列中发送优先级最高的列车。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM