GRPC調(diào)研

Grpc 線程架構(gòu)


Execute_thrd: 公有線程,啟動(dòng)時(shí)負(fù)責(zé)啟動(dòng)監(jiān)聽,IO,其他任務(wù);

Timer_thrd:負(fù)責(zé)執(zhí)行指定的定時(shí)任務(wù)(非周期性任務(wù));

Consumer_thrd:從Queue中取Event消費(fèi)。

網(wǎng)絡(luò)模型


Thread: 用戶Consumer線程;

Completion_queue: Grpc Queue,用來實(shí)現(xiàn)異步的事件隊(duì)列;

Pollset: 每個(gè)queue有個(gè)對(duì)應(yīng)的pollset,用來從底層收集IO事件;

Polling island : 是pollset的一個(gè)邏輯單位,可以包含多個(gè)pollset;

Epoll set: 底層os對(duì)應(yīng)的epool set,OS內(nèi)核負(fù)責(zé)收活動(dòng)FD,底層epool的封裝(windows giops封裝)

Transport Explainer

在Grpc上的一個(gè)batch,由幾個(gè)基本的stream ops組成。Batch是調(diào)度的基本單位。

Stream ops如下:

send_initial_metadata

Client: initate an RPC

Server: supply response headers

recv_initial_metadata

Client: get response headers

Server: accept an RPC

send_message (zero or more) : send a data buffer

recv_message (zero or more) : receive a data buffer

send_trailing_metadata

Client: half-close indicating that no more messages will be coming

Server: full-close providing final status for the RPC

recv_trailing_metadata: get final status for the RPC

Server extra: This op shouldn't actually be considered complete until the server has also sent trailing metadata to provide the other side with final status

cancel_stream: Attempt to cancel an RPC

collect_stats: Get stats

The fundamental responsibility of the transport is to transform between this internal format and an actual wire format, so the processing of these operations is largely transport-specific.

Transport負(fù)責(zé)內(nèi)部格式和網(wǎng)絡(luò)格式之間轉(zhuǎn)換。

One or more of these ops are grouped into a batch. Applications can start all of a call's ops in a single batch, or they can split them up into multiple batches. Results of each batch are returned asynchronously via a completion queue.

每個(gè)call的ops可以放到一個(gè)batch中,如果一部實(shí)現(xiàn),會(huì)放到多個(gè)batch中,每一個(gè)batch會(huì)返回completion queue一個(gè)Event。

Internally, we use callbacks to indicate completion. The surface layer creates a callback when starting a new batch and sends it down the filter stack along with the batch. The transport must invoke this callback when the batch is complete, and then the surface layer returns an event to the application via the completion queue. Each batch can have up to 3 callbacks:

recv_initial_metadata_ready (called by the transport when the recv_initial_metadata op is complete)

recv_message_ready (called by the transport when the recv_message op is complete)

on_complete (called by the transport when the entire batch is complete)

上面三個(gè)回調(diào)函數(shù),肯定會(huì)被執(zhí)行

一個(gè)batch可以分成這三個(gè)階段recv_initial_metadata,recv_message_ready,on_complete。

一個(gè)call的時(shí)序圖:


Client send_initial_metadata: Initiate an RPC with a path (method) and authority

Server recv_initial_metadata: accept an RPC

Client send_message: Supply the input proto for the RPC

Server recv_message: Get the input proto from the RPC

Client send_trailing_metadata: This is a half-close indicating that the client will not be sending any more messages

Server recv_trailing_metadata: The server sees this from the client and knows that it will not get any more messages. This won't complete yet though, as described above.

Server send_initial_metadata, send_message, send_trailing_metadata: A batch can contain multiple ops, and this batch provides the RPC response headers, response content, and status. Note that sending the trailing metadata will also complete the server's receive of trailing metadata.

Client recv_initial_metadata: The number of ops in one side of the batch has no relation with the number of ops on the other side of the batch. In this case, the client is just collecting the response headers.

Client recv_message, recv_trailing_metadata: Get the data response and status

模式處理

服務(wù)器端異步模式框架,添加自定義Event Queue增加并發(fā)性能


?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • Spring Cloud為開發(fā)人員提供了快速構(gòu)建分布式系統(tǒng)中一些常見模式的工具(例如配置管理,服務(wù)發(fā)現(xiàn),斷路器,智...
    卡卡羅2017閱讀 136,641評(píng)論 19 139
  • NAME dnsmasq - A lightweight DHCP and caching DNS server....
    ximitc閱讀 2,995評(píng)論 0 0
  • rljs by sennchi Timeline of History Part One The Cognitiv...
    sennchi閱讀 7,864評(píng)論 0 10
  • 前情回顧:(19)——第一章第三節(jié) 失之交臂 張翼從馮綸手中接過弩機(jī),托在手上,仔細(xì)地端詳了好半天,驚訝地對(duì)馮綸說...
    帝都奇妙物語閱讀 491評(píng)論 4 6
  • bellonaaa閱讀 184評(píng)論 0 0

友情鏈接更多精彩內(nèi)容