irisowo
  • NEW!
    NEW!  Connect Ideas Across Notes
    Save time and share insights. With Paragraph Citation, you can quote others’ work with source info built in. If someone cites your note, you’ll see a card showing where it’s used—bringing notes closer together.
    Got it
      • Create new note
      • Create a note from template
        • Sharing URL Link copied
        • /edit
        • View mode
          • Edit mode
          • View mode
          • Book mode
          • Slide mode
          Edit mode View mode Book mode Slide mode
        • Customize slides
        • Note Permission
        • Read
          • Only me
          • Signed-in users
          • Everyone
          Only me Signed-in users Everyone
        • Write
          • Only me
          • Signed-in users
          • Everyone
          Only me Signed-in users Everyone
        • Engagement control Commenting, Suggest edit, Emoji Reply
      • Invite by email
        Invitee

        This note has no invitees

      • Publish Note

        Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note No publishing access yet

        Your note will be visible on your profile and discoverable by anyone.
        Your note is now live.
        This note is visible on your profile and discoverable online.
        Everyone on the web can find and read all notes of this public team.

        Your account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

        Your team account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

        Explore these features while you wait
        Complete general settings
        Bookmark and like published notes
        Write a few more notes
        Complete general settings
        Write a few more notes
        See published notes
        Unpublish note
        Please check the box to agree to the Community Guidelines.
        View profile
      • Commenting
        Permission
        Disabled Forbidden Owners Signed-in users Everyone
      • Enable
      • Permission
        • Forbidden
        • Owners
        • Signed-in users
        • Everyone
      • Suggest edit
        Permission
        Disabled Forbidden Owners Signed-in users Everyone
      • Enable
      • Permission
        • Forbidden
        • Owners
        • Signed-in users
      • Emoji Reply
      • Enable
      • Versions and GitHub Sync
      • Note settings
      • Note Insights New
      • Engagement control
      • Make a copy
      • Transfer ownership
      • Delete this note
      • Save as template
      • Insert from template
      • Import from
        • Dropbox
        • Google Drive
        • Gist
        • Clipboard
      • Export to
        • Dropbox
        • Google Drive
        • Gist
      • Download
        • Markdown
        • HTML
        • Raw HTML
    Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
    Create Create new note Create a note from template
    Menu
    Options
    Engagement control Make a copy Transfer ownership Delete this note
    Import from
    Dropbox Google Drive Gist Clipboard
    Export to
    Dropbox Google Drive Gist
    Download
    Markdown HTML Raw HTML
    Back
    Sharing URL Link copied
    /edit
    View mode
    • Edit mode
    • View mode
    • Book mode
    • Slide mode
    Edit mode View mode Book mode Slide mode
    Customize slides
    Note Permission
    Read
    Only me
    • Only me
    • Signed-in users
    • Everyone
    Only me Signed-in users Everyone
    Write
    Only me
    • Only me
    • Signed-in users
    • Everyone
    Only me Signed-in users Everyone
    Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note No publishing access yet

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.

    Your account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

    Your team account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

    Explore these features while you wait
    Complete general settings
    Bookmark and like published notes
    Write a few more notes
    Complete general settings
    Write a few more notes
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    <style> H2{color:#BF0060 !important;} H3{color:#009393 !important;} p{color:Black !important;} li strong {color:#4682b4 !important;} </style> # Clock Synchronization in Distributed System ## **Physiacal clock** * 時鐘有 skew * 電腦 are synchronized to UTC(=GMT), which is based on Atomic Clock. ### **名詞定義** * **Perfect clock C~p~(t) = t** * **Frequency** * Frequency is the rate at which a clock progresses * ==C~p~'(t)== is the frequency at time t of clock C~p~ * Cp'(t) = ${dCp(t)\over dt} = \lim_{Δ\to\ 0}{Cp(t)-Cp(t-Δ) \over Δ}$ = 1 for perfect clock <img src="https://i.imgur.com/EUY6Sm6.png" width = "200"/></img> * **Offset** * 時間差 <img src="https://i.imgur.com/7TOG6eT.png" width = "350"/></img> * **Precision and Accuracy** * Precision π * 精確度是相對概念 $∀t,\ ∀p, q : |C~p~(t)-C~q~(t)| ≤ π$ * the offset between two clocks is bounded by π * Accuracy α * 準確度代表絕對 * $∀t,\ ∀p : |C~p~(t)-t| ≤ α$ * the offset between a clock and a reference point (e.g., UTC) is bounded by α * Note : * clocks that are accurate within bound α, will be precise within bound π = 2α * **Skew** * ==C~a~’(t) – C~b~’(t)== : The skew of a clock C~a~ `relative to `clock C~b~ at time t * ==C~a~’(t) – 1== : The skew of C~a~, since perfect clock C~p~(t)' = 1 * **Skew Tolerance: Max Drift Rate** * Clock drift rate : the difference per unit of time from a perfect reference clock * ==Max Drift Rate $ρ$== is specified by manufactors * $1-ρ ≤ {dCp(t)\over dt} ≤ 1+ρ \ , \ ∀t$ * 2 clock may differ by ==2$ρ$Δt in Δt== * **題目** * Given Max Drift Rate $ρ$, 要求 Precision π * 解: * $2ρΔt ≤ π$ $Δt ≤ {π \over 2ρ}$ ,所以每 ${π \over 2ρ}$ 秒應 resynchronize 一次 ### **Cristian’s Algorithm** * **原因** * 電腦向 UTC =t 對齊時,msg delay Δ 導致收到的 t 實際上是 t+Δ * **假設** * Clock A B 有相同 offset & frequency * ==round-trip delay = delay(m) + delay(m’)== : 一來一回的 delay * round-trip delay = ==(T4-T3) - (T1-T2)== <img src="https://i.imgur.com/zjCo4P5.png" width = "300"/></img> * **Estimate the Offset** * Assume * O = C~B~(t) – C~A~(t) * delay(m) ~= delay(m’) * ==O = (T1 - T3 + T2 - T4) /2== <img src="https://i.imgur.com/rTpQF59.png" width = "250"/></img> * 例題 <img src="https://i.imgur.com/BfJOZ12.png" width = "500"/></img> ### **Network Time Protocol (NTP)** * **特色** * 向階層化 server 要時間 : primary, secondary...server * accuracy : 1~50ms * statically technique for filtering (去除outlier) * 保留最近 8 次 (O~i~,D~i~) pair * O~i~ = offset, D~i~ = round-trip time * ==O = 最小 D~i~ 那次的 O~i~== * survive lengthy losses of connectivity (克服斷線) * Reduntant server and paths to server , which provides protection against malicious interference ### **Berkeley Algorithm** * **特色** * 電腦間彼此同步 * 一台為 master 定期 poll slaves,取大家 Avg time 差值 <img src="https://i.imgur.com/CqRWJU9.png" width = "500"/></img> ### **Decentralized Averaging Algo** * **特色** * 每台電腦定期廣播 local time,算 Avg time 自我校正 ### **Reference Broadcast Sync (RBS)** * **前情提要** * 同步時的 4 種 time error <img src="https://i.imgur.com/OVed7Yw.png" width = "400"/></img> * **原理** * <img src="https://i.imgur.com/1gUUYCt.png" width = "300"/></img> * Sender 同時發 m∈M 的 referenced packets 給 receivers * 假設所有 receivers 應該同時收到 packets * removes send and access time errors (因為同 sender 送出) * sensitive to receive time and propagation delay (因為此 Algo 假設這兩種 error 一樣) * 範例 :上圖 receiver 1 & 2 彼此內部時間差 1s * 所有 receivers 互相同步,計算彼此時間差 Offset[p,q] * 忽略 clock skew : `Offset[p,q]` = ${\sum\limits_{m∈M}^{}Tp,m - Tq,m \over |M|}$ * 考慮 clock skew:令 `Offset[p,q](t)` = 時間函數 αt + β * **特性** * Broadcast 使用 relative time reference * 因為實際時間不重要,Msg 只是當作共同參考點 * Each receiver synchronizes to a reference packet * Msg ==沒有 timestamp== * 所以任一種 broadcast protocol 都可以 e.g. ARP, RTS/CTS, route discovery packets, etc. ### **Multihop RBS** * **前提: Phase Offset Estimation** * Receivers 紀錄收到脈衝時的 local time * Receivers exchange observations * form a local (relative) timescale * **原理**: * <img src="https://i.imgur.com/DpQLgCJ.png" width = "500"/></img> ## **Model of distributed computation** ### **Actions and events** * The states of processes and channels change as the events occur. * **3 type of events** | | internal event| msg send event | msg receive event | | --------| -------- | -------- | -------- | | Change the state of | process itself | sending process & channel | receiving process & channel| ### **From Causality(因果) to Event ordering** * 利用 Event ordering 推斷因果關係 * Event Relation 是 partial order,因為 DS 中無 global clock,不可能有 total order * **Happened-Before (HB) Relation** * Induced By Message Passing * Strict Partial Order * irrefexivity, antisymmetry(因到果,不能果到因), transitivity ### **2 Rules** 1. e~i~ 到不了 e~j~ ,但 e~j~ 到/到不了 e~i~ 都有可能 2. e~i~ 能到 e~j~,則 e~j~ 必到不了 e~i~ <img src="https://i.imgur.com/V9H2xI7.png" width = "400"/></img> ### **Concurrent** * **Def** * Neither e~i~ -> e~j~ nor e~j~ -> e~i~ 則 e~i~ || e~j~ * <img src="https://i.imgur.com/srGP4UD.png" width = "200"/></img> * **Concurrent relation 沒有遞移性** * <img src="https://i.imgur.com/O6ttTNT.png" width = "400"/></img> * **將 Logically concur 視作 physically concur** * 因為不影響 causality * LogiC 出錯,不代表 PhyC 會出錯 ### **結論** * <img src="https://i.imgur.com/uxkde99.png" width = "400"/></img> ## **Logical time and logical clock** ### **Logical clock** * **Definition** * C: H ↦ T * ==Maps event e to timestamp C(e)==, e∈H, C(e)∈T * ==Clock consistent conditions== * (1) ei ➞ ej ⇒ C(ei) < C(ej) * satisfied protocal : Lamport's Scalar Time * (2) ei ➞ ej ⇔ C(ei) < C(ej) : strongly consistent * satisfied protocal : Vector time * **physical vs. logocal clock** * <img src="https://i.imgur.com/uUW79CC.png" width = "300"/></img> ### **Implementing logical clock** * **2 issue** * (1) Data Structure * local logical clock:lc~i~ * global logical clock:gc~i~ * (2) ==Protocal== to update the DS that ensures the consistency * 2 rules * ==R1== : how ==lc ~i~== is udated as the events (send/receive/internal) occurs * ==R2== : how ==gc~i~== is udated * **Protocal** * ==(1) Lamport's scalar time== * Use C~i~ to represent both lc~i~ and gc~i~ * R1 : C~i~ := C~i~ + d * R2 : C~i~ = max(C~i~, C~msg~)+d * d=1 as an example * <img src="https://i.imgur.com/oluSybO.png" width = "300"/></img> * <img src="https://i.imgur.com/GnEyOj8.png" width = "350"/></img> * ==(2) Vector time== * R1 : vt~i~[i] := vt~i~[i] + d * R2 : * 1 ≤ k ≤ n : vt~i~[k] := max(vt~i~[k], vt[k]) + d * vt~i~[i] := vt~i~[i] + d * d=1 as an example * <img src="https://i.imgur.com/qkKIv6I.png" width = "400"/></img> ## **Lamport’s Scalar Time** ### **Construct Consistent Total Order** * **問題** * Scalar Clocks 可以排出 Consistent Total Order,但不能排出所有可能 * **目標 : Construct Unique Total Order** * 作法:時間相同時比 process id * 範例: * 原來有 2!2!種排法,變成 1 種 * <img src="https://i.imgur.com/lIWA8hk.png" width = "300"/></img> ### **Totally-ordered Multicasting** * **原理** * Msg timestamped 後 multicast 出去 * 收到 Msg 後放進 ==local queue== 按照 C(m) ==排序==,回覆 ==Ack== * Scalar time 中,若有 hb 關係則 C(m1) < C(m2) * Msg 在 queue 的 head 且收到所有 processes 的 Ack,才會把 Msg 交給 Application * **Ack 用處** * 因為 channel 是 FIFO 所以當 Pa 收到 Pb 的 Ack,表示 Pb 在 Ack 以前的訊息都送完了 ## **Vector Time** ### **Relation** * `vh < vk` : less than, 存在 vh < vk ,其他維度 vh <= vk * `vh || vk` : incomparable, 某些維度上 vh < vk 有些 vk < vh * **Isomorphism** * Set of events <---isomorphic to---> Set of timestamp * Strong consistency holds * ei ➞ ej ⇔ C(ei) < C(ej) * ei || ej ⇔ C(ei) || C(ej) ### **Singhal–Kshemkalyani’s differential technique** * **目的** * 減少 msg overhead * **原理** * 每個 process 只花 2n storage * 存上次 send/update 的本地時間vt~i~[i] * LS~i~[j] : last sent to process j * LU~i~[j] : 上次 update vt~i~[j] * 當 LS~i~[j] < LU~i~[k] 時,發送 {(k, vt~i~[k])} 給 process j * 範例: * LS~i~[j] = 4, LU~i~[k]=9, LU~i~[l]=10 * 發送 {(k,vt~i~[k]),(l,vt~i~[l])} 給 process j * **例題** * <img src="https://i.imgur.com/EStmH3O.png" width = "500"/></img> ###### tags: `OS`

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password
    or
    Sign in via Google Sign in via Facebook Sign in via X(Twitter) Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    By signing in, you agree to our terms of service.

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully