Presentation is loading. Please wait.

Presentation is loading. Please wait.

Synchronization Clock Synchronization Logical Clocks Global State Election Algorithms Mutual Exclusion.

Similar presentations


Presentation on theme: "Synchronization Clock Synchronization Logical Clocks Global State Election Algorithms Mutual Exclusion."— Presentation transcript:

1 Synchronization Clock Synchronization Logical Clocks Global State Election Algorithms Mutual Exclusion

2 Learning outcomes By the end of this session, you should be able to: –Explain why synchronization is so important in distributed systems by giving an appropriate example –Describe a clock synchronization algorithm –Know what is the logical clock and describe an algorithm that can be used to synchronize the logical clocks. –Understand the concept of global state of a distributed system. –Know what’s the election algorithms for –Give an example of how mutual exclusion can be implemented in distributed systems.

3 1.Clock Synchronization In a centralized system, time is unambiguous. If process A asks for the time, and then a little later process B asks for the time, the value that B gets will be higher than the value A got. make example: make program compares the times at which all the sources and object files were last modified. If the source file is created late than its object file, compilation of that source file is deeded to create a new object file, vice versa, no recompilation needed. If the make program run on distributed systems without global agreement on time, there is a problem.

4 Clock Synchronization When each machine has its own clock, an event that occurred after another event may nevertheless be assigned an earlier time.

5 1.1 Physical Clocks Every computer has a circuit for keeping track of time, we call it ‘clock’ or ‘timer’ Although the frequency at which a crystal oscillator runs is usually fairly stable, it is impossible to guarantee that the crystals in different computers all run at exactly the same frequency. There are different ways to measure the time. E.g. mean solar time, International Atomic Time. There are also different organizations to broadcast the Universal Coordinated Time (UTC), e.g. NIST operates a shortwave radio station with call letters WWV to broadcast a short pulse at the start of each UTC second.

6 1.2 Clock Synchronization Algorithms All the algorithms have the same underlying model of the system, which will be describe bellow: –When UTC time is t, the value of the clock on machine p is Cp(t). In a perfect world, we would have Cp(t) = t for all p and all t, that is dC/dt=1. –Real timer do not interupt exactly H times a second as supposed. There must be a relative error. If there exists some constant c such that : 1-c < dC/dt < 1+c –That constant c is specified by the manufacturer and is known as the maximum drift rate –If two clocks are drifting from UTC in opposite direction, at a time Dt after they synchronized, they may be as much as 2c Dt apart. If the system designers want to guarantee that no two clocks ever differ by more than d, clock must be resynchronized (in software) at least every d /2c seconds

7 Clock Synchronization Algorithms The relation between clock time and UTC when clocks tick at different rates.

8 Cristian's Algorithm Getting the current time from a time server. –Sender set it time to C UTC after get reply from server, there are two problems for this algorithm: Major one is that time must never run backward. Change can be introduce gradually Minor one is that there it takes a nonzero amount of time for the timer server’s reply to get back to the sender.

9 The Berkeley Algorithm The time daemon asks all the other machines for their clock values The machines answer The time daemon tells everyone how to adjust their clock

10 2 Logical Clocks For many purposes, it is sufficient that all machines agree on the same time. It is not essential that this time also agree with the real time (e.g. UTC). It is conventional to speak of the clock as logical clocks. Lamport timestamps –The expression a->b is read “a happens before b” –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 is also true.

11 Lamport Timestamps Three processes, each with its own clock. The clocks run at different rates. Lamport's algorithm corrects the clocks.

12 Lamport timestamps Happens-before is a transitive relation, so if a->b and b- >c, then a->c. If two events, x and y, happen in different processes that do not exchange messages, then x->y is not true, but neither is y->x. These event are said to be concurrent. Clock time C, must always go forward (increasing), never backward (decreasing) Use Lamport’s algorithm, we should assign time to all events in a distributed system subject to the following conditions: –If a happens before b in the same process, C(a)<C(b) –If a and b represent the sending and receiving of a message, respectively, C(a)<C(b). –For all distinctive events a and b, C(a)≠C(b).

13 Example: Totally-Ordered Multicasting Updating a replicated database and leaving it in an inconsistent state.

14 3. Global State The global state of a distributed system consists of the local state of each process, together with the messages that are currently in transit, that is, that have been sent but not delivered. Global state can be used to analysis if the distributed system in deadlock or distributed computation terminated One way to record the global state of a distributed system is to use the distributed snapshoot. It reflects a state in which the distributed system might have been. An important property is that such a snapshot reflects a consistent global state. The notion of a global state can be graphically represented by what is called a cut.

15 Global State A consistent cut An inconsistent cut

16 4. Election Algorithms Distributed algorithms usually require one process to act as coordinator, initiator, or otherwise perform some special role. The election algorithms are used for electing a coordinator. The goal of an election algorithm is to ensure that when an election starts, it concludes with all processes agreeing on who the new coordinator is to be. The Bully Algorithm: –When any process notices that the coordinator is no longer responding to requests, it initiates an election. A process, p, holds and election as follows: P sends an ELECTION message to all processes with higher numbers. If no one responds, P wins the election and becomes coordinator If one of the higher-ups answers, it takes over. P’s job is done.

17 The Bully Algorithm (1) The bully election algorithm Process 4 holds an election Process 5 and 6 respond, telling 4 to stop Now 5 and 6 each hold an election

18 The Bully Algorithm (2) Process 6 tells 5 to stop Process 6 wins and tells everyone

19 A Ring Algorithm Election algorithm using a ring.

20 Mutual Exclusion: A Centralized Algorithm Process 1 asks the coordinator for permission to enter a critical region. Permission is granted Process 2 then asks permission to enter the same critical region. The coordinator does not reply. When process 1 exits the critical region, it tells the coordinator, when then replies to 2

21 A Distributed Algorithm The process that want to enter a critical region builds a message containing the name of the critical region it wants to enter, its process number, and the current time. Send the message to all other processes and itself. For the process receives a request message, it will act in three different ways: –If the receiver is not in the critical region and does not want to enter it, it sends back an OK message to the sender. –If the receiver is already in the critical region, it does not reply. Instead, it queues the request. –If the receiver wants to enter the critical region but has not yet done so, it compares the timestamp in the incoming message with the one contained in the message that it has sent everyone. The lowest one wins. If the incoming message is lower, the receiver sends back an OK message. If its own message has a lower timestamp, the receiver queues the incoming request and sends nothing.

22 A Distributed Algorithm Two processes want to enter the same critical region at the same moment. Process 0 has the lowest timestamp, so it wins. When process 0 is done, it sends an OK also, so 2 can now enter the critical region.

23 A Toke Ring Algorithm An unordered group of processes on a network. A logical ring constructed in software.

24 Comparison A comparison of three mutual exclusion algorithms. Algorithm Messages per entry/exit Delay before entry (in message times) Problems Centralized32Coordinator crash Distributed2 ( n – 1 ) Crash of any process Token ring 1 to  0 to n – 1 Lost token, process crash


Download ppt "Synchronization Clock Synchronization Logical Clocks Global State Election Algorithms Mutual Exclusion."

Similar presentations


Ads by Google