Ref: Toutube Distributed Systems lecture series
https://www.youtube.com/watch?v=x-D8iFU1d-o&list=PLeKd45zvjcDFUEv_ohr_HdUFe97RItdiB&index=12
DDIA 作者的 Distributed System 101,涉及基础的 CAP 理论,RPC,拜占庭将军,一致性,CRDT,分布式事务等内容,非常推荐

Lamport clock vs Vector clock

First and foremost, I want to say I am pretty much tired mentally and physically yet do not how to boost up myself. But I am human, so just have some fun with knowledge and pray I will be better when I reach the end of the post. Pray for me!

My today topic is much different compared to other posts. Neither programming languages nor Web-related things. Today is about Distributed Computer Systems and I can assure that it is not difficult to grasp as it seems to be.

1. Timing in distributed system

One of the most fundamental concept in distributed system is to manage the order of events – knowing one event happening before the another. To the best of my knowledge, two algorithms were invented to solve such thing are Lamport and Vector clock.

1.1 Lamport clock

Lamport timestamp or Lamport clock is an algorithm named under its creator, Lessie Lamport. Lamport clock is used to determine the partial ordering the events.

Suppose we have 3 different processes P0, P1, P2 in the system. By following Lamport rules, every processes P0, P1, P2 will maintain a single Lamport clock, says t. Whenever a event sends a message to the receiver, it will necessarily attach its timestamp along with its message.

Figure 1

The first rule is for every internal event inside the process, the clock t will be increased by 1 as illustrated in the Figure 1 with the process P0 and its events a, b, c, d

t:= t + 1

The second rule is whenever the receiver receives the message, it will try to compare its current timestamp with the attached timestamp of the message, and after that the value will be increased by 1. Mathematically, we say

t:= max(currentTimestamp, messageTimestamp) + 1 where

currentTimestamp: the current timestamp of the receiver

messageTimestamp: the attached timestamp of the message

In the Figure 1, event k is the receipt of the sending message of event *f* of the process P0. Following the first rule, we can say that the timestamp of event k should be 2. However, because event *k* is the receiver, we have to consider the second rule in this case. In detail, the attached timestamp of f is 6, and the computation

t := max(2 = currentTimestamp, 6 = messageTimestamp) + 1

simply yields 7. Thus, we have timestamp of *k* is 7. Easy enough?

1. 2 Vector clock

Vector clock works in a little different manner compared to Lamport clock. Origin from mathematics, vector demonstrates the displacement from point to point. For example, vector AB [x,y,z] from point A(0,0,0) to point B(3, 4, 5) in 3D space. So, you can image vector clock is such an array in which each process is a list item.

Formally, vector clock is an array of integer instead of Lamport clocks’s unique integer. Reuse the above example, we will have a vector clock as following.

Figure 2

I will now explain rules of the Vector clock algorithms step by step by using the example.

First of all, every processes will have single vector, says vp[N] where N is the number of processes. In our case, P0, P1, P2 will have vectors (0, 0, 0) at the beginning. And whenever the event start sending message, it necessarily attach its vector clock to the message in the same way as we see in Lamport clock.

Secondly, for every internal event of the same process, the timestamp will be increased by 1. Take a look at events a, b, c, d… of process P0, the according timestamps are (1, 0, 0), (2, 0, 0)… respectively.

vp[p] := vp[p] + 1 where p is the current process.

Thirdly, whenever the receiver receives the message, it will compare the value as same as Lamport.

vp[i] := max(currentVector[i], receivedVector[i])

Event k, for example, is supposed to have the vector clock (0, 0, 2). However, when it receives the message from the event f, the third rule executes, which makes the vector of k is (6, 1, 2).

Distributed System: Lamport clock vs Vector clock | 分布式系统:Lamport clock 和 Vector clock 详解相关推荐

  1. 分布式系统关联查询_一文详解分布式系统 | 留言送书

    分布式系统,顾名思义,就是让多台服务器.多计算单元,协同来完成整体的计算任务.它拥有多种组织方式.在分布式系统中,使用分层模型,路由和代理计算任务.存储任务,将不同的工作,划分到不同业务集群机器中,是 ...

  2. 分布式系统(Distributed System)资料

    分布式系统(Distributed System)资料 <Reconfigurable Distributed Storage for Dynamic Networks> 介绍:这是一篇介 ...

  3. Vector和Stack详解

    一.学习Vector和Stack之前先学习ArrayList ArrayList详解_Allence的博客-CSDN博客一.介绍ArrayList是以什么数据结构实现的ArrayList底层的数据结构 ...

  4. Note: Time clocks and the ordering of events in a distributed system

    http://research.microsoft.com/en-us/um/people/lamport/pubs/time-clocks.pdf 分布式系统的时钟同步是一个非常困难的问题,this ...

  5. 【Java 8 新特性】Java Clock 详解

    Java Clock 详解 systemDefaultZone millis instant offset system systemUTC tick tickMillis tickSeconds t ...

  6. 分布式文件系统-HDFS(   HDFS全称是Hadoop Distributed System)

    分布式文件系统-HDFS HDFS Hadoop的核心就是HDFS与MapReduce.那么HDFS又是基于GFS的设计理念搞出来的. HDFS全称是Hadoop Distributed System ...

  7. Linux(6)RedHat7 基本命令五-hwclock(clock)命令详解

    导言 hwclock命令 作用 描述 用法 详细全选项参数解释 常用选项 -r选项show -w选项 实践 - 验证clock和hwclock是一个命令 实践二-查看采用的时区和时间格式 总结 导言 ...

  8. 嵌入式Linux驱动笔记(十四)------详解clock时钟(CCF)框架及clk_get函数

    你好!这里是风筝的博客, 欢迎和我一起交流. 我在找资料的时候,发现网上大部分文章都是说: 在s3c244x_init_clocks函数里: void __init s3c244x_init_cloc ...

  9. 国际C语言混乱代码大赛优胜作品详解之“A clock in one line

    国际C语言混乱代码大赛优胜作品详解之"A clock in one line" 发表于2013-04-11 17:22| 9419次阅读| 来源StackOverflow| 53  ...

最新文章

  1. Url Rewrite 再说Url 重写
  2. 关于思考写程序的意义
  3. Win7 下打开wifi共享的方法
  4. JSF:直接从页面将参数传递给JSF操作方法,这是JavaEE 6+的一个不错的功能
  5. 15分钟,教你用Python爬网站数据,并用BI可视化分析!
  6. QML笔记-JavaScript在QML中的使用(直接调用和间接调用)
  7. Linux学习笔记 --iptables防火墙配置
  8. 杂志html转换服务平台,Verypdf HTML Converter(网页转换器)
  9. 深入理解Linux系统中的用户和组账号
  10. CSS样式切换技巧 - 动态更换网页色彩皮肤
  11. 单片机的C语言中位操作用法
  12. unicode字符和多字节字符的相互转换接口
  13. difference softreference and weakreference
  14. java完成crm系统ppt,客户关系管理系统答辩稿.ppt
  15. 基于E4A的手机蓝牙串口助手app制作
  16. 心形函数的几种表达式
  17. 如何用matlab画一个球
  18. 纺织服装业如何利用技术进行数字化转型
  19. 工业锅炉远程监控平台_工业物联网解决方案案例
  20. 南大计算机学院有几个院士,中国大学两院院士数量排名,看看谁的科研实力最强...

热门文章

  1. Linux压缩那些事
  2. Zotero参考文献管理
  3. EOJ_1024_表达式
  4. 用C++实现的壳(基础版)
  5. 10.IDA-基本操作
  6. cocos2d-x游戏开发(十三)细说回调函数
  7. C++设计模式之访问者模式
  8. C++ 泛型编程(二):非类型模板参数,模板特化,模板的分离编译
  9. 深入理解软件和硬件(国庆精彩活动预告)
  10. 牛逼! IDEA 2020 要本土化,真的是全中文了!