RPC语义到底是什么目的 [英] RPC semantics what exactly is the purpose

查看:80
本文介绍了RPC语义到底是什么目的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究 rpc 语义,至少一次和最多一次语义,它们是如何工作的?

I was going through the rpc semantics, at-least-once and at-most-once semantics, how does they work?

无法理解其实现的概念.

Couldn't understand the concept of their implementation.

推荐答案

在这两种情况下,目标都是调用一次函数.然而,不同之处在于它们的故障模式.在至少一次"中,系统将重试失败,直到它知道函数被成功调用,而至多一次"将不会尝试重试(或将确保有一个否定的确认)重试前调用).

In both cases, the goal is to invoke the function once. However, the difference is in their failure modes. In "at-least-once", the system will retry on failure until it knows that the function was successfully invoked, while "at-most-once" will not attempt a retry (or will ensure that there is a negative acknowledgement of the invocation before retrying).

至于这些是如何实现的,这可能会有所不同,但伪代码可能如下所示:

As to how these are implemented, this can vary, but the pseudo-code might look like this:

At least once:
    request_received = false
    while not request_received:
       send RPC
       wait for acknowledgement with timeout
       if acknowledgment received and acknowledgement.is_successful:
          request_received = true


At most once:
   request_sent = false
   while not request_sent:
      send RPC
      request_sent = true
      wait for acknowledgement with timeout
      if acknowledgment received and not acknowledgement.is_successful:
         request_sent = false

您想要执行最多一次"的示例案例类似于付款(您不想意外地向某人的信用卡收取两次费用),其中至少一次"的示例案例就像使用特定值更新数据库一样(如果您碰巧连续两次将相同的值写入数据库,那实际上不会对任何事情产生任何影响).您几乎总是希望将至少一次"用于非变异(又名幂等)操作;相比之下,大多数变异操作(或者至少是那些逐渐改变状态并因此在应用变异时依赖当前/先前状态的操作)将需要最多一次".

An example case where you want to do "at-most-once" would be something like payments (you wouldn't want to accidentally bill someone's credit card twice), where an example case of "at-least-once" would be something like updating a database with a particular value (if you happen to write the same value to the database twice in a row, that really isn't going to have any effect on anything). You almost always want to use "at-least-once" for non-mutating (a.k.a. idempotent) operations; by contrast, most mutating operations (or at least ones that incrementally mutate the state and are thus dependent on the current/prior state when applying the mutation) would need "at-most-once".

我应该补充一点,在至少一次"系统之上实现最多一次"语义是相当普遍的,方法是在 RPC 的主体中包含一个唯一标识它的标识符,并确保在服务器上系统看到的每个 ID 只处理一次.您可以将 TCP 数据包中的序列号(确保数据包按顺序传送一次)视为此模式的特例.然而,这种方法在分布式系统上正确实施可能有些挑战,在分布式系统上,相同 RPC 的重试可能会到达运行相同服务器软件的两台不同的计算机.(处理这个问题的一种技术是记录接收到 RPC 的事务,然后在重新分配系统内部的请求以进行进一步处理之前使用集中式系统聚合和删除这些记录;另一种技术是机会性地处理 RPC,但是当服务器之间的同步最终检测到这种重复时,要协调/恢复/回滚状态……这种方法可能不会用于支付,但它在论坛帖子等其他情况下很有用).

I should add that it is fairly common to implement "at most once" semantics on top of an "at least once" system by including an identifier in the body of the RPC that uniquely identifies it and by ensuring on the server that each ID seen by the system is processed only once. You can think of the sequence numbers in TCP packets (ensuring the packets are delivered once and in order) as a special case of this pattern. This approach, however, can be somewhat challenging to implement correctly on distributed systems where retries of the same RPC could arrive at two separate computers running the same server software. (One technique for dealing with this is to record the transaction where the RPC is received, but then to aggregate and deduplicate these records using a centralized system before redistributing the requests inside the system for further processing; another technique is to opportunistically process the RPC, but to reconcile/restore/rollback state when synchronization between the servers eventually detects this duplication... this approach would probably not fly for payments, but it can be useful in other situations like forum posts).

这篇关于RPC语义到底是什么目的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆