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)系作者
  • 序言:七十年代末丑孩,一起剝皮案震驚了整個(gè)濱河市,隨后出現(xiàn)的幾起案子灭贷,更是在濱河造成了極大的恐慌温学,老刑警劉巖,帶你破解...
    沈念sama閱讀 219,366評(píng)論 6 508
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件甚疟,死亡現(xiàn)場(chǎng)離奇詭異仗岖,居然都是意外死亡,警方通過查閱死者的電腦和手機(jī)古拴,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,521評(píng)論 3 395
  • 文/潘曉璐 我一進(jìn)店門箩帚,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人黄痪,你說我怎么就攤上這事紧帕。” “怎么了?”我有些...
    開封第一講書人閱讀 165,689評(píng)論 0 356
  • 文/不壞的土叔 我叫張陵是嗜,是天一觀的道長(zhǎng)愈案。 經(jīng)常有香客問我,道長(zhǎng)鹅搪,這世上最難降的妖魔是什么站绪? 我笑而不...
    開封第一講書人閱讀 58,925評(píng)論 1 295
  • 正文 為了忘掉前任,我火速辦了婚禮丽柿,結(jié)果婚禮上恢准,老公的妹妹穿的比我還像新娘。我一直安慰自己甫题,他們只是感情好馁筐,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,942評(píng)論 6 392
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著坠非,像睡著了一般敏沉。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上炎码,一...
    開封第一講書人閱讀 51,727評(píng)論 1 305
  • 那天盟迟,我揣著相機(jī)與錄音,去河邊找鬼潦闲。 笑死攒菠,一個(gè)胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的矫钓。 我是一名探鬼主播要尔,決...
    沈念sama閱讀 40,447評(píng)論 3 420
  • 文/蒼蘭香墨 我猛地睜開眼,長(zhǎng)吁一口氣:“原來是場(chǎng)噩夢(mèng)啊……” “哼新娜!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起既绩,我...
    開封第一講書人閱讀 39,349評(píng)論 0 276
  • 序言:老撾萬榮一對(duì)情侶失蹤概龄,失蹤者是張志新(化名)和其女友劉穎,沒想到半個(gè)月后饲握,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體私杜,經(jīng)...
    沈念sama閱讀 45,820評(píng)論 1 317
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,990評(píng)論 3 337
  • 正文 我和宋清朗相戀三年救欧,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了衰粹。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點(diǎn)故事閱讀 40,127評(píng)論 1 351
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡笆怠,死狀恐怖铝耻,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情,我是刑警寧澤瓢捉,帶...
    沈念sama閱讀 35,812評(píng)論 5 346
  • 正文 年R本政府宣布频丘,位于F島的核電站,受9級(jí)特大地震影響泡态,放射性物質(zhì)發(fā)生泄漏搂漠。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,471評(píng)論 3 331
  • 文/蒙蒙 一某弦、第九天 我趴在偏房一處隱蔽的房頂上張望桐汤。 院中可真熱鬧,春花似錦靶壮、人聲如沸惊科。這莊子的主人今日做“春日...
    開封第一講書人閱讀 32,017評(píng)論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽馆截。三九已至,卻和暖如春蜂莉,著一層夾襖步出監(jiān)牢的瞬間蜡娶,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 33,142評(píng)論 1 272
  • 我被黑心中介騙來泰國(guó)打工映穗, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留窖张,地道東北人。 一個(gè)月前我還...
    沈念sama閱讀 48,388評(píng)論 3 373
  • 正文 我出身青樓蚁滋,卻偏偏與公主長(zhǎng)得像宿接,于是被迫代替她去往敵國(guó)和親。 傳聞我的和親對(duì)象是個(gè)殘疾皇子辕录,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 45,066評(píng)論 2 355

推薦閱讀更多精彩內(nèi)容

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