mc714 sistemas distribuidos
play

MC714 - Sistemas Distribuidos slides by Maarten van Steen (adapted - PowerPoint PPT Presentation

MC714 - Sistemas Distribuidos slides by Maarten van Steen (adapted from Distributed System - 3rd Edition) Chapter 06: Coordination Version: April 15, 2019 Coordination: Clock synchronization Physical clocks Coordination vs Synchronization


  1. MC714 - Sistemas Distribuidos slides by Maarten van Steen (adapted from Distributed System - 3rd Edition) Chapter 06: Coordination Version: April 15, 2019

  2. Coordination: Clock synchronization Physical clocks Coordination vs Synchronization Synchronization Process synchronization - to ensure that one process waits for another to complete its operation. Data synchronization - to ensure that two sets of data are the same. Coordination The goal is to manage the interactions and dependencies between activities in a distributed system. 2 / 41

  3. Coordination: Clock synchronization Physical clocks Physical clocks Problem Sometimes we simply need the exact time, not just an ordering. Solution: Universal Coordinated Time (UTC) Based on the number of transitions per second of the cesium 133 atom (pretty accurate). At present, the real time is taken as the average of some 50 cesium clocks around the world. Introduces a leap second from time to time to compensate that days are getting longer. Note UTC is broadcast through short-wave radio and satellite. Satellites can give an accuracy of about ± 0 . 5 ms. 3 / 41

  4. Coordination: Clock synchronization Clock synchronization algorithms Clock synchronization Precision The goal is to keep the deviation between two clocks on any two machines within a specified bound, known as the precision π : ∀ t , ∀ p , q : | C p ( t ) − C q ( t ) | ≤ π with C p ( t ) the computed clock time of machine p at UTC time t . Accuracy In the case of accuracy, we aim to keep the clock bound to a value α : ∀ t , ∀ p : | C p ( t ) − t | ≤ α Synchronization Internal synchronization: keep clocks precise External synchronization: keep clocks accurate 4 / 41

  5. Coordination: Clock synchronization Clock synchronization algorithms Clock drift Clock specifications A clock comes specified with its maximum clock drift rate ρ . F ( t ) denotes oscillator frequency of the hardware clock at time t F is the clock’s ideal (constant) frequency ⇒ living up to specifications: ∀ t : ( 1 − ρ ) ≤ F ( t ) ≤ ( 1 + ρ ) F Observation Fast, perfect, slow clocks By using hardware interrupts we couple dC (t) p > 1 dt dC (t) a software clock to the hardware clock, Clock time, C p = 1 k k dt c c and thus also its clock drift rate: o o l l c c t c t s e dC (t) a f r Slow clock � t p F e < 1 C p ( t ) = 1 0 F ( t ) dt ⇒ dC p ( t ) = F ( t ) P dt F dt F ⇒ ∀ t : 1 − ρ ≤ dC p ( t ) ≤ 1 + ρ dt UTC, t 5 / 41

  6. Coordination: Clock synchronization Clock synchronization algorithms Detecting and adjusting incorrect times Getting the current time from a time server T 2 T 3 B T 1 T 4 A � T req � T res Computing the relative offset θ and delay δ Assumption: δ T req = T 2 − T 1 ≈ T 4 − T 3 = δ T res � � � � θ = T 3 + ( T 2 − T 1 )+( T 4 − T 3 ) / 2 − T 4 = ( T 2 − T 1 )+( T 3 − T 4 ) / 2 � � δ = ( T 4 − T 1 ) − ( T 3 − T 2 ) / 2 Network Time Protocol 6 / 41

  7. Coordination: Clock synchronization Clock synchronization algorithms Detecting and adjusting incorrect times Getting the current time from a time server T 2 T 3 B T 1 T 4 A � T req � T res Computing the relative offset θ and delay δ Assumption: δ T req = T 2 − T 1 ≈ T 4 − T 3 = δ T res � � � � θ = T 3 + ( T 2 − T 1 )+( T 4 − T 3 ) / 2 − T 4 = ( T 2 − T 1 )+( T 3 − T 4 ) / 2 � � δ = ( T 4 − T 1 ) − ( T 3 − T 2 ) / 2 Network Time Protocol Collect eight ( θ , δ ) pairs and choose θ for which associated delay δ was minimal. Network Time Protocol 6 / 41

  8. Coordination: Clock synchronization Clock synchronization algorithms Keeping time without UTC Principle Let the time server scan all machines periodically, calculate an average, and inform each machine how it should adjust its time relative to its present time. Using a time server Time daemon 3:00 3:00 3:05 3:00 0 +5 3:00 -10 +15 3:00 +25 -20 Network 2:50 3:25 2:50 3:25 3:05 3:05 The Berkeley algorithm 7 / 41

  9. Coordination: Clock synchronization Clock synchronization algorithms Keeping time without UTC Principle Let the time server scan all machines periodically, calculate an average, and inform each machine how it should adjust its time relative to its present time. Using a time server Time daemon 3:00 3:00 3:05 3:00 0 +5 3:00 -10 +15 3:00 +25 -20 Network 2:50 3:25 2:50 3:25 3:05 3:05 Fundamental You’ll have to take into account that setting the time back is never allowed ⇒ smooth adjustments (i.e., run faster or slower). The Berkeley algorithm 7 / 41

  10. Coordination: Logical clocks Lamport’s logical clocks The Happened-before relationship Issue What usually matters is not that all processes agree on exactly what time it is, but that they agree on the order in which events occur. Requires a notion of ordering. 8 / 41

  11. Coordination: Logical clocks Lamport’s logical clocks The Happened-before relationship Issue What usually matters is not that all processes agree on exactly what time it is, but that they agree on the order in which events occur. Requires a notion of ordering. The happened-before relation If a and b are two events in the same process, and a comes before b , then a → b . If a is the sending of a message, and b is the receipt of that message, then a → b If a → b and b → c , then a → c Note This introduces a partial ordering of events in a system with concurrently operating processes. 8 / 41

  12. Coordination: Logical clocks Lamport’s logical clocks Logical clocks Problem How do we maintain a global view on the system’s behavior that is consistent with the happened-before relation? 9 / 41

  13. Coordination: Logical clocks Lamport’s logical clocks Logical clocks Problem How do we maintain a global view on the system’s behavior that is consistent with the happened-before relation? Attach a timestamp C ( e ) to each event e , satisfying the following properties: P1 If a and b are two events in the same process, and a → b , then we demand that C ( a ) < C ( b ) . P2 If a corresponds to sending a message m , and b to the receipt of that message, then also C ( a ) < C ( b ) . 9 / 41

  14. Coordination: Logical clocks Lamport’s logical clocks Logical clocks Problem How do we maintain a global view on the system’s behavior that is consistent with the happened-before relation? Attach a timestamp C ( e ) to each event e , satisfying the following properties: P1 If a and b are two events in the same process, and a → b , then we demand that C ( a ) < C ( b ) . P2 If a corresponds to sending a message m , and b to the receipt of that message, then also C ( a ) < C ( b ) . Problem How to attach a timestamp to an event when there’s no global clock ⇒ maintain a consistent set of logical clocks, one per process. 9 / 41

  15. Coordination: Logical clocks Lamport’s logical clocks Logical clocks: solution Each process P i maintains a local counter C i and adjusts this counter For each new event that takes place within P i , C i is incremented by 1. 1 Each time a message m is sent by process P i , the message receives a 2 timestamp ts ( m ) = C i . Whenever a message m is received by a process P j , P j adjusts its local 3 counter C j to max { C j , ts ( m ) } ; then executes step 1 before passing m to the application. Notes Property P1 is satisfied by (1); Property P2 by (2) and (3). It can still occur that two events happen at the same time. Avoid this by breaking ties through process IDs. 10 / 41

  16. Coordination: Logical clocks Lamport’s logical clocks Logical clocks: example Consider three processes with event counters operating at different rates P 1 P 2 P 3 P 1 P 2 P 3 0 0 0 0 0 0 6 m 1 8 10 6 m 1 8 10 12 16 20 12 16 20 18 24 m 2 30 18 24 m 2 30 24 32 40 24 32 40 P adjusts 2 30 40 50 30 40 50 its clock 36 48 60 36 48 60 P adjusts 1 m 3 42 56 70 42 61 70 m 3 its clock 48 64 80 48 69 80 m 4 m 4 54 72 90 70 77 90 60 80 100 76 85 100 11 / 41

  17. Coordination: Logical clocks Lamport’s logical clocks Logical clocks: where implemented Adjustments implemented in middleware Application layer Message is delivered Application sends message to application Adjust local clock Adjust local clock and timestamp message Middleware layer Middleware sends message Message is received Network layer 12 / 41

  18. Coordination: Logical clocks Lamport’s logical clocks Example: Total-ordered multicast Concurrent updates on a replicated database are seen in the same order everywhere P 1 adds $100 to an account (initial value: $1000) P 2 increments account by 1% There are two replicas Update 1 Update 2 Replicated database Update 1 is Update 2 is performed before performed before update 2 update 1 Result In absence of proper synchronization: replica #1 ← $1111, while replica #2 ← $1110. Example: Total-ordered multicasting 13 / 41

  19. Coordination: Logical clocks Lamport’s logical clocks Example: Total-ordered multicast Solution Process P i sends timestamped message m i to all others. The message itself is put in a local queue queue i . Any incoming message at P j is queued in queue j , according to its timestamp, and acknowledged to every other process. Example: Total-ordered multicasting 14 / 41

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend