1 / 81

Synchronization

Synchronization. Clock Synchronization and algorithm. Synchronization. Concentrate on how process can synchronize Not simultaneously access a shared resources. Multiple process can agree on the ordering of event/access the shared resources;

elinor
Télécharger la présentation

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 Clock Synchronization and algorithm

  2. Synchronization • Concentrate on how process can synchronize • Not simultaneously access a shared resources. • Multiple process can agree on the ordering of event/access the shared resources; • E.g: process p1 should send message m1 prior to pcs p2 and message m2 • Synchronization in DS is much more difficult rather that in uniprocessor/multiprocessor system

  3. Use of time in distributed systems:

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

  5. Clock Synchronization Algorithms • ! Centralized Algorithms • ! Cristian’s Algorithm (1989) • ! Berkeley Algorithm (1989) • ! Decentralized Algorithms • ! Averaging Algorithms (e.g. NTP) • ! Multiple External Time Sources

  6. Cristian’s Algorithm • Assume one machine (the time server) has a WWV receiver and all other machines are to stay synchronized with it. • Every specificseconds, each machine sends a message to the time server asking for the current time. ! Time server responds with message containing current time, CUTC.

  7. Cristian's Algorithm • Getting the current time from a time server.

  8. Cristian's Algorithm A major problem – the sender clock/client is fast " arriving value of CUTC from the time server will be smaller than client’s current time, C. ! What to do? ! One needs to gradually slow down client clock by adding less time per tick. Normally each interrupt add 10msec => 9msec per tick. or add 11 msec per tick to advance the time

  9. Cristian’s Algorithm • Minor problem • – the one-way delay from the server to client is “significant” and may vary considerably. • What to do? • Measure this delay and add it to CUTC. • The best estimate of delay is (T1 – T0)/2 for the message propagation time. • Can subtract off I (the server interrupt handling time). • one way propagation time = (T1 – T0-I)/2 !

  10. 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

  11. Averaging Algorithm • Every R seconds, each machine broadcasts its current time. ! The local machine collects all other broadcast time samples during some time interval, S. ! The simple algorithm algorithm the new local time is set as the average of the value received from all other machines.

  12. Averaging Algorithms ! A slightly more sophisticated algorithm :: Discard the m highest and m lowest to reduce the effect of a set of faulty clocks. – Average the rest. ! Another improved algorithm :: Correct each message by adding to the received time an estimate of the propagation time from the source. ! One of the most widely used algorithms in the Internet is the Network Time Protocol (NTP).

  13. Logical Clocks • All machine must agree with one time/clock. • Logical clock: no matter its not the same to the real time. • Lamport “ all process must agree with the sequence of event occurs” • Either input.c is older or newer then input.o

  14. Logical Clock and Lamport Timestamp • Logical clocks • Order of events matters more than absolute time • E.g. UNIX make: input.c input.o • Lamport timestamp • Synchronize logical clocks • Happens-before relation • A -> B : A happens before B • Two cases which determine “happens-before” • A and B are in same process, and A occurs before B: a -> b • A is send-event of message M, and B is receive-event of same message M • Transitive relation • If A -> B and B -> C, then A-> C • Concurrent events • Neither A -> B nor B -> A is true

  15. Lamport Algorithm • Assign time value C(A) such that • 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, C(a) < C(b) • Lamport Algorithm • Each process increments local clock between any two successive events • Message contains a timestamp • Upon receiving a message, if received timestamp is ahead, receiver fast forward it clock to be one more than sending time • Extension for total ordering • Requirement: For all distinctive events a and b, C(a)  C(b) • Solution: Break tie between concurrent events using process number

  16. Lamport Timestamp Example 0 0 0 6 A 8 10 12 16 20 18 24 B 30 24 32 40 30 40 50 36 48 C 60 42 56 70 48 D 64 80 54 72 90 60 80 100 • Clocks run at different rate

  17. Solutions 0 0 0 6 A 8 10 12 16 20 18 24 B 30 24 32 40 30 40 50 36 48 C 60 42 61 70 48 D 69 80 70 77 90 76 85 100 • Message C From process 2 leaves at 60 > must arrive at 61 or later Correct clocks using Lamport’s Algorithm

  18. Example: Totally-Ordered Multicast • Application of Lamport timestamps • Scenario • Replicated accounts in New York(NY) and San Francisco(SF) • Two transactions occur at the same time and multicast • Current balance: $1,000 • Add $100 at SF • Add interest of 1% at NY • Possible results ??

  19. Inconsistent State $1000*.01+1000=1010 $1000+$100=1100 1010+100 =$1110 1100*.01+1100=$1111

  20. Totally Ordered Multicast • Use Lamport timestamps • Algorithm • Message is time stamped with sender’s logical time • Message is multicast (including sender itself) • When message is received • It is put into local queue • Ordered according to timestamp • Multicast acknowledgement • Message is delivered to applications only when • It is at head of queue • It has been acknowledged by all involved processes • Lamport algorithm (extended) ensures total ordering of events • All processes will eventually have the same copy • of the local queue # consistent global ordering.

  21. Global state • local state of each process • eg: database records (not temporary records) • with messages are in transit ( have been sent but not delivered)

  22. Distributed Snapshot: Intro • Reflects the state in which a system might have been • Chandy and Lamport (1985) • If it is recorded that Q recd a msg from P • then it should also be recorded that P sent it • However, If P’s sending is recorded, but not that of Q receiving it, that’s allowed • Assumption: processes are connected to each other via uni-directional point-to-point channels • Any process can initiate the algorithm • Use a marker with the message to initiate communication

  23. Global State (1) • A consistent cut • An inconsistent cut

  24. Global State (2) • Organization of a process and channels for a distributed snapshot

  25. ALGORITHM • Any process can initiate the algorithm. • 2. Initiating process P starts by recording its own local state. Then it sends a marker • along each of its outgoing channels. • 3. When a process Q receives a marker through an incoming channel C: • • If Q hasn’t already saved its local state, • Q first records its local state and then sends a marker along each of its own outgoing channels. • • If Q has already recorded its state earlier, the marker on channel C is an indicator that Q • should record the state of the channel. • 4. A process is done when it has received a marker on each of its coming channels. The • local state of the process and the state of each of its incoming channels are sent to the • initiating process.

  26. Global State (3) • Process Q receives a marker for the first time and records its local state • Q records all incoming message • Q receives a marker for its incoming channel and finishes recording the state of the incoming channel

  27. When Q finishes its role in the snapshot it can send one of the two messages to it predecessor • DONE or CONTINUE • A DONE message is sent if • All of Q’s successors have returned a “DONE” • Q has not received any message • ElSE • CONTINUE message will sent to its predecessor

  28. Election Algorithms • Need to find one process that is the coordinator • Assume • Each process has a unique identifier • network address for example • One process per machine • Every process knows the process number of every other process • Processes don’t know which processes are down and which ones are still running • End result of the algorithm: all processes agree on who is the new coordinator/leader • Bully algorithm & Ring Algorithm

  29. Bully Algorithm (Garcia-Molina) • A process notices that coordinator is not responding • it starts an election (any process can start one) • Election algorithm • P sends an ELECTION message to processes with higher numbers • If no one responds, P wins the election • If some process with higher process number responds • P’s job is done, that process takes over • the receiver sends an OK message to P • receiver starts an election process • Eventually all processes give up, except one • This process sends out a message saying that it is the new “COORDINATOR” • A process that was down, when it comes back up starts a new election of its own

  30. The Bully Algorithm (1) The bully election algorithm; pcs 7 as coordinator=> crashed • Process 4 is the first on noticed the crashed >> send ELECTION process to 5, 6 and 7 (higher pcs) • Process 5 and 6 respond, telling 4 to stop • Now 5 and 6 each hold an election

  31. The Bully Algorithm (2) • Process 6 tells 5 to stop • Process 6 wins and tells everyone

  32. Ring Algorithm (1) • Does NOT use a token • Assume • processes are ordered • each process knows its successor • and the successor’s successor, and so on (needed in case of failures) • Process P detects that the coordinator is dead • sends an ELECTION message to its successor • includes its process number in the message • each process that receives it • adds its own process number and then forwards it to its successor • eventually it gets back that message • now what does it do?

  33. Ring Algorithm (2) • The process that initiated it, then sends out a message saying “COORDINATOR” • the process with highest number in list is the leader • when this comes back, then process P deletes it

  34. A Ring Algorithm(1) • Election algorithm using a ring. We start with 6 processes,     connected in a logical ring. Process 6 is the leader,     as it has the highest number.

  35. A Ring Algorithm(2) Process 6 fails.

  36. A Ring Algorithm(3) Process 3 notices that Process 6 does not respond So it starts an election, sending a message containing its id to the next node in the ring.

  37. A Ring Algorithm(4) Process 5 passes the message on,     adding its own id to the message

  38. A Ring Algorithm(5) Process 0 passes the message on,     adding its own id to the message.

  39. A Ring Algorithm(6) Process 1 passes the message on,     adding its own id to the message.

  40. A Ring Algorithm(7) Process 4 passes the message on,     adding its own id to the message

  41. A Ring Algorithm(8) When Process 3 receives the message back,     it knows the message has gone around the ring,         as its own id is in the list. Picking the highest id in the list,     it starts the coordinator message "5 is the leader" around the ring

  42. A Ring Algorithm(9) Process 5 passes on the coordinator message

  43. A Ring Algorithm(10) Process 0 passes on the coordinator message.

  44. A Ring Algorithm(11) Process 1 passes on the coordinator message.

  45. A Ring Algorithm(12) Process 4 passes on the coordinator message Process 3 receives the coordinator message,     and stops it.

  46. Mutual Exclusion • What is mutual exclusion? • Make sure that no other will use the shared data structure at the same time. • Single processor systems • use semaphores and monitors • Three different algorithms • Centralized Algorithm • Distributed Algorithm • Token Ring Algorithm

  47. Mutual Exclusion:Centralized Algo(1) • One process is elected as coordinator • Other processes send it a message asking for permission • coordinator grants permission • or says no-permission (or doesn’t reply at all) • queues the request • When the critical region is free • it sends a message to the first one in the queue

  48. Mutual Exclusion: A Centralized Algorithm(2) • Process 1 asks the coordinator (ask)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,(release) when then replies to 2

  49. Mutual Exclusion: A Centralized Algorithm(3) • Coordinator only let one process to enter the critical region. • The request is granted in the order: no process ever waits forever ( no starvation). • Three messages is use in accessing the critical region/shared resources: • Request • Grant • Release • Drawback:coordinator is single point failure • If process blocked after making a request- it is cannot distinguish either the coordinator is dead or resource not available. • Performance bottleneck in a large system.

More Related