Lamport Clock 筆記

Time, Clocks, and the Ordering of Events in a Distributed System 論文閱讀筆記

之前看過一點分佈式算法:Distributed Computing —— Principles, Algorithms, and System 筆記,看這篇就比較輕鬆了。

happens-before relation: aba\to b, event aa happens before event bb if

  • aabb 在同一進程,並且 aa sequences before bb
  • aa​bb​ 在不同進程,並且 aa​ synchronizes before bb​,即 aa​ 是一個消息發送事件,bb​ 是一個消息接收事件
  • \to 具有傳遞性

happens-before 是偏序關係(partial ordering),稱 aabb 是併發的,即 aba||b,如果 a̸ba\not \to b 並且 b̸ab\not\to a

Logical Clock

logical clock 是每一個進程自己的遞增的 counter(遞增步幅不定),當一個事件發生時就產生一個 timestamp,Ci(a)C_i(a)

如果 aba\to b​,那麼

  • aabb 在同一進程,有 C(a)<C(b)C(a)<C(b)
  • 進程 pip_i 的發送事件 aa 和進程 pjp_j 的接受事件 bb,有 Ci(a)<Cj(b)C_i(a)<C_j(b)

於是有
abC(a)<C(b) a\to b \Rightarrow C(a) < C(b)
反之不成立

Ordering the Events Totally

在進程間定義全序關係 \prec,可以任意指定

定義事件全序關係 aba\Rightarrow b,事件 apia\in p_i,事件 bpjb\in p_j,如果

  • Ci(a)<Cj(b)C_i(a)<C_j(b) 或者
  • Ci(a)=Cj(b)  pipjC_i(a)=C_j(b)\ \land\ p_i\prec p_j

於是有 aba\to b 推出 aba\Rightarrow b

有句話他在 intro(Ref[1]) 中強調了:

The synchronization is specified in terms of a State Machine.

在 FIFO 通信模型中)A process can execute a command timestamped TT when it has learned of all commands issued by all other processes with timestamps less than or equal to TT.

Physical Clocks

Ci(t)C_i(t) 表示進程 pip_i 在物理時刻 tt 時的進程邏輯時鐘的值。

  • Ci(t)1<k|C_i^{'}(t)-1|<k
  • Ci(t)Cj(t)<ϵ|C_i(t)-C_j(t)|<\epsilon

爲了保證:在物理時刻 ttpjp_j 發出的信息到達 pip_i 的時鐘 Ci(t+t0)C_i(t+t_0) 一定比 Cj(t)C_j(t) 大,我們需要找到一個 μ\mu,使得 Ci(t+μ)Cj(t)>0C_i(t+\mu)-C_j(t) > 0,其中 μ\mu 是比傳輸時間小的值。

粗略估計,當 μϵ1k\mu \ge \frac{\epsilon}{1-k} 時,Ci(t+μ)Cj(t)>0C_i(t+\mu)-C_j(t) > 0 成立。(這保證了現實世界中的同步關係,即所有進程所組成的系統之外的 happens-before 關係)

最後給了個定理,沒看懂說的啥,以後看吧。

Reference

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章