分布式Process之三: Time and Ordering
2015-12-14 16:54
344 查看
1 two approach to order events across process
1)synchronize global clock, use absolute time
2)use logical time-stamp
本文关注第二个方法。
2 Happen-Before关系
定义逻辑关系 happen-before (" -> ") among pairs of events,三条规则
1)同一process A -> B if time(A) < time(B) local time
2) send(M) - > receive(M)
3) transitivity: A -> B and B -> C, then A -> C
类比java 线程 的happen before规则:
1)同一线程,顺序的指令,前面的指令 -> 后面的指令
2)通过同步器:
对一个锁的unlock -> 同一个锁后续的lock
对volatile 变量的写 -> 后续的读
3)transitivity: A -> B and B -> C, then A -> C
是一种partial order 因为不是所有的event都有happen-before关系,没有happen-before关系的event 叫 concurrent event。
A -> B or B -> A or A ||| B
3 Lamport timestamp
用sequence number给每个事件赋timestamp,并在消息中携带自己的integer clock
Each process uses a local counter (clock) which is an integer• Initial value of counter is 0
– A process increments its counter when a send or an instruction happens at it. The counter is assigned to the event as its timestamp.
– A send (message) event carries its timestamp
– For a receive (message) event the counter is updated bymax(local clock, message timestamp) + 1
A -> B 则 => LT(A) < LT(B) 但是反过来不成立,
LT(A) < LT(B) = > A -> B or A|||B
也就是说用Lamport stamp不能区分出 是A -> B还是 A|||B,只能排除不会是B -> A
4 Vector timestamp
每个process不是维护一个自己的integer clock, 而是它每一个process的最新sequence number
发消息前increment自己的 clock, 然后把整个vector include在消息里
收到消息的process, 先increment自己的clock,然后用message里的vector timestamp, 更新自己vector,(取每个process最新的clock)
1). On an instruction or send event at process i, it increments only its ithelement of its vector clock
2). Each message carries the send-event’s vector timestamp Vmessage[1…N]
3). On receiving a message at process i:Vi[i] = Vi[i] + 1Vi[j] = max(Vmessage[j], Vi[j]) for j ≠ i
VT(A) < VT(B) iif A -> B
Not (VT(A <= VT(B)) and Not (VT(B) <= VT(A)) iif A ||| B
也就是说,vector里,有的分量是A大,有的是B大,则A和B是Concurrent的
1)synchronize global clock, use absolute time
2)use logical time-stamp
本文关注第二个方法。
2 Happen-Before关系
定义逻辑关系 happen-before (" -> ") among pairs of events,三条规则
1)同一process A -> B if time(A) < time(B) local time
2) send(M) - > receive(M)
3) transitivity: A -> B and B -> C, then A -> C
类比java 线程 的happen before规则:
1)同一线程,顺序的指令,前面的指令 -> 后面的指令
2)通过同步器:
对一个锁的unlock -> 同一个锁后续的lock
对volatile 变量的写 -> 后续的读
3)transitivity: A -> B and B -> C, then A -> C
是一种partial order 因为不是所有的event都有happen-before关系,没有happen-before关系的event 叫 concurrent event。
A -> B or B -> A or A ||| B
3 Lamport timestamp
用sequence number给每个事件赋timestamp,并在消息中携带自己的integer clock
Each process uses a local counter (clock) which is an integer• Initial value of counter is 0
– A process increments its counter when a send or an instruction happens at it. The counter is assigned to the event as its timestamp.
– A send (message) event carries its timestamp
– For a receive (message) event the counter is updated bymax(local clock, message timestamp) + 1
A -> B 则 => LT(A) < LT(B) 但是反过来不成立,
LT(A) < LT(B) = > A -> B or A|||B
也就是说用Lamport stamp不能区分出 是A -> B还是 A|||B,只能排除不会是B -> A
4 Vector timestamp
每个process不是维护一个自己的integer clock, 而是它每一个process的最新sequence number
发消息前increment自己的 clock, 然后把整个vector include在消息里
收到消息的process, 先increment自己的clock,然后用message里的vector timestamp, 更新自己vector,(取每个process最新的clock)
1). On an instruction or send event at process i, it increments only its ithelement of its vector clock
2). Each message carries the send-event’s vector timestamp Vmessage[1…N]
3). On receiving a message at process i:Vi[i] = Vi[i] + 1Vi[j] = max(Vmessage[j], Vi[j]) for j ≠ i
VT(A) < VT(B) iif A -> B
Not (VT(A <= VT(B)) and Not (VT(B) <= VT(A)) iif A ||| B
也就是说,vector里,有的分量是A大,有的是B大,则A和B是Concurrent的
相关文章推荐
- 第16周实践项目-归并排序
- BoxFilter包滤波器的Matlab代码实现分析(基础)
- 一些实用的在线编辑器、在线转换工具
- 第十六周上机实践—项目1(3)—验证算法 堆排序 归并排序 基数排序
- ts流介绍
- 希尔排序
- 启动异常java.lang.IllegalAccessError: tried to access method DefaultSingletonBeanRegistry
- 简单的 JavaScript 类继承框架
- windows端搭建svn服务器 客户端xcode利用svn提交项目到服务端 流程全纪录
- TLD之L-K光流算法代码篇
- 8086的寻址方式
- Android的onCreateOptionsMenu()创建菜单Menu
- Remove Element leetcode java
- 两个App之间的跳转 并传值
- Unity3d 配置OpenCV(EmguCV) 周围环境
- java 将字符串数组变为字典顺序排序后的字符串数组
- 第16周 项目1-快速排序
- 插入排序之直接插入排序
- 第十五周项目9—基数排序
- UINavigationBar appearance 无效原因分析