OS2- Sem1 83-84, R. Jalili Synchronization Chapter 5.

Slides:



Advertisements
Similar presentations
Time and Global States Part 3 ECEN5053 Software Engineering of Distributed Systems University of Colorado, Boulder.
Advertisements

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.
Distributed Systems Spring 2009
4. Synchronization Clock synchronization
CS 582 / CMPE 481 Distributed Systems
Computer Science Lecture 12, page 1 CS677: Distributed OS Last Class Distributed Snapshots –Termination detection Election algorithms –Bully –Ring.
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.
Synchronization in Distributed Systems. Mutual Exclusion To read or update shared data, a process should enter a critical region to ensure mutual exclusion.
EEC-681/781 Distributed Computing Systems Lecture 11 Wenbing Zhao Cleveland State University.
Clock Synchronization and algorithm
Tanenbaum & Van Steen, Distributed Systems: Principles and Paradigms, 2e, (c) 2007 Prentice-Hall, Inc. All rights reserved DISTRIBUTED SYSTEMS.
EEC-681/781 Distributed Computing Systems Lecture 10 Wenbing Zhao Cleveland State University.
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.
Time, Clocks, and the Ordering of Events in a Distributed System Leslie Lamport (1978) Presented by: Yoav Kantor.
1 Synchronization Part 1 REK’s adaptation of Claypool’s adaptation of Tanenbaum’s Distributed Systems Chapter 5.
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.
CIS 720 Distributed algorithms. “Paint on the forehead” problem Each of you can see other’s forehead but not your own. I announce “some of you have paint.
© Oxford University Press 2011 DISTRIBUTED COMPUTING Sunita Mahajan Sunita Mahajan, Principal, Institute of Computer Science, MET League of Colleges, Mumbai.
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.
Global State (1) a)A consistent cut b)An inconsistent cut.
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.
Fall 2007cs4251 Distributed Computing Umar Kalim Dept. of Communication Systems Engineering 15/01/2008.
Synchronization. Why we need synchronization? It is important that multiple processes do not access shared resources simultaneously. Synchronization in.
Vector Clock Each process maintains an array of clocks –vc.j.k denotes the knowledge that j has about the clock of k –vc.j.j, thus, denotes the clock of.
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?
Distributed Systems Principles and Paradigms Chapter 05 Synchronization.
Tanenbaum & Van Steen, Distributed Systems: Principles and Paradigms, 2e, (c) 2007 Prentice-Hall, Inc. All rights reserved DISTRIBUTED SYSTEMS.
Real-Time & MultiMedia Lab Synchronization Distributed System Jin-Seung,KIM.
Synchronization Chapter Contents qClock Synchronization qLogical Clocks qGlobal State qElection Algorithms qMutual Exclusion qDistributed Transactions.
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
Distributed Systems Topic 5: Time, Coordination and Agreement
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.
Page 1 Mutual Exclusion & Election Algorithms Paul Krzyzanowski Distributed Systems Except as otherwise noted, the content.
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 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
Outline Theoretical Foundations
Presentation transcript:

OS2- Sem , R. Jalili Synchronization Chapter 5

OS2- Sem , R. Jalili Synchronization Processes need synchronization. –Access to resources, –Sharing printers –Ordering of events Sync based on the actual time. Relative ordering instead of absolute ordering. Election algorithms for group management. Distributed Mutual Exclusion

OS2- Sem , R. Jalili Clock Synchronization When each machine has its own clock, an event that occurred after another event may nevertheless be assigned an earlier time.

OS2- Sem , R. Jalili Physical Clocks (1) Counter & Holding register  clock tick Computation of the mean solar day.

OS2- Sem , R. Jalili Physical Clocks (2) TAI seconds are of constant length, unlike solar seconds. Leap seconds are introduced when necessary to keep in phase with the sun.

OS2- Sem , R. Jalili Clock Synchronization Algorithms The relation between clock time and UTC when clocks tick at different rates.

OS2- Sem , R. Jalili Clock Synchronization The clocks drift at most  per time unit. So, we have 1-  ≤ dC/ dt ≤ 1+  If two clocks are drifting in opposite directions, at a time  t, they may be as much as 2   t apart. If the OS designers want to guarantee that two clocks ever differ by more than , the clocks must be re-synch at least every  /2  seconds. Various algorithms …

OS2- Sem , R. Jalili Cristian's Algorithm It is assumed that a time server exists. Getting the current time from a time server periodically, certainly not more than every  /2  seconds. The points –Time must never run backward  gradual decrement or increment –The propagation delay which is ≥ 0. This time is vary and depends on the network load. Cristian’s attempt is to measure the delay WITH the SAME clock. (the round trip of sending a query to the time server and getting reply = (T1 – T0)/2 or a better estimate :: (T1 – T0 – I )/2, I is the interrupt handling time in the time server.

OS2- Sem , R. Jalili Cristian's Algorithm

OS2- Sem , R. Jalili The Berkeley Algorithm In the Cristian’s algorithm, the time server was passive. Other machines periodically ask it for the time. In the Berekley Unix, the time server is polling every machine and checking its time. Based on the average of such times, it advises all to correct their time. Discarding faulty values from the both extremes.

OS2- Sem , R. Jalili The Berkeley Algorithm a)The time daemon asks all the other machines for their clock values b)The machines answer c)The time daemon tells everyone how to adjust their clock

OS2- Sem , R. Jalili Additional Clock Synch. Alg. Most widely used in the Internet is NTP (Network Time Protocol). It is now possible to have millions of clocks synch. Use of Synch Clocks: –Enforcing at-most-once message delivery to a server, even in the face of crashes. –Conventional method: seq# and keeping all numbers; if a server crashes, it forgets everything! –If we attach each message a timestamp, and we keep the most recent timestamp seen for each connection, the msg with less timestamp is regarded as duplicate and rejected.

OS2- Sem , R. Jalili Use of Synch Clocks –Old timestamps in the table can be removed using a global variable: G = CurrentTime – MaxLifeTime – MaxClockSkew –If an incoming msg has no correspondent connection and its time is more recent than G, it is accepted; otherwise it is rejected. –In the case of server crash and reboot, G is reloaded from the time stored on disk and increments by the update period and again the same criterion rejects or accepts the incoming messages.

OS2- Sem , R. Jalili Logical Clocks Many cases need agreement on the same time, not exactly the actual time.  Logical clocks. Lamport in 1978 introduced the non-absolute clocks. If two processes do not communicate, it is not necessary to synch their clocks. All processes do not agree on time, they agree on the order in which events happen. Base idea is the Happens-Before relation

OS2- Sem , R. Jalili Logical Clocks-2 A  B means A happened before B Two rules 1- If A and B belong to the same process and A occurs before B, then A  B is true. 2- If A is the event of sending m, and B is the event of receipt of m by another process, then A  B is true. Happens-Before is a transitive relation. If we do not have either A  B or B  A then A and B are concurrent. We need a way to measure the time for each event; so we assign C(A) as the time of event A.

OS2- Sem , R. Jalili Logical Clocks-3 A  B implies that C(A) < C(B). For local events, we have the above relation. For the case of sending and receiving a message, again we believe t hat we should have the above relation. The clock value C must go forward. Correction of a time is achieved through adding a positive number. Lamport proposed how to assign time to events.

OS2- Sem , R. Jalili Lamport Timestamps a)Three processes, each with its own clock. The clocks run at different rates. b)Lamport's algorithm corrects the clocks.

OS2- Sem , R. Jalili Logical Clocks Rules for assignment of the time values: If A happens before B in the same process, then C(A) < C(B) If A and B represent the sending and receiving of a message, C(A) < C(B) For distinctive events, C(A) is irrelevant to C(B)

OS2- Sem , R. Jalili Example: Totally-Ordered Multicasting Updating a replicated database and leaving it in an inconsistent state.

OS2- Sem , R. Jalili Totally-Ordered Multicasting Assume that msgs are multicast. When a process receives a msg, it broadcast an ack. Eventually all processes have the same queue, including msgs and acks. A process can deliver a queued msg to its application when it is acked by all processes. As all processes have the same queue, the order is guaranteed.

OS2- Sem , R. Jalili Vector Timestamp Lamport clock guarantees a total order of events while they the happened-before relation. –A  B  C(A) < C(B) However, if C(A) < C(B) then either A  B or B  A or A || B !!! What we have is the time values of the events, not their relations In fact, Lamport timestamps do not capture causality. If I have received an event, I am not sure if I have received its cause.

OS2- Sem , R. Jalili Vector Timestamp Each event is assigned a VT(A) to en event A. VT(A) < VT (B)  A  B Example: chained s or news Each process maintains a V as its vector clock. –V i [i] is the # of events had occurred at Pi, so each event is happened in Pi, Vi[i] is incremented. –Vi[j] is the # events occurred at Pj, based on Pi knowledge: this property is maintained by piggybacking vectors along messages. vt (m) says how many events at other processes have taken place before Pi sent m. Thus causality of m to those events can be specified.

OS2- Sem , R. Jalili Vector Timestamp The definition of < Upgrade: –When Pi receives m, it adjusts its own vector: Vj[k] = max {Vj[k], vt(m)[k]} Vi[i] is incremented by 1 Msg is deliverable from Pj in Pk, iff –Vt( r)[j] = Vk[j] +1 –Vt (r )[i] ≤ Vk[i] for all i≠ j.

OS2- Sem , R. Jalili Global State (1) Relationship of cuts to vt

OS2- Sem , R. Jalili Global State (2) a)Organization of a process and channels for a distributed snapshot

OS2- Sem , R. Jalili Global State (3) b)Process Q receives a marker for the first time and records its local state c)Q records all incoming message d)Q receives a marker for its incoming channel and finishes recording the state of the incoming channel

OS2- Sem , R. Jalili Application The termination detection

OS2- Sem , R. Jalili Election Algorithms Requirement for the coordinator. Assume that processes can be distinguished somehow; through their MAC address, … Assume that any process knows the process# of all other processes and if they are up or down currently. Various algorithms including Bully alg. By Garcia- Molina When a process notices that the coordinator no longer responding to requests, it initiates the alg.

OS2- Sem , R. Jalili Bully Alg. 1.P sends an ELECTION to all with higher id# 2.If no one responds, P wins the election and becomes the coordinator. 3.If one of the higher id#’s responds, it takes over. At any moment, a process can get an ELECTION msg from its lower id# colleagues. The winner announces its victory by sending a msg announcing its leadership. The biggest guy in town wins!  Bully alg!

OS2- Sem , R. Jalili The Bully Algorithm (2) 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

OS2- Sem , R. Jalili The Bully Algorithm(3) d)Process 6 tells 5 to stop e)Process 6 wins and tells everyone

OS2- Sem , R. Jalili A Ring Algorithm This alg. is based on ring without token. Assume that processes are physically or logically ordered. Each process knows its successor. To start, a process sends its id# inside the ELECTION msg to its successor. If it is down, the next one is selected to send to. At each intermediate node, the list of id#s is expanded, so the new ring is introduced. When the initiator received the msg including its id#, it circulated the msg announcing itself as coordinator. Two concurrent initiation!!

OS2- Sem , R. Jalili A Ring Algorithm Election algorithm using a ring.

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

OS2- Sem , R. Jalili A Distributed Algorithm a)Two processes want to enter the same critical region at the same moment. b)Process 0 has the lowest timestamp, so it wins. c)When process 0 is done, it sends an OK also, so 2 can now enter the critical region.

OS2- Sem , R. Jalili A Token Ring Algorithm a)An unordered group of processes on a network. b)A logical ring constructed in software. Process 0 has the token. Token lost!!

OS2- Sem , R. Jalili 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