1 / 33

Synchronization

Learn about the importance of synchronization in distributed systems, the challenges it presents, and various synchronization algorithms like Lamport's logical clocks and vector clocks.

tamarc
Download Presentation

Synchronization

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Synchronization

  2. Why we need synchronization? • It is important that multiple processes do not access shared resources simultaneously. • Synchronization in a distributed system is difficult since each processes may be using its own clock time. • In Distributed system there must be a global agreement on time.

  3. Clock synchronization • As an example consider UNIX make program. Normally in Unix, large programs are split up into multiple source files ,so to change one source file only require one file to be recompiled not all files. • Consider a program which consist of 100 files.When the programmer has finished changing all source files , he runs the make which examines the time at which all source and object files were last modified.

  4. If the source file input.c has time 2151and the corresponding object file input. o has time 2150, make knows that input.c has been changed since input. o was created and thus input.c must be recompiled. • If input.c has time 2144 and output.c has time 2145, no compilation is needed.

  5. Thus make goes through all the source files to find out which one need to be recompiled and calls the compiler to recompile them.

  6. What could happen in a distributed system in which there is no global agreement on time?

  7. Clock Synchronization Figure 6-1. When each machine has its own clock, an event that occurred after another event may nevertheless be assigned an earlier time.

  8. Therefore make will not call the compiler and the resulting binary program will contain a mixture of object file from the old source and new source program and pgm may crash.

  9. Physical clocks • A computer timer is precisely machined quartz crystal. • Associated with each crystal are two registers counter, holding register. • It is possible to program a timer to generate an interrupt 60 times a second, or at any other desired frequency. Each interrupt is called one clock tick.

  10. Physical clocks • A computer timer is precisely machined quartz crystal. • Associated with each crystal are two registers counter, holding register. • It is possible to program a timer to generate an interrupt 60 times a second, or at any other desired frequency. Each interrupt is called one clock tick.

  11. When a system has n computers, all n crystals will run at slightly different rates , causing the clocks gradually to get out of synchronization and give different values when read out. • This difference in time values is called clock skew.

  12. The berkeley algorithm

  13. Figure 6-7. (a) The time daemon asks all the other machines for their clock values.

  14. Figure 6-7. (b) The machines answer.

  15. Figure 6-7. (c) The time daemon tells everyone how to adjust their clock.

  16. Logical clocks

  17. Lamport’s Logical clock • In 1978 Lamport pointed out that processes must agree on the order in which events occur also must be synchronized. He developed an algorithm for that.

  18. Lamport’s Logical clock • For synchronization Lamport defined a relation called happens-before. • The expression a -> b a happens before b means that all processes agree that first event a occurs then event b occurs.

  19. Lamport’s Logical Clocks (1) The "happens-before" relation → can be observed directly in two situations: • If a and b are events in the same process, and a occurs before b, then a → b is true. • If a is the event of a message being sent by one process, and b is the event of the message being received by another process, then a → b

  20. Figure 6-9. (a) Three processes, each with its own clock. The clocks run at different rates.

  21. Figure 6-9. (b) Lamport’s algorithm corrects the clocks.

  22. Lamport’s Logical Clocks (4) Figure 6-10. The positioning of Lamport’s logical clocks in distributed systems.

  23. Lamport’s Logical Clocks (5) Updating counter Ci for process Pi • Before executing an event Pi executes Ci ← Ci + 1. • When process Pi sends a message m to Pj, it sets m’s timestamp ts (m) equal to Ci after having executed the previous step. • Upon the receipt of a message m, process Pjadjusts its own local counter as Cj ← max{Cj , ts (m)}, after which it then executes the first step and delivers the message to the application.

  24. Example: Totally Ordered Multicasting Figure 6-11. Updating a replicated database and leaving it in an inconsistent state.

  25. Vector clock

  26. Vector clock • Vector clocks is an algorithm for generating a partial ordering of events in a distributed system and detecting causality violations.

  27. Casuality • If I send you a message, and you then send one to someone else, your message is causally related to mine because its possible that whatever was in my message influenced the message you sent. However, if I send my message to a third party, it no longer causally precedes yours because you couldn't have reacted to what I sent.

  28. Just as in Lamport timestamps, interprocess messages contain the state of the sending process's logical clock. • A vector clock of a system of N processes is an array of N logical clocks, one per process, a local copy of which is kept in each process with the following rules for clock updates:

  29. Rules for clock updates • Initially all clocks are zero. • Each time a process experiences an internal event, it increments its own logical clock in the vector by one. • Each time a process prepares to send a message, it increments its own logical clock in the vector by one and then sends its entire vector along with the message being sent.

  30. Rules for clock updates • Each time a process receives a message, it increments its own logical clock in the vector by one and updates each element in its vector by taking the maximum of the value in its own vector clock and the value in the vector in the received message (for every element)

  31. Vector Clocks Figure 6-12. Concurrent message transmission using logical clocks.

  32. Vector Clocks Vector clocks are constructed by letting each process Pi maintain a vector VCi with the following two properties: • VCi [ i ] is the number of events that have occurred so far at Pi. In other words, VCi [ i ] is the local logical clock at process Pi . • If VCi [ j ] = k then Pi knows that k events have occurred at Pj. It is thus Pi’s knowledge of the local time at Pj .

  33. Vector Clocks Steps carried out to accomplish property 2 of previous slide: • Before executing an event Pi executes VCi [ i ] ← VCi [i ] + 1. • When process Pi sends a message m to Pj, it sets m’s (vector) timestamp ts (m) equal to VCi after having executed the previous step. • Upon the receipt of a message m, process Pj adjusts its own vector by setting VCj [k ] ← max{VCj [k ], ts (m)[k ]} for each k, after which it executes the first step and delivers the message to the application.

More Related