Synchronization Chapter 5.

Slides:



Advertisements
Similar presentations
Synchronization Chapter clock synchronization * 5.2 logical clocks * 5.3 global state * 5.4 election algorithm * 5.5 mutual exclusion * 5.6 distributed.
Advertisements

Distributed Computing
Page 1 Mutual Exclusion* Distributed Systems *referred to slides by Prof. Paul Krzyzanowski at Rutgers University and Prof. Mary Ellen Weisskopf at University.
Tanenbaum & Van Steen, Distributed Systems: Principles and Paradigms, 2e, (c) 2007 Prentice-Hall, Inc. All rights reserved DISTRIBUTED.
Distributed Systems Spring 2009
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.
Centralized Architectures
Synchronization in Distributed Systems. Mutual Exclusion To read or update shared data, a process should enter a critical region to ensure mutual exclusion.
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.
Clock Synchronization and algorithm
Tanenbaum & Van Steen, Distributed Systems: Principles and Paradigms, 2e, (c) 2007 Prentice-Hall, Inc. All rights reserved DISTRIBUTED SYSTEMS.
Lecture 14 Synchronization (cont). EECE 411: Design of Distributed Software Applications Logistics Project P01 deadline on Wednesday November 3 rd. Non-blocking.
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 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.
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.
Distributed Mutex EE324 Lecture 11.
Tanenbaum & Van Steen, Distributed Systems: Principles and Paradigms, 2e, (c) 2007 Prentice-Hall, Inc. All rights reserved Chapter 6 Synchronization.
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.
1 Mutual Exclusion: A Centralized Algorithm a)Process 1 asks the coordinator for permission to enter a critical region. Permission is granted b)Process.
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.
Presenter: Long Ma Advisor: Dr. Zhang 4.5 DISTRIBUTED MUTUAL EXCLUSION.
Synchronization. Why we need synchronization? It is important that multiple processes do not access shared resources simultaneously. Synchronization in.
CSC 536 Lecture 1. Outline Synchronization Clock synchronization Logical clocks Lamport timestamps Vector timestamps Global states and distributed snapshot.
Synchronization Chapter 5. Outline 1.Clock synchronization 2.Logical clocks 3.Global state 4.Election algorithms 5.Mutual exclusion 6.Distributed transactions.
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.
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
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.
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.
6.2 Logical Clocks Kranthi Koya09/23/2015. Overview Introduction Lamport’s Logical Clocks Vector Clocks Research Areas Conclusion.
Distributed Mutual Exclusion Synchronization in Distributed Systems Synchronization in distributed systems are often more difficult compared to synchronization.
Synchronization Chapter 5. Clock Synchronization When each machine has its own clock, an event that occurred after another event may nevertheless be assigned.
Tanenbaum & Van Steen, Distributed Systems: Principles and Paradigms, 2e, (c) 2007 Prentice-Hall, Inc. All rights reserved DISTRIBUTED SYSTEMS.
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 Mutex EE324 Lecture 11.
DISTRIBUTED SYSTEMS Principles and Paradigms Second Edition ANDREW S
Distributed Systems CS
DISTRIBUTED SYSTEMS Principles and Paradigms Second Edition ANDREW S
Outline Distributed Mutual Exclusion Introduction Performance measures
Distributed Systems CS
Prof. Leonardo Mostarda University of Camerino
Distributed Systems CS
Outline Theoretical Foundations
Presentation transcript:

Synchronization Chapter 5

Chapter Outline Clock Synchronization Logical Clocks Mutual Exclusion Physical Clocks Clock synchronization algorithms Logical Clocks Lamport’s logical clock Vector clocks Mutual Exclusion A centralized algorithm A decentralized algorithm A distributed algorithm A token ring algorithm Election Algorithms Bully algorithm Ring algorithm

Why do we need to synchronize clocks? When each machine has its own clock, an event that occurred after another event may nevertheless be assigned an earlier time.

Why do we need to synchronize clocks? Inconsistency due to incorrect ordering of events

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

Getting the current time from a time server. Network Time Protocol B T2 T3 A T1 T4 DTreq DTres Offset θ = T3 + ((T2 – T1) + (T4 – T3))/2 – T4 = ((T2 – T1) + (T3-T4))/2 Getting the current time from a time server.

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

Logical Clocks Sufficient for two processes to agree on the current time without the time being the same as the real time If two processes do not interact, it is not necessary for their clocks to be synchronized For synchronization, usually the ordering of events is more relevant than an agreement on time

Lamport’s Logical Clocks (1) The events are logically ordered by defining a relation happens-before as follows: 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. A message cannot be received before it is sent, or even at the same time it is sent.

Lamport’s Logical Clocks (2) For implementing Lamport’s logical clock, each process Pi maintains a local counter Ci. These counters are updated as follows: 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 receipt of a message m, process Pj adjusts 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

Lamport’s Logical Clocks (3) 6 12 18 24 30 36 42 48 54 60 66 8 16 24 32 40 48 56 64 72 80 88 10 20 30 40 50 60 70 80 90 100 110 6 12 18 24 30 36 42 48 70 76 82 8 16 24 32 40 48 61 69 77 85 93 10 20 30 40 50 60 70 80 90 100 110 Three processes each with its own clock b) Clocks after applying Lamport’s algorithm

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

Concurrent message transmission using logical clocks Why Vector Clocks? 6 12 18 24 30 36 42 48 70 76 82 8 16 24 32 40 48 61 69 77 85 93 10 20 30 40 50 60 70 80 90 100 110 m1 m2 m3 m4 m5 Concurrent message transmission using logical clocks

Vector Clocks (1) Vector clocks capture causality A vector clock VC(a) assigned to an event a has the property that if VC(a) < VC(b) for some event b, then event a is known to causally precede b. Vector clocks are implemented by letting each process Pi maintain a vector VCi With the following properties: VCi[i] is the number of events that have occurred so far at Pi. If VCi[j] = k then Pi knows that k events have occurred at Pj.

Vector Clocks (2) Vector clocks that satisfying the two properties are implemented as follows: Before executing an event Pi executes VCi → VCi + 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 receipt of a message m, process Pj adjusts its own local counter as VCj →max{VCj, ts(m)[k]} for each k, after which it executes the first step and delivers the message to the application

Enforcing Causal Communication Messages are delivered to the application only when all messages that causally precede it have been received as well Weaker model than totally ordered multicasting Clocks only adjusted only when sending and receiving messages While sending a message, a process Pi will only increment VCi[i] by 1 While receiving a message m with timestamp ts(m), it only adjusts VCi[k] to max{VCi[k], ts(m)[k]} for each k When a process Pj receives a message m from Pi with vector timestamp ts(m), the message will be delivered to the application only if ts(m)[i] = VCj[i] + 1 ts(m)[k] <= VCj[k] for all k ≠ i

Mutual Exclusion Concurrent accesses to resources may result in the shared resource to be in an inconsistent state Mutual exclusive access may be required to prevent inconsistencies. Algorithms for mutual exclusion can be broadly classified into Token-based: algorithms that use a token (i.e. a special message) Permission based: algorithms that require any process that needs access to a shared resource obtain the required permission from other processes

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

A decentralized Algorithm Assumptions: Each resource is replicated n times. Every replica has its own coordinator for controlling concurrent access. When a coordinator crashes it recovers but would have forgotten the vote it gave before it crashed When a process wants to access the resource, it will simply need to get a majority vote from m > n/2 coordinators.

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.

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

Messages per entry/exit Delay before entry (in message times) Comparison Algorithm Messages per entry/exit Delay before entry (in message times) Problems Centralized 3 2 Coordinator crash Decentralized 3mk, k=1,2,… 2m Starvation, low efficiency Distributed 2 ( n – 1 ) Crash of any process Token ring 1 to  0 to n – 1 Lost token, process crash A comparison of four mutual exclusion algorithms.

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

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

Election algorithm using a ring. A Ring Algorithm Election algorithm using a ring.

References Lecture slides of Distributed Systems principles and paradigms by Andrew Tannenbaum and Van Steen, Prentice Hall India, 2002.