Advanced Topics in Distributed Systems. Dr. Ayman A. Abdel-Hamid. Computer Science Department Virginia Tech

Similar documents
Chapter 6 Synchronization

CSE 5306 Distributed Systems. Synchronization

CSE 5306 Distributed Systems

SYNCHRONIZATION. DISTRIBUTED SYSTEMS Principles and Paradigms. Second Edition. Chapter 6 ANDREW S. TANENBAUM MAARTEN VAN STEEN

Clock Synchronization. Synchronization. Clock Synchronization Algorithms. Physical Clock Synchronization. Tanenbaum Chapter 6 plus additional papers

Time in Distributed Systems

Distributed Coordination 1/39

Synchronization. Clock Synchronization

Distributed Synchronization. EECS 591 Farnam Jahanian University of Michigan

Verteilte Systeme (Distributed Systems)

殷亚凤. Synchronization. Distributed Systems [6]

Synchronization. Chapter 5

Synchronization Part 1. REK s adaptation of Claypool s adaptation of Tanenbaum s Distributed Systems Chapter 5

ICT 6544 Distributed Systems Lecture 7

Last Class: Naming. Today: Classical Problems in Distributed Systems. Naming. Time ordering and clock synchronization (today)

Mutual Exclusion. A Centralized Algorithm

PROCESS SYNCHRONIZATION

Synchronization. Distributed Systems IT332

CS 455: INTRODUCTION TO DISTRIBUTED SYSTEMS [DISTRIBUTED MUTUAL EXCLUSION] Frequently asked questions from the previous class survey

Chapter 6 Synchronization (1)

Clock and Time. THOAI NAM Faculty of Information Technology HCMC University of Technology

CS455: Introduction to Distributed Systems [Spring 2018] Dept. Of Computer Science, Colorado State University

Time Synchronization and Logical Clocks

Frequently asked questions from the previous class survey

CS455: Introduction to Distributed Systems [Spring 2018] Dept. Of Computer Science, Colorado State University

Distributed Systems COMP 212. Lecture 17 Othon Michail

Last Class: Clock Synchronization. Today: More Canonical Problems

CS555: Distributed Systems [Fall 2017] Dept. Of Computer Science, Colorado State University

Synchronization Part 2. REK s adaptation of Claypool s adaptation oftanenbaum s Distributed Systems Chapter 5 and Silberschatz Chapter 17

Process groups and message ordering

Clock-Synchronisation

Distributed Systems. coordination Johan Montelius ID2201. Distributed Systems ID2201

Distributed Systems Exam 1 Review. Paul Krzyzanowski. Rutgers University. Fall 2016

OUTLINE. Introduction Clock synchronization Logical clocks Global state Mutual exclusion Election algorithms Deadlocks in distributed systems

DISTRIBUTED MUTEX. EE324 Lecture 11

Process Synchroniztion Mutual Exclusion & Election Algorithms

Distributed Operating Systems. Distributed Synchronization

Coordination 1. To do. Mutual exclusion Election algorithms Next time: Global state. q q q

Synchronization Part II. CS403/534 Distributed Systems Erkay Savas Sabanci University

Synchronisation in. Distributed Systems. Co-operation and Co-ordination in. Distributed Systems. Kinds of Synchronisation. Clock Synchronization

Event Ordering. Greg Bilodeau CS 5204 November 3, 2009

Coordination and Agreement

TIME ATTRIBUTION 11/4/2018. George Porter Nov 6 and 8, 2018

2. Time and Global States Page 1. University of Freiburg, Germany Department of Computer Science. Distributed Systems

Multi-threaded programming in Java

Arranging lunch value of preserving the causal order. a: how about lunch? meet at 12? a: <receives b then c>: which is ok?

wait with priority An enhanced version of the wait operation accepts an optional priority argument:

Advanced Topics in Distributed Systems. Dr. Ayman A. Abdel-Hamid. Computer Science Department Virginia Tech

CSE 124: LAMPORT AND VECTOR CLOCKS. George Porter October 30, 2017

Coordination 2. Today. How can processes agree on an action or a value? l Group communication l Basic, reliable and l ordered multicast

Distributed Systems Principles and Paradigms

Large Systems: Design + Implementation: Communication Coordination Replication. Image (c) Facebook

Selected Questions. Exam 2 Fall 2006

CSE 486/586 Distributed Systems


CSE 380 Computer Operating Systems

Distributed Systems Synchronization

Distributed Coordination! Distr. Systems: Fundamental Characteristics!

Distributed Systems Exam 1 Review Paul Krzyzanowski. Rutgers University. Fall 2016

Distributed Systems. Clock Synchronization: Physical Clocks. Paul Krzyzanowski

Chapter 6 Synchronization (2)

Distributed Systems. Pre-Exam 1 Review. Paul Krzyzanowski. Rutgers University. Fall 2015

Lecture 7: Logical Time

Several of these problems are motivated by trying to use solutiions used in `centralized computing to distributed computing

Important Lessons. A Distributed Algorithm (2) Today's Lecture - Replication

Lecture 10: Clocks and Time

Parallel and Distributed Systems. Programming Models. Why Parallel or Distributed Computing? What is a parallel computer?

Time Synchronization and Logical Clocks

Network Protocols. Sarah Diesburg Operating Systems CS 3430

Synchronization (contd.)

Data Link Layer, Part 5 Sliding Window Protocols. Preface

Failure Tolerance. Distributed Systems Santa Clara University

Lecture 6: Logical Time

Lecture 12: Time Distributed Systems

Time. COS 418: Distributed Systems Lecture 3. Wyatt Lloyd

Last Class: Naming. DNS Implementation

Outline. CS5984 Mobile Computing

Coordination and Agreement

Coordination and Agreement

Distributed Systems. 05. Clock Synchronization. Paul Krzyzanowski. Rutgers University. Fall 2017

Distributed Mutual Exclusion

2017 Paul Krzyzanowski 1

Algorithms and protocols for distributed systems

Distributed systems. Lecture 6: distributed transactions, elections, consensus and replication. Malte Schwarzkopf

CS 417: the one-hour study guide for exam 2

DISTRIBUTED REAL-TIME SYSTEMS

Homework #2 Nathan Balon CIS 578 October 31, 2004

TDDD82 Secure Mobile Systems Lecture 1: Introduction and Distributed Systems Models

Chapter 8 Fault Tolerance

Fault Tolerance Part II. CS403/534 Distributed Systems Erkay Savas Sabanci University

CMPSCI 677 Operating Systems Spring Lecture 14: March 9

Event Ordering Silberschatz, Galvin and Gagne. Operating System Concepts

CprE Fault Tolerance. Dr. Yong Guan. Department of Electrical and Computer Engineering & Information Assurance Center Iowa State University

The flow of data must not be allowed to overwhelm the receiver

How Bitcoin achieves Decentralization. How Bitcoin achieves Decentralization

Tasks. Task Implementation and management

Implementing a NTP-Based Time Service within a Distributed Middleware System

CS Final Review

Verteilte Systeme/Distributed Systems Ch. 5: Various distributed algorithms

Last Class: Clock Synchronization. Today: More Canonical Problems

Transcription:

Advanced Topics in Distributed Systems Dr. Ayman A. Abdel-Hamid Computer Science Department Virginia Tech Synchronization (Based on Ch6 in Distributed Systems: Principles and Paradigms, 2/E) Synchronization Dr. Ayman Abdel-Hamid, CS6204, Sp08 1 Clock Synchronization Physical clocks Logical clocks Mutual exclusion Election algorithms Outline Synchronization Dr. Ayman Abdel-Hamid, CS6204, Sp08 2 1

Clock Synchronization Time in a centralized system Lack of global time agreement in a distributed system Implications? Physical clocks Logical clocks Synchronization Dr. Ayman Abdel-Hamid, CS6204, Sp08 3 Physical clocks 1/2 Timer (counter and holding register) Clock tick Date and time entered after booting converted to the number of ticks after some known starting date and stored in memory Battery-backed up CMOS RAM With every clock tick ISR adds 1 to time stored in memory Multiple CPUs clock skew Synchronization Dr. Ayman Abdel-Hamid, CS6204, Sp08 4 2

Physical clocks 2/2 Astronomers (Transit of the sun and mean solar second because days are getting longer) Physicists Atomic clock in 1948 transitions of the cesium 133 atom Atomic second = mean solar second Time it takes cesium 133 atom to make 9,192,631,770 transitions International Atomic Time (TAI) Mean number of ticks of cesium 133 clocks since midnight on Jan, 1, 1958 divided by 9,192,631,770 86,400 TAI seconds is now about 3 msec less than a mean solar day Introduce leap seconds whenever discrepancy between TAI and solar time grows to 800 msec Universal coordinated time (UTC) Synchronization Dr. Ayman Abdel-Hamid, CS6204, Sp08 5 Getting Time from a Time Server ( T2 T1 ) + ( T4 T3 ) A s offset relative to B = θ θ = T3 2 NTP buffers eight pairs of (θ,delay) selecting minimal delay Synchronization Dr. Ayman Abdel-Hamid, CS6204, Sp08 6 3

Lamport s Logical Clocks 1/5 To synchronize logical clocks (need to agree on order of events, but not exact time) 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 If a b, then C(a) < C(b) where C(i) is a time value Synchronization Dr. Ayman Abdel-Hamid, CS6204, Sp08 7 Lamport s Logical Clocks 2/5 Figure 6-9. (a) Three processes, each with its own clock. The clocks run at different rates. Synchronization Dr. Ayman Abdel-Hamid, CS6204, Sp08 8 4

Lamport s Logical Clocks 3/5 Figure 6-9. (b) Lamport s algorithm corrects the clocks. Synchronization Dr. Ayman Abdel-Hamid, CS6204, Sp08 9 Lamport s Logical Clocks 4/5 Figure 6-10. The positioning of Lamport s logical clocks in distributed systems. Synchronization Dr. Ayman Abdel-Hamid, CS6204, Sp08 10 5

Lamport s Logical Clocks 5/5 Updating counter C i for process P i 1. Before executing an event, P i executes C i C i + 1. 2. When process P i sends a message m to P j, it sets m s timestamp ts(m) equal to C i after having executed the previous step. 3. Upon the receipt of a message m, process P j adjusts its own local counter as C j max{c j, ts (m)}, after which it then executes the first step and delivers the message to the application. Synchronization Dr. Ayman Abdel-Hamid, CS6204, Sp08 11 Example: Totally Ordered Multicasting Message timestamped with current logical time of sender Receiver multicasts an ACK to other processes Deliver message when at head of queue and has been ACKed by each other process Synchronization Dr. Ayman Abdel-Hamid, CS6204, Sp08 12 6

If C(a) < C(b) does not imply that a happened before b? T rcv (m 1 ) < T snd (m 2 ) Sending m 2 has nothing to do with receipt of m 1 Lamport clocks do not capture causality Need for vector clocks Vector Clocks 1/3 Figure 6-12. Concurrent message transmission using logical clocks. Synchronization Dr. Ayman Abdel-Hamid, CS6204, Sp08 13 Vector Clocks 2/3 Vector clocks are constructed by letting each process P i maintain a vector VC i with the following two properties: 1. VC i [ i ] is the number of events that have occurred so far at P i. In other words, VC i [ i ] is the local logical clock at process P i. 2. If VC i [ j ] = k then P i knows that k events have occurred at P j. It is thus P i s knowledge of the local time at P j. Synchronization Dr. Ayman Abdel-Hamid, CS6204, Sp08 14 7

Vector Clocks 3/3 Steps carried out to accomplish property 2 of previous slide: 1. Before executing an event P i executes VC i [ i ] VC i [i ] + 1. 2. When process P i sends a message m to P j, it sets m s (vector) timestamp ts(m) equal to VC i after having executed the previous step. 3. Upon the receipt of a message m, process P j adjusts its own vector by setting VC j [k ] max{vc j [k ], ts (m)[k ]} for each k, after which it executes the first step and delivers the message to the application. Synchronization Dr. Ayman Abdel-Hamid, CS6204, Sp08 15 Enforcing Causal Communication 1/2 Causally-ordered communication weaker than totally-ordered communication P j receives a message m from P i with vector timestamp ts(m) Delivery of message to application layer delayed until 2 conditions met ts(m)[i]=vc j [i]+1 m is next message P j expects from P i ts(m)[k]<= VC j [k] for all k!= i P j has seen all the messages that have been seen by P i when it sent message m Synchronization Dr. Ayman Abdel-Hamid, CS6204, Sp08 16 8

Enforcing Causal Communication 2/2 Figure 6-13. Enforcing causal communication. Synchronization Dr. Ayman Abdel-Hamid, CS6204, Sp08 17 Distributed Mutual Exclusion Token-based solutions One token Whoever has the token, can access the shared resource When finished, pass token to next resource Avoids starvation an deadlock A problem if token is lost Permission-based solutions Ask for permission first Synchronization Dr. Ayman Abdel-Hamid, CS6204, Sp08 18 9

Mutual Exclusion: A Centralized Algorithm 1/3 Figure 6-14. (a) Process 1 asks the coordinator for permission to access a hared resource. Permission is granted. Synchronization Dr. Ayman Abdel-Hamid, CS6204, Sp08 19 Mutual Exclusion: A Centralized Algorithm 2/3 Figure 6-14. (b) Process 2 then asks permission to access the same resource. The coordinator does not reply. Synchronization Dr. Ayman Abdel-Hamid, CS6204, Sp08 20 10

Mutual Exclusion: A Centralized Algorithm 3/3 Figure 6-14. (c) When process 1 releases the resource, it tells the coordinator, which then replies to 2. Synchronization Dr. Ayman Abdel-Hamid, CS6204, Sp08 21 A Distributed Algorithm 1/6 Assume total ordering of all events in the system When access a shared resource Build a message (resource name, process number, and current logical time Send message to all other processes, including itself When process receives a request Action depends on own state with respect to resource in message 3 different cases Synchronization Dr. Ayman Abdel-Hamid, CS6204, Sp08 22 11

A Distributed Algorithm 2/6 Three different cases: 1. If the receiver is not accessing the resource and does not want to access it, it sends back an OK message to the sender. 2. If the receiver already has access to the resource, it simply does not reply. Instead, it queues the request. 3. If the receiver wants to access the resource as well but has not yet done so, it compares the timestamp of the incoming message with the one contained in the message that it has sent everyone. The lowest one wins. Synchronization Dr. Ayman Abdel-Hamid, CS6204, Sp08 23 A Distributed Algorithm 3/6 After sending out asking for permissions Sit back and wait until everyone has given permission After finished send OK to all processes on its queue and delete from queue Synchronization Dr. Ayman Abdel-Hamid, CS6204, Sp08 24 12

A Distributed Algorithm 4/6 Figure 6-15. (a) Two processes want to access a shared resource at the same moment. Synchronization Dr. Ayman Abdel-Hamid, CS6204, Sp08 25 A Distributed Algorithm 5/6 Figure 6-15. (b) Process 0 has the lowest timestamp, so it wins. Synchronization Dr. Ayman Abdel-Hamid, CS6204, Sp08 26 13

A Distributed Algorithm 6/6 Figure 6-15. (c) When process 0 is done, it sends an OK also, so 2 can now go ahead. Synchronization Dr. Ayman Abdel-Hamid, CS6204, Sp08 27 A Token Ring Algorithm Figure 6-16. (a) An unordered group of processes on a network. (b) A logical ring constructed in software. Synchronization Dr. Ayman Abdel-Hamid, CS6204, Sp08 28 14