Distributed Systems CS425/ECE428 01/31/2020
Today’s agenda • Clock synchronization • Chapter 14.1-14.3 • Logical clocks • Chapter 14.4
Recap from last class: Failures • Three types: omission, arbitrary, timing . • Failure detection (detecting a crashed process): • Send periodic ping-acks or heartbeats. • Report crash if no response until a timeout. • Timeout can be precisely computed for synchronous systems and estimated for asynchronous. • Metrics: completeness, accuracy, failure detection time, bandwidth. • Failure detection for a system with multiple processes: • Centralized, ring, all-to-all • Trade-off between completeness and bandwidth usage.
Recap from last class: Clocks • Useful to compare timestamps across processes (or know accurate time). • Clocks in different computers show different times. • Clock skew: relative difference between two clock values. • Clocks in different computers drift at different rates. • Clock drift rate: change in skew from a perfect reference clock per unit time (measured by the reference clock). • Need for synchronization : • External: with an authoritative clock, for achieving accuracy • Internal: among the processes within a distributed system.
Synchronization of clocks m r : What is the time? client server m s : It is T s What time T c should client adjust its local clock to after receiving m s ? T s ∆ T c = T s + ∆ But the value of ∆ is unknown.
Synchronization in synchronous systems m r : What is the time? client server m s : It is T s What time T c should client adjust its local clock to after receiving m s ? Let max and min be maximum and minimum network delay. If T c = T s , skew(client, server) ≤ max. If T c = (T s + max) , skew(client, server) ≤ (max – min) If T c = (T s + min) , skew(client, server) ≤ (max – min) T c = (T s + (min + max)/2) , skew(client,server) ≤ (max – min)/2
Synchronization in asynchronous systems • Cristian Algorithm • Berkeley Algorithm • Network Time Protocol
Cristian Algorithm m r : What is the time? client server m s : It is T s What time T c should client adjust its local clock to after receiving m s ? Client measures the round Try deriving the worst case skew! trip time ( T round ). T c = T s + (T round / 2) Hint: client is assuming its one-way skew ≤ (T round / 2) – min delay from server ( ∆ ) is T round /2. How off ( min is minimum one way can it be? network delay).
Cristian Algorithm m r : What is the time? client server m s : It is T s What time T c should client adjust its local clock to after receiving m s ? t Client measures the round T s = t + min trip time ( T round ). ( ∆ = T round – min) T s + T round - min T c = T s + (T round / 2) t skew ≤ (T round / 2) – min T s = t + T round - min ( min is minimum one way ( ∆ = min) network delay). T s + min
Cristian Algorithm m r : What is the time? client server m s : It is T s What time T c should client adjust its local clock to after receiving m s ? Improve accuracy by sending multiple Client measures the round spaced requests and using response trip time ( T round ). with smallest T round . T c = T s + (T round / 2) skew ≤ (T round / 2) – min Server failure: Use multiple ( min is minimum one way synchronized time servers. network delay).
Cristian Algorithm m r : What is the time? client server m s : It is T s What time T c should client adjust its local clock to after receiving m s ? Client measures the round trip time ( T round ). Cannot handle faulty time T c = T s + (T round / 2) servers. skew ≤ (T round / 2) – min ( min is minimum one way network delay).
Berkeley Algorithm Only supports internal synchronization. 1. Server periodically polls clients: “what time do you think it is?” Client Client ? ? Client Server ? ? ? Client Client
Berkeley Algorithm Only supports internal synchronization. 1. Server periodically polls clients: “what time do you think it is?” Client Client 2. Each client responds with its local time. t 1 t 2 3. Server uses Cristian algorithm to Client estimate local time at each client. Server t 3 t 5 4. Average all local times (including its own) – use as updated time. t 4 Client Client
Berkeley Algorithm Only supports internal synchronization. 1. Server periodically polls clients: “what time do you think it is?” Client Client 2. Each client responds with its local time. 𝑝 1 𝑝 2 3. Server uses Cristian algorithm to Client estimate local time at each client. Server 𝑝 3 𝑝 5 4. Average all local times (including its own) – use as updated time. 𝑝 4 5. Send the offset (amount by Client which each clock needs Client adjustment).
Berkeley Algorithm Only supports internal synchronization. Client Client Handling faulty processes: Only use timestamps within t 1 t 2 some threshold of each other. Client Server t 3 Handling server failure: t 5 Detect the failure and elect a t 4 new leader. Client Client
Network Time Protocol Time service over the Internet for synchronizing to UTC. Primary, UTC synch 1 Accuracy Secondary, 2 2 2 synched primary Strata 3, synched by the 3 3 secondary 3 3 3 3 Hierarchical structure for scalability . Multiple lower strata servers for robustness . Authentication mechanisms for security . Statistical techniques for better accuracy .
Network Time Protocol Primary, UTC synch 1 Secondary, 2 2 2 synched primary Strata 3, synched by the 3 3 secondary 3 3 3 3 How clocks get synchronized: • Servers may multicast timestamps within a LAN. Clients adjust time assuming a small delay. Low accuracy . • Procedure-call (Cristian algorithm). Higher accuracy. • Symmetric mode used to synchronize lower strata servers. Highest accuracy .
NTP Symmetric Mode Server B T T i-2 i-1 Time m m' Time Server A T T i- 3 i A and B exchange messages and record the send and receive timestamps. Use these timestamps to compute offset with respect to one another ( o i ).
NTP Symmetric Mode Server B T T i-2 i-1 Time m m' Time Server A T T i- 3 i • t and t’: actual transmission times T i-2 = T i-3 + t + o for m and m’(unknown) T i = T i-1 + t’ – o • o: true offset of clock at B relative to clock at A (unknown) d i = t + t’ = (T i-2 - T i-3 ) + (T i - T i-1 ) • o i : estimate of actual offset o i = ((T i-2 - T i-3 ) - (T i -T i-1 ))/2 between the two clocks o = o i + (t’ – t)/2 • d i : estimate of accuracy of o i ; total transmission times for m and m’; d i =t+t’
NTP Symmetric Mode Server B T T i-2 i-1 Time m m' Time Server A T T i- 3 i • t and t’: actual transmission times T i-2 = T i-3 + t + o for m and m’(unknown) T i = T i-1 + t’ – o • o: true offset of clock at B relative to clock at A (unknown) d i = t + t’ = (T i-2 - T i-3 ) + (T i - T i-1 ) • o i : estimate of actual offset o i = ((T i-2 - T i-3 ) - (T i -T i-1 ))/2 between the two clocks o = o i + (t’ – t)/2 • d i : estimate of accuracy of o i ; t, t’ ≥ 0 total transmission times for m (o i – d i / 2) ≤ o ≤ (o i + d i / 2) and m’; d i =t+t’
NTP Symmetric Mode Server B T T i-2 i-1 Time m m' Time Server A T T i- 3 i A and B exchange messages and record the send and receive timestamps. Use these timestamps to compute offset with respect to one another ( o i ). A server computes its offset from multiple different sources and adjust its local time accordingly.
Synchronization in asynchronous systems • Cristian Algorithm • Synchronization between a client and a server. round / 2) – min ≤ T • Synchronization bound = (T round / 2 • Berkeley Algorithm • Internal synchronization between clocks. • A central server picks the average time and disseminates offsets. • Network Time Protocol • Hierarchical time synchronization over the Internet.
Event Ordering • A usecase of synchronized clocks: • Reasoning about order of events. • Can we reason about order of events without synchronized clocks?
Process, state, events • Consider a system with n processes: <p 1 , p 2 , p 3 , …., p n > • Each process p i is described by its state s i that gets transformed over time. • State includes values of all local variables, affected files, etc. • s i gets transformed when an event occurs. • Three types of events: • Local computation. • Sending a message. • Receiving a message.
Event ordering • Easy to order events within a single process, based on timestamps. j is the j th event of the i th process. • e i m > • history(p i ) = h i = < e i 0 , e i 1 , e i 1 , …. e i • Initial state
Event Ordering • Easy to order events within a single process p i , based on their time of occurrence. • How do we reason about events across processes? • A message must be sent before it gets received at another process. • These two notions help define happened-before (HB) relationship denoted by → . • e → e’ means e happened before e’ .
Happened-Before Relationship • Happened-before (HB) relationship denoted by → . • e → e’ means e happened before e’ . • e → i e’ means e happened before e’ , as observed by p i . • HB rules: • If ∃ p i , e → i e’ then e → e’ . • For any message m, send(m) → receive(m) • If e → e’ and e’ → e” then e → e’’ • Also called “potentially causal” ordering.
Recommend
More recommend