拨回1984:看Implementing Remote Procedure Calls如何石破天惊?

历史总与我们的现在遥遥相和,History doesnot repeat, but it rhymes.

前言:

前言:其实,现在理解RPC的概念较为简单,但在一个概念在走向成熟的过程中的探索,是值得我们追寻与思考的。要追本溯源,是因为历史总与我们的现在遥遥相和,History doesnot repeat, but it rhymes.

图1:RPC论文

文章的岁数比我大,来自《ACM Transactions on Computer Systems, Vol. 2, No. 1, February 1984》,是在1976年的前人提出概念上的拓展,最后形成的就是RPC规范,可以说是远程调用的实行的起点,一个真正的开启。

Remote procedure calls (RPC) appear to be a useful paradig m for providing communication across a network between programs written in a high-level language.

Background不谈了,那时候一切都是刚开始。

图2:RPC论文

环境也不谈了,和现在相差很大,但需要理解PUP协议的内容,应为接下来,会谈到很多次。

The PUP family of protocols provides uniform access to any computer onthis internetwork. Previous PUP protocols include simple unreliable (but high-probability) datagram service, and reliable flow-controlled byte streams.

Aims

图3:RPC论文

RPC的初衷就是让分布式计算更加方便。在此之前,困难重重,机器、网络、协议、传输路径等等,有点像是带着导航的"漂流瓶"。

RPC will, we hope, remove unnecessary difficulties, leaving only the fundamental difficulties of building distributed systems: timing, inde-

pendent failure of components, and the coexistence of independent execution environments.

主要有两个目标,减少困难和避免失败。

图4:RPC论文

An important issue in design is resolving the tension between powerful semantics and efficiency.

虽然当时的主流语言Mesa已经没人记住,但数据结构的规范和响应与返回流程,留了下来。以GRPC协议栈为例。

图5:RPC论文

我们可以看到基础设计被沿用了下来,没有使用远程调用最开始的共享地址空间的方式,因为它会产生undue upheaval,主要是因为进程的竞争,会有峰谷值的差异,这会在网络环境中开销加大。We discarded the possibility of emulating some form of shared address space among the computers.

可以看到TCP和Sockets同为协议栈的基石。

图6:RPC论文

Structure

它的结构是与 Nelson的论文是相似的,包含五个部分,the user, the user-stub, the RPC communications package (known as RPCRuntime), the server-stub, and the server.

图7:RPC论文

其实现在很容易理解,只是RPCRuntime有了稍许变化,On receipt of these packets, the RPCRuntime in the callee machine passes them to the server-stub.更多是作为Cedar system的标准部分,RPCRuntime is responsible for packet-level communications.

图8:RPC论文

Naming

The binding operation offered by our RPC package is to bind an importer of an interface to an exporter of an interface. After binding, calls made by the importer invoke procedures implemented by the (remote) exporter. 基本上一个接口由它的类型和接口值组成。

图9:RPC论文

这里加载出口主要是用分布式数据库的角度,就分为个人和组织两种入口。

Grapevine distributed database的思想还是留了下来,one for each type and one for each instance.

图10:RPC论文

这段比较有意思,主要是讲述了RPCRuntime中的Exportlnterface和Importlnterface。就是分离了编辑机制和绑定机制。These are the basis of the Mesa (and Cedar) separate compilation and binding mechanism.

图11:RPC论文

When the RPCRuntime on the callee machine receivesa new call packet it uses the index to look up its table of current exports(efficiently), verifies that the unique identifier in the packet matches that in thetable, and passes the call packet to the dispatcher procedure specified in the table.它其实是维护了一个表进行查询匹配。

图12:RPC论文

他的探讨非常谦虚,讲述了这种模式的重要影响。我们都知道为了避免过多crash发生。Finally, note that this scheme allows calls to be made only on procedures that have been explicitly exported through the RPC mechanism.

图13:RPC论文

图14:RPC论文

However,the result of a call is sufficient acknowledgment that the call packet was received,and a call packet is sufficient to acknowledge the result packet of the previous call made by that process.就是传递和返回的包如何定义序列和方式。

图15:RPC论文

这里比较关键,讲到它是如何进行连接的建立与维护。

that we rely on the unique identifier we introduced when doing remote binding. Without this identifier we would be unable to detect duplicates if a server crashed and then restarted while a caller was still retransmitting a call packet (not very likely, but just plausible). We are also assuming that the call sequence number from an activity does not repeat even if the calling machine is restarted.

当链接开始的时候,后端也存储了状态信息的关键数量。我们需要确保远程绑定时的标识是唯一的。并且如何调用方重启,同一个活动的调用序列号并不会重复。这种轻量的连接管理在构建大型分布式系统的时候会变得非常重要。这让调用方能意识到caller如果发生crash或者其他严重的连接失败,就能通知到期待中的用户。

主要思想就是最小化连接的消耗并在服务上维持稳定的状态。

图16:RPC论文

下面展示了复杂调用的过程。当涉及到多个数据体或者包的时候,如何维持多个会话的连接反应。

图17:RPC论文

Exception Handling

关于异常的处理。Our RPC package faithfully emulates this mechanism.

图18:RPC论文

图19:RPC论文

The first step in reducing cost is maintaining in each machine a stock of idle server processes willing to handle incoming packets. 关于懒连接该如何处理。

关于安全

图20:RPC论文

它的时间,正确率这类。

图21:RPC论文

最后是状态的讨论。

图22:RPC论文

图23:RPC论文

我们可以看下,现在主流的gRPC和REST的差别。他们都诞生于同一个思想。

图24:RPC论文

最后,让我们回顾下本文的思想。

The techniques for managing transport level connections so as to minimize the communication costs and the state that must be maintained by a server are important in our experience of servers dealing with large numbers of users. Our binding semantics are quite powerful, but conceptually simple for a programmer familiar with single machine binding.

简单而有力量。simple and powerful.

这是一个新事物的产生,对世界带来的改变。

也是指导我们学习和研究的中心思想。

对世界来说,减枝要比生枝更加有益,也更值得赞扬。

Licensed under CC BY-NC-SA 4.0
comments powered by Disqus