Clock Synchronization and algorithm

Slides:



Advertisements
Similar presentations
Global States.
Advertisements

CS 542: Topics in Distributed Systems Diganta Goswami.
Time and Global States Part 3 ECEN5053 Software Engineering of Distributed Systems University of Colorado, Boulder.
Synchronization Chapter clock synchronization * 5.2 logical clocks * 5.3 global state * 5.4 election algorithm * 5.5 mutual exclusion * 5.6 distributed.
Distributed Computing
Distributed Computing
Tanenbaum & Van Steen, Distributed Systems: Principles and Paradigms, 2e, (c) 2007 Prentice-Hall, Inc. All rights reserved DISTRIBUTED.
Time and Global States ECEN5053 Software Engineering of Distributed Systems University of Colorado, Boulder.
Distributed Systems Spring 2009
LEADER ELECTION CS Election Algorithms Many distributed algorithms need one process to act as coordinator – Doesn’t matter which process does the.
4. Synchronization Clock synchronization
CS 582 / CMPE 481 Distributed Systems
1. Explain why synchronization is so important in distributed systems by giving an appropriate example When each machine has its own clock, an event that.
Synchronization Clock Synchronization Logical Clocks Global State Election Algorithms Mutual Exclusion.
Computer Science Lecture 11, page 1 CS677: Distributed OS Last Class: Clock Synchronization Logical clocks Vector clocks Global state.
SynchronizationCS-4513, D-Term Synchronization in Distributed Systems CS-4513 D-Term 2007 (Slides include materials from Operating System Concepts,
Synchronization in Distributed Systems CS-4513 D-term Synchronization in Distributed Systems CS-4513 Distributed Computing Systems (Slides include.
EEC-681/781 Distributed Computing Systems Lecture 11 Wenbing Zhao Cleveland State University.
EEC-681/781 Distributed Computing Systems Lecture 11 Wenbing Zhao Cleveland State University.
1 Synchronization  Clock Synchronization  and algorithm.
Tanenbaum & Van Steen, Distributed Systems: Principles and Paradigms, 2e, (c) 2007 Prentice-Hall, Inc. All rights reserved DISTRIBUTED SYSTEMS.
Lecture 12 Synchronization. EECE 411: Design of Distributed Software Applications Summary so far … A distributed system is: a collection of independent.
Synchronization Chapter 5. Clock Synchronization When each machine has its own clock, an event that occurred after another event may nevertheless be assigned.
Computer Science Lecture 10, page 1 CS677: Distributed OS Last Class: Clock Synchronization Physical clocks Clock synchronization algorithms –Cristian’s.
Computer Science Lecture 12, page 1 CS677: Distributed OS Last Class Vector timestamps Global state –Distributed Snapshot Election algorithms.
1 Synchronization Part 1 REK’s adaptation of Claypool’s adaptation of Tanenbaum’s Distributed Systems Chapter 5.
Election Algorithms and Distributed Processing Section 6.5.
Election Algorithms. Topics r Issues r Detecting Failures r Bully algorithm r Ring algorithm.
Synchronization Chapter 6 Part I Clock Synchronization & Logical clocks Part II Mutual Exclusion Part III Election Algorithms Part IV Transactions.
Synchronization.
Tanenbaum & Van Steen, Distributed Systems: Principles and Paradigms, 2e, (c) 2007 Prentice-Hall, Inc. All rights reserved DISTRIBUTED SYSTEMS.
Tanenbaum & Van Steen, Distributed Systems: Principles and Paradigms, 2e, (c) 2007 Prentice-Hall, Inc. All rights reserved DISTRIBUTED SYSTEMS.
OS2- Sem , R. Jalili Synchronization Chapter 5.
Computer Science Lecture 10, page 1 CS677: Distributed OS Last Class: Naming Name distribution: use hierarchies DNS X.500 and LDAP.
Computer Science Lecture 12, page 1 CS677: Distributed OS Last Class Vector timestamps Global state –Distributed Snapshot Election algorithms –Bully algorithm.
Synchronization CSCI 4900/6900. Importance of Clocks & Synchronization Avoiding simultaneous access of resources –Cooperate to grant exclusive access.
Synchronization CSCI 4780/6780. Mutual Exclusion Concurrency and collaboration are fundamental to distributed systems Simultaneous access to resources.
Tanenbaum & Van Steen, Distributed Systems: Principles and Paradigms, 2e, (c) 2007 Prentice-Hall, Inc. All rights reserved DISTRIBUTED SYSTEMS.
Synchronization. Why we need synchronization? It is important that multiple processes do not access shared resources simultaneously. Synchronization in.
Lamport’s Logical Clocks & Totally Ordered Multicasting.
Chapter 5 Synchronization Clocks and Synchronization Algorithms Lamport Timestamps and Vector Clocks Distributed Snapshots Termination Detection Election.
Synchronization Chapter 5. Outline 1.Clock synchronization 2.Logical clocks 3.Global state 4.Election algorithms 5.Mutual exclusion 6.Distributed transactions.
Synchronization Chapter 5.
Communication & Synchronization Why do processes communicate in DS? –To exchange messages –To synchronize processes Why do processes synchronize in DS?
Real-Time & MultiMedia Lab Synchronization Distributed System Jin-Seung,KIM.
Distributed Coordination. Turing Award r The Turing Award is recognized as the Nobel Prize of computing r Earlier this term the 2013 Turing Award went.
Synchronization CSCI 4900/6900. Importance of Clocks & Synchronization Avoiding simultaneous access of resources –Cooperate to grant exclusive access.
Synchronization Chapter 5. Table of Contents Clock Synchronization Logical Clocks Global State Election Algorithms Mutual Exclusion.
Distributed Process Coordination Presentation 1 - Sept. 14th 2002 CSE Spring 02 Group A4:Chris Sun, Min Fang, Bryan Maden.
DISTRIBUTED SYSTEMS Principles and Paradigms Second Edition ANDREW S
Chapter 5 Synchronization Presenter: Maria Riaz. Distributed Systems – Fall 2004 – Prof. SY Lee2 Sequence of Presentation Synchronization Clock Synchronization.
Tanenbaum & Van Steen, Distributed Systems: Principles and Paradigms, 2e, (c) 2007 Prentice-Hall, Inc. All rights reserved DISTRIBUTED SYSTEMS.
Clock Synchronization When each machine has its own clock, an event that occurred after another event may nevertheless be assigned an earlier time.
Election Distributed Systems. Algorithms to Find Global States Why? To check a particular property exist or not in distributed system –(Distributed) garbage.
Tanenbaum & Van Steen, Distributed Systems: Principles and Paradigms, 2e, (c) 2007 Prentice-Hall, Inc. All rights reserved DISTRIBUTED SYSTEMS.
Logical Clocks. Topics r Logical clocks r Totally-Ordered Multicasting.
6 SYNCHRONIZATION. introduction processes synchronize –exclusive access. –agree on the ordering of events much more difficult compared to synchronization.
Synchronization. Clock Synchronization In a centralized system time is unambiguous. In a distributed system agreement on time is not obvious. When each.
Synchronization Chapter 5. Clock Synchronization When each machine has its own clock, an event that occurred after another event may nevertheless be assigned.
COMP 655: Distributed/Operating Systems Summer 2011 Dr. Chunbo Chu Week 6: Synchronyzation 3/5/20161 Distributed Systems - COMP 655.
Synchronization Chapter 5. Clock Synchronization When each machine has its own clock, an event that occurred after another event may nevertheless be assigned.
Mutual Exclusion Algorithms. Topics r Defining mutual exclusion r A centralized approach r A distributed approach r An approach assuming an organization.
Lecture on Synchronization Submitted by
Distributed Systems Lecture 9 Leader election 1. Previous lecture Middleware RPC and RMI – Marshalling 2.
Distributed Systems 31. Theoretical Foundations of Distributed Systems - Coordination Simon Razniewski Faculty of Computer Science Free University of Bozen-Bolzano.
Distributed Computing
DISTRIBUTED SYSTEMS Principles and Paradigms Second Edition ANDREW S
Chapter 5 (through section 5.4)
Prof. Leonardo Mostarda University of Camerino
Last Class: Naming Name distribution: use hierarchies DNS
Presentation transcript:

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; 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

Use of time in distributed systems:

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

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

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

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

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

Cristian’s Algorithm Minor problem What to do? – 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 !

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

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.

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

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

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

Lamport Algorithm Assign time value C(A) such that Lamport Algorithm 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

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

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

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 ??

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

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.

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

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

Global State (1) A consistent cut An inconsistent cut

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

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.

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

A DONE message is sent if 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

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

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

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

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

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?

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

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.

A Ring Algorithm(2) Process 6 fails.

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.

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

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

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

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

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

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

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

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