关于分布式逻辑时钟,Lamport算法
大家好我想问一下分布式系统中的逻辑时钟。 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的顺序?
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
答案很简单。基于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.
重要的是这些过程按照事件发生的顺序一致。
为了同步逻辑时钟,Lamport 定义了一种称为先验事件的关系。表达式a-> b 读作“a 出现在 b 之前”。这种发生关系可以在两种情况下看到:
如果'a'和'b'是同一进程的事件,并且'a'发生在'b'之前,那么
一个-> b 为真。
如果“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:
If 'a' and 'b' are events of the same process, and 'a' occurs before 'b', then
a -> b is true.
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.