关于分布式逻辑时钟,Lamport算法

发布于 2024-12-09 18:55:45 字数 426 浏览 0 评论 0原文

大家好我想问一下分布式系统中的逻辑时钟。 Lamport算法定义,当进程Pi中的事件a发送消息,并且进程Pj中的事件b接收到该消息时,则可以定义事件a在b之前发生。假设进程 Pj 在事件 b 处收到消息之前,Pj 上发生了事件 c(因此 c 发生在 b 之前)并向进程 Pi 发送消息,然后进程 Pi 在事件 a 之后的事件 d 处收到消息,则事件 c以及 a 发生在 d 之前。

我的问题是,如何定义事件a(第一个事件发生在进程Pi上)和事件c(第一个事件发生在进程Pj上)之间的关系?如何让进程Pi和Pj都同意事件a和c的顺序?

Lamport 算法:http://en.wikipedia.org/wiki/Lamport_timestamps

Hi everyone I would like to ask about the logical clock in distrbuted system. Lamport algorithms defines that when events a in process Pi send a message, and in Process Pj events b received that message, then it could be defined that events a is happened before b. Suppose before Process Pj received the message at events b, events c happened on Pj (thus c is happened before b) and send a message Process Pi, and then Process Pi received the message at events d after event a, then we have event c, as well as a, happened before d.

My question is, how to define the relationship between event a (The first event happened on Process Pi)and event c(The first event happened on Process Pj)? How to let process Pi and Pj both agree on the order of event a and c?

Lamport Algorithm: http://en.wikipedia.org/wiki/Lamport_timestamps

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

孤独岁月 2024-12-16 18:55:45

答案很简单。基于Lamport算法,您无法定义事件a和c之间的任何关系。我们所知道的所有事情是:

a ->; b和c-> d和a-> d和c-> b

但你不能得出 a -> 的结论c或c->一个
就这样。

The answer is simple. Based on the Lamport algorithm, you cannot define any relationships between events a and c. All the things we know are:

a -> b and c -> d and a -> d and c -> b

but you cannot conclude either a -> c or c -> a
that's all.

闻呓 2024-12-16 18:55:45

重要的是这些过程按照事件发生的顺序一致。
为了同步逻辑时钟,Lamport 定义了一种称为先验事件的关系。表达式a-> b 读作“a 出现在 b 之前”。这种发生关系可以在两种情况下看到:

  1. 如果'a'和'b'是同一进程的事件,并且'a'发生在'b'之前,那么
    一个-> b 为真。

  2. 如果“a”是进程发送消息的事件,“b”是进程发送消息的事件
    另一个进程收到消息,则a-> b 也是如此。

该算法是如何工作的?

每条消息都有发件人的发送时间。因此,如果接收器的时间小于发送器的时间,则接收器会修改时间。因此该算法同步接收器的时钟。
发送到另一个进程的每条消息都将包含发送该消息的时间单位,因此会检查时钟。

The important thing is that the processes coincide in the order that the events happen.
To synchronize logical clocks, Lamport defined a relationship called a prior occurrence. The expression a -> b is read as "a occurs before b". This relationship of occurrence can be seen in 2 situations:

  1. If 'a' and 'b' are events of the same process, and 'a' occurs before 'b', then
    a -> b is true.

  2. If 'a' is the event in which a process sends a message, and 'b' is the event of
    receipt of the message by another process, then a-> b is also true.

How does the algorithm work?

Each message has the sender's sending time. So the receiver modifies the time, in case its time is less than the time of the transmitter. So the Algorithm syncronizes the receiver's clock.
Each message that is sent to another process will contain the unit of time in which the message was sent, and thus the clocks are checked.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文