RPC、Yar、gRPC

自 11 月后端结构调整正式启动已有月余,效果初现;
PHP Yar(Yet Another RPC Framework)是我们采取的措施之一;
版本 1.3 开发过程中,Yar 服务 5XX 错误频频,问题解决速度远低于期望;
调试(Debug)技术、测试技术、观测手段的匮乏,恐怕是其中最大的原因之一;
源于超人在 PHPUnit 上的 最新尝试,我们试图在这方面上一个台阶:高质量的敏捷交付;

RPC(Remote Procedure Calling) Mechanism
RPC、Yar、gRPC_第1张图片
  • 示意图由 Dave Marshall 提供;

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 协议传输数据;
  • 多种 data packager:php,json,msgpack;
    msgpack 需要单独安装扩展;
  • Runtime Configure


    RPC、Yar、gRPC_第2张图片
示例
  • yarserver.php
handle();
  • yarserver.php @ api.example.com
  • yarclient.php
testName("michael");
    echo $client->testAdd(2,3);
  • yarclient.php @ www.example.com
如何对 RPC 服务进行单独测试?
关于 gRPC

Google 名下的开源项目;


RPC、Yar、gRPC_第3张图片
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

你可能感兴趣的:(RPC、Yar、gRPC)