GRPC Source/transport/Flow control

Source: Internet
Author: User
Tags mutex

Flow control

Code

Https://github.com/messixukej ...
Added some comments on the basis of liangzhiyang/annotate-grpc-go

Send Flow control

The target of the HTTP/2 flow control, under the constraints of the initial value of the traffic window, gives the receiving end full control of the current traffic size to be accepted.

    • Algorithm:

      • Both ends (transmit and receive) maintain a Flow control window (Windows) initial value.
      • Each data frame is sent by the sender, the window is decremented, decreasing the amount of the frame size, if the window is smaller than the frame size, then the frame must be split. If window equals 0, no frame can be sent.
      • The receiver can send the window_update frame to the sending end, and the sending end is added to the window with the window Size increment specified in the frame as an increment.
// 用于发送流控。 将当前可用的quota(字节数)写入c,有数据发送需要时,从c中获取。acquire到的大小即为可支持的最大发送量。// acquire 将quota全部获取出来,根据实际使用量,将未使用的重新add回pool。type quotaPool struct{    c chan int    mu    sync.Mutex    quota int}http2Client.Write消耗quota,client跟stream有各自的控制。handleWindowUpdate补充quota。

Receive flow control

 //for receiving flow control. OnData by judging the Pendingdata, pendingupdate and whether or not exceeding limit to flow control. Type inflow struct{///The inbound flow control limit for pending data./limit uint32 mu sync.    Mutex//Pendingdata is the overall data which has been received but not been consumed by applications.    Data received but not consumed by the application, corresponding to OnData. Pendingdata UInt32//The amount of data the application have consumed but GRPC have not sent Windows Update for them.    Used to reduce window update frequency. Corresponding OnRead pendingupdate uint32}pendingdata:handledata->ondata increased pendingdata->s.write (IO available. Readfull Read) PendingUpdate:io.ReadFull (S1, p)->stream.read read Data->windowhandler->updatewindow-> OnRead reduce Pendingdata, 1/4limit volume also empty pendingupdate->windowupdate->framer.writewindowupdate update send side window size, Send-side processing handlewindowupdate (id=0 Update client, non-0 update for stream), and then add send-side quota  
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.