RPC算谈、Yar、gRPC

自 11 月后端結(jié)構(gòu)調(diào)整正式啟動已有月余料滥,效果初現(xiàn)然眼;
PHP Yar(Yet Another RPC Framework)是我們采取的措施之一;
版本 1.3 開發(fā)過程中葵腹,Yar 服務(wù) 5XX 錯誤頻頻高每,問題解決速度遠低于期望;
調(diào)試(Debug)技術(shù)践宴、測試技術(shù)鲸匿、觀測手段的匱乏,恐怕是其中最大的原因之一阻肩;
源于超人在 PHPUnit 上的 最新嘗試带欢,我們試圖在這方面上一個臺階:高質(zhì)量的敏捷交付运授;

RPC(Remote Procedure Calling) Mechanism

A remote procedure is uniquely identified by the triple: (program number, version number, procedure number) The program number identifies a group of related remote procedures, each of which has a unique procedure number. A program may consist of one or more versions. Each version consists of a collection of procedures which are available to be called remotely. Version numbers enable multiple versions of an RPC protocol to be available simultaneously. Each version contains a a number of procedures that can be called remotely. Each procedure has a procedure number.

Yar 在 GitHub

Yar is a RPC framework which aims to provide a simple and easy way to do communication between PHP applications.
It has the ability to concurrently call multiple remote services.

  • 是一個 PECL 擴展乔煞,屬于 Web Service 分類吁朦;
  • 采用 HTTP 協(xié)議傳輸數(shù)據(jù);
  • 多種 data packager:php渡贾,json逗宜,msgpack;
    msgpack 需要單獨安裝擴展空骚;
  • Runtime Configure


示例
  • yarserver.php
<?php
class API {
    public function testName($name) {
        error_log("Hello, $name\n", 3, "/logs/yar.log");
        return "Hello, $name";
    }
    public function testAdd($a, $b) {
        $c = $a + $b;
        error_log("$a + $b = $c\n", 3, "/logs/yar.log");
        return "$a + $b = $c";
    }
}
$service = new Yar_Server(new API());
$service->handle();
<?php
    $client = new Yar_Client("http://api.example.com/yarserver.php");
    echo $client->testName("michael");
    echo $client->testAdd(2,3);
如何對 RPC 服務(wù)進行單獨測試纺讲?
關(guān)于 gRPC

Google 名下的開源項目府怯;


Works across languages and platforms
  • gRPC Concepts刻诊;
    Like many RPC systems, gRPC is based around the idea of defining a service, specifying the methods that can be called remotely with their parameters and return types. By default, gRPC uses protocol buffers as the Interface Definition Language (IDL) for describing both the service interface and the structure of the payload messages.
  • A Basic PHP Programmer’s Introduction to Working with gRPC
  • Why use gRPC?
    With gRPC you can define your service once in a .proto file and implement clients and servers in any of gRPC’s supported languages, which in turn can be run in environments ranging from servers inside Google to your own tablet - all the complexity of communication between different languages and environments is handled for you by gRPC. You also get all the advantages of working with protocol buffers, including efficient serialization, a simple IDL(Interface Definition Language), and easy interface updating.
  • Protocol Buffers - Google's data interchange format.
    Protocol Buffers (a.k.a., protobuf) are Google's language-neutral, platform-neutral, extensible mechanism for serializing structured data. You can find protobuf's documentation on the Google Developers site.
  • Protocol Buffers are similar to the Apache Thrift (used by Facebook) or Microsoft Bond protocols.
    Comparison of data serialization formats.
  • gRPC library for PHP牺丙;
  • SOA则涯,SOA Reference Model
  • HTTP Status Code 499
    HTTP 499 in Nginx means that the client closed the connection before the server answered the request. In my experience it is usually caused by client side timeout. As I know it's an Nginx specific error code.

https://gist.github.com/dzlab/2e6e79419877dc29d2efc63ae5974fd5
https://danielmiessler.com/blog/log-post-data-nginx/#gs.ZM_5pEY
http://developers.redhat.com/blog/2016/05/23/configuring-nginx-to-log-post-data-on-linux-rhel/
http://stackoverflow.com/questions/4939382/logging-post-data-from-request-body
https://laracasts.com/discuss/channels/general-discussion/laravel-and-rpc
http://restfulapi.nl/#what1
http://www.jsonrpc.org/
https://miniflux.net/documentation/json-rpc-api
http://pages.cs.wisc.edu/~remzi/OSTEP/dist-intro.pdf

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末冲簿,一起剝皮案震驚了整個濱河市粟判,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌峦剔,老刑警劉巖档礁,帶你破解...
    沈念sama閱讀 207,113評論 6 481
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場離奇詭異吝沫,居然都是意外死亡呻澜,警方通過查閱死者的電腦和手機,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 88,644評論 2 381
  • 文/潘曉璐 我一進店門惨险,熙熙樓的掌柜王于貴愁眉苦臉地迎上來羹幸,“玉大人,你說我怎么就攤上這事辫愉≌な埽” “怎么了?”我有些...
    開封第一講書人閱讀 153,340評論 0 344
  • 文/不壞的土叔 我叫張陵恭朗,是天一觀的道長屏镊。 經(jīng)常有香客問我,道長痰腮,這世上最難降的妖魔是什么而芥? 我笑而不...
    開封第一講書人閱讀 55,449評論 1 279
  • 正文 為了忘掉前任,我火速辦了婚禮膀值,結(jié)果婚禮上棍丐,老公的妹妹穿的比我還像新娘弟翘。我一直安慰自己,他們只是感情好骄酗,可當我...
    茶點故事閱讀 64,445評論 5 374
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著悦冀,像睡著了一般趋翻。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上盒蟆,一...
    開封第一講書人閱讀 49,166評論 1 284
  • 那天踏烙,我揣著相機與錄音,去河邊找鬼历等。 笑死讨惩,一個胖子當著我的面吹牛,可吹牛的內(nèi)容都是我干的寒屯。 我是一名探鬼主播荐捻,決...
    沈念sama閱讀 38,442評論 3 401
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼寡夹!你這毒婦竟也來了处面?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 37,105評論 0 261
  • 序言:老撾萬榮一對情侶失蹤菩掏,失蹤者是張志新(化名)和其女友劉穎魂角,沒想到半個月后,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體智绸,經(jīng)...
    沈念sama閱讀 43,601評論 1 300
  • 正文 獨居荒郊野嶺守林人離奇死亡野揪,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 36,066評論 2 325
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發(fā)現(xiàn)自己被綠了瞧栗。 大學時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片斯稳。...
    茶點故事閱讀 38,161評論 1 334
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖沼溜,靈堂內(nèi)的尸體忽然破棺而出平挑,到底是詐尸還是另有隱情,我是刑警寧澤系草,帶...
    沈念sama閱讀 33,792評論 4 323
  • 正文 年R本政府宣布通熄,位于F島的核電站,受9級特大地震影響找都,放射性物質(zhì)發(fā)生泄漏唇辨。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點故事閱讀 39,351評論 3 307
  • 文/蒙蒙 一能耻、第九天 我趴在偏房一處隱蔽的房頂上張望赏枚。 院中可真熱鬧亡驰,春花似錦、人聲如沸饿幅。這莊子的主人今日做“春日...
    開封第一講書人閱讀 30,352評論 0 19
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽栗恩。三九已至透乾,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間磕秤,已是汗流浹背乳乌。 一陣腳步聲響...
    開封第一講書人閱讀 31,584評論 1 261
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留市咆,地道東北人汉操。 一個月前我還...
    沈念sama閱讀 45,618評論 2 355
  • 正文 我出身青樓,卻偏偏與公主長得像蒙兰,于是被迫代替她去往敵國和親磷瘤。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當晚...
    茶點故事閱讀 42,916評論 2 344

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