Time. To do. q Physical clocks q Logical clocks

Similar documents
Time. Today. l Physical clocks l Logical clocks

Agreement. Today. l Coordination and agreement in group communication. l Consensus

Distributed Computing. Synchronization. Dr. Yingwu Zhu

Clock Synchronization

Chapter 11 Time and Global States

Time in Distributed Systems: Clocks and Ordering of Events

Distributed Systems Principles and Paradigms. Chapter 06: Synchronization

Distributed Systems Principles and Paradigms

DISTRIBUTED COMPUTER SYSTEMS

CS505: Distributed Systems

Distributed systems Lecture 4: Clock synchronisation; logical clocks. Dr Robert N. M. Watson

Slides for Chapter 14: Time and Global States

Absence of Global Clock

Clocks in Asynchronous Systems

CS505: Distributed Systems

Time is an important issue in DS

7680: Distributed Systems

Distributed Systems 8L for Part IB

416 Distributed Systems. Time Synchronization (Part 2: Lamport and vector clocks) Jan 27, 2017

CS 425 / ECE 428 Distributed Systems Fall Indranil Gupta (Indy) Oct. 5, 2017 Lecture 12: Time and Ordering All slides IG

Distributed Systems. 06. Logical clocks. Paul Krzyzanowski. Rutgers University. Fall 2017

Distributed Systems. Time, Clocks, and Ordering of Events

Logical Time. 1. Introduction 2. Clock and Events 3. Logical (Lamport) Clocks 4. Vector Clocks 5. Efficient Implementation

CptS 464/564 Fall Prof. Dave Bakken. Cpt. S 464/564 Lecture January 26, 2014

Time, Clocks, and the Ordering of Events in a Distributed System

Distributed Systems Time and Global State

C 1. Recap: Finger Table. CSE 486/586 Distributed Systems Consensus. One Reason: Impossibility of Consensus. Let s Consider This

Clock Synchronization

Our Problem. Model. Clock Synchronization. Global Predicate Detection and Event Ordering

Distributed Systems. Time, clocks, and Ordering of events. Rik Sarkar. University of Edinburgh Spring 2018

Causality and physical time

Consistent Global States of Distributed Systems: Fundamental Concepts and Mechanisms. CS 249 Project Fall 2005 Wing Wong

Today. Vector Clocks and Distributed Snapshots. Motivation: Distributed discussion board. Distributed discussion board. 1. Logical Time: Vector clocks

Do we have a quorum?

Chandy-Lamport Snapshotting

Distributed Algorithms Time, clocks and the ordering of events

Figure 10.1 Skew between computer clocks in a distributed system

CS 347 Parallel and Distributed Data Processing

Distributed Mutual Exclusion Based on Causal Ordering

Agreement Protocols. CS60002: Distributed Systems. Pallab Dasgupta Dept. of Computer Sc. & Engg., Indian Institute of Technology Kharagpur

Integrating External and Internal Clock Synchronization. Christof Fetzer and Flaviu Cristian. Department of Computer Science & Engineering

Cuts. Cuts. Consistent cuts and consistent global states. Global states and cuts. A cut C is a subset of the global history of H

A subtle problem. An obvious problem. An obvious problem. An obvious problem. No!

Recap. CS514: Intermediate Course in Operating Systems. What time is it? This week. Reminder: Lamport s approach. But what does time mean?

MAD. Models & Algorithms for Distributed systems -- 2/5 -- download slides at

Causality and Time. The Happens-Before Relation

Coordination. Failures and Consensus. Consensus. Consensus. Overview. Properties for Correct Consensus. Variant I: Consensus (C) P 1. v 1.

CS5412: REPLICATION, CONSISTENCY AND CLOCKS

Distributed Systems Fundamentals

Time. Lakshmi Ganesh. (slides borrowed from Maya Haridasan, Michael George)

Distributed Algorithms (CAS 769) Dr. Borzoo Bonakdarpour

1 Introduction During the execution of a distributed computation, processes exchange information via messages. The message exchange establishes causal

6.852: Distributed Algorithms Fall, Class 24

Failure detectors Introduction CHAPTER

6.852: Distributed Algorithms Fall, Class 10

Real-Time Course. Clock synchronization. June Peter van der TU/e Computer Science, System Architecture and Networking

Reliable Broadcast for Broadcast Busses

Snapshots. Chandy-Lamport Algorithm for the determination of consistent global states <$1000, 0> <$50, 2000> mark. (order 10, $100) mark

Shared Memory vs Message Passing

1 Introduction During the execution of a distributed computation, processes exchange information via messages. The message exchange establishes causal

Implementing Uniform Reliable Broadcast with Binary Consensus in Systems with Fair-Lossy Links

Verification of clock synchronization algorithm (Original Welch-Lynch algorithm and adaptation to TTA)

Consensus when failstop doesn't hold

CIS 4930/6930: Principles of Cyber-Physical Systems

Causal Broadcast Seif Haridi

Lecture 8: Time & Clocks. CDK: Sections TVS: Sections

Accurate Event Composition

Seeking Fastness in Multi-Writer Multiple- Reader Atomic Register Implementations

Causal Consistency for Geo-Replicated Cloud Storage under Partial Replication

Degradable Agreement in the Presence of. Byzantine Faults. Nitin H. Vaidya. Technical Report #

arxiv: v1 [cs.dc] 22 Oct 2018

Towards optimal synchronous counting

CS505: Distributed Systems

Real Time Operating Systems

Early consensus in an asynchronous system with a weak failure detector*

TTA and PALS: Formally Verified Design Patterns for Distributed Cyber-Physical

Early stopping: the idea. TRB for benign failures. Early Stopping: The Protocol. Termination

Chapter 7 HYPOTHESIS-BASED INVESTIGATION OF DIGITAL TIMESTAMPS. 1. Introduction. Svein Willassen

Using Happens-Before Relationship to debug MPI non-determinism. Anh Vo and Alan Humphrey

AGREEMENT PROBLEMS (1) Agreement problems arise in many practical applications:

Consensus and Universal Construction"

Distributed Algorithms

Ordering Events Based on Intentionality in Cyber-Physical Systems

Distributed Consensus

Multicore Semantics and Programming

Causality & Concurrency. Time-Stamping Systems. Plausibility. Example TSS: Lamport Clocks. Example TSS: Vector Clocks

Gradient Clock Synchronization

Genuine atomic multicast in asynchronous distributed systems

The Weakest Failure Detector to Solve Mutual Exclusion

TSCCLOCK: A LOW COST, ROBUST, ACCURATE SOFTWARE CLOCK FOR NETWORKED COMPUTERS

DEXON Consensus Algorithm

Overview: Synchronous Computations

Rollback-Recovery. Uncoordinated Checkpointing. p!! Easy to understand No synchronization overhead. Flexible. To recover from a crash:

Section 6 Fault-Tolerant Consensus

Clojure Concurrency Constructs, Part Two. CSCI 5828: Foundations of Software Engineering Lecture 13 10/07/2014

Rollback-Dependency Trackability: A Minimal Characterization and Its Protocol

Efficient Dependency Tracking for Relevant Events in Concurrent Systems

Distributed Computing in Shared Memory and Networks

Time Synchronization

Valency Arguments CHAPTER7

Transcription:

Time To do q Physical clocks q Logical clocks

Events, process states and clocks A distributed system A collection P of N single-threaded processes (p i, i = 1,, N) without shared memory The processes in P communicate via message exchanges p 1 p p Each process p i has a state s i (that transforms as it executes) executes a series of actions send, receive, transform state Event The execution of a single action The sequence of events signifies the flow of information and establishes causal dependencies across the system To detect deadlocks, build a checkpoint, do garbage collection

Events, process states and clocks Event histories All events in a process can be place in a total ordering i e i e iff e is an event that occurs after e in p i History of a process p i history(p i ) = h i =< e i,e i 1,e i,... > How do we order the history of multiple processes? In the outside world, using clocks Keep clocks in different machines synchronized Timestamp all events in all histories

Events, process states and clocks Within a single process, we can order its events, but how can we timestamp them? Computers have their own hardware-based clock, C i, which can be used to assign timestamps to events Clock is based on a counting of oscillation of a crystal at a given frequency stored in some register, say H i OS reads value H i, scales it (x α) and adds an offset (β) to compute a software clock (H i (t) is value of H i at time t) C i (t) = α H i (t) + β

Events, process states and clocks Clocks tend to drift and do so a different rates Clock drift Clocks oscillators are subject to physical variations that makes them drift from each other Drift rate Change in the offset between a clock and a nominal perfect reference clock per unit of time For common quartz-crystal based clocks, ~1-6 sec/sec or 1 second every 11.6 days Skew Instantaneous difference between the readings of two clocks Clock time (C) Real time (t) 5

Physical clocks From solar to atomic time Before, time was measured astronomically (solar time) Since 1967, atomic clocks based on number of transitions/sec of cesium 1 atom Drift rate of one part in 1 1 Universal Coordinated Time (UTC) Currently, real time is avg of ~5 cesium-clocks Since days are getting longer, add leap second to keep it in synch with astronomical time Broadcast through short wave radio (WWV in the US) and satellite (GPS) Bathys Cesium 1 watch $6, kickstarter 6

Ordering and clock synchronization To order distributed events, keep clocks in different machines synchronized We want to distribute this to the set of machines Each runs its own timer, keeping a clock C p (t) (t being UTC) Given a maximum drift rate r (1 r dc/dt 1+ r) To never let two clocks differ by more than δ synchronize at least every δ/(r) seconds 7

Clock synchronization Two synchronization modes Internal Clocks must agree within a bound δ C i (t) C j (t) < δ for i, j = 1,,.. N External Clocks must be accurate respect to a UTC source within a bound δ S(t) C j (t) < δ for i = 1,,.. N Internally synchronized > externally synchronized But if the system is externally synchronized with bound δ, it is internally synchronized with bound δ 8

Correctness of clocks Correctness of a hardware clock H If drift rate < known bound r, error in measuring the time interval between real time t and t is bounded (1 r)(t t) H(t ) H(t) (1+r)(t t) For software clocks, a weaker rule may suffice If it satisfies monotonicity t > t => C(t ) > C(t) We can still adjust clocks changing α and β in C i (t) = αh i(t) + β 9

Correctness of clocks A hybrid condition, Monotonicity and Drift rate is bounded between synchronization points, but can jump ahead at those points Otherwise, a faulty clock A clock s crash failure clock stops ticking altogether Any other failure is an arbitrary failure (e.g., YK bug, from 1999 to 19!) Note that clocks don t have to be accurate to be correct 1

Clock synchronization External Cristian s approach (1989) A time server gets signal from a UTC source Others ask server for accurate time with some periodicity While asynchronous, rtts are typically short Must estimate rtt, including interrupt handling, msg processing Cristian describes the algorithm as probabilistic 11

Clock synchronization External Setting the time based on source Set time to t + T round / (timestamp of the message) (time to get back) Accuracy, assuming min RTT can be estimated Earliest time t+min, latest time t+t round min Width T round min, so accuracy is ±(T round / min) Issues with Cristian s approach Single server, single point of failure Cristian s suggestion: a group of synchronized servers Faulty server, not Cristian s problem If f is the number of faulty clocks out of N, you need N >f clocks for the others to achieve agreement 1

Clock synchronization Internal Berkeley s algorithm by Gusella and Zatti (1989) A coordinator computer, master, periodically polls other machines : Master calculates a fault-tolerant avg after adjusting for transfer time Average is computed among clocks that don t differ from the others by more than some given amount Tells all how to adjust their clocks (+/-) :5 +5 :5 +15-1

Clock synchronization External For Internet synchronization - Network Time Protocol (NTP, Mills 1995) A logical hierarchy of servers Primary servers directly connected to time sources Secondary servers synchronized with others servers The logical hierarchy synchronization subnet Servers synchronize with others in one of three modes Multicast For fast LANs Procedure-call ~Cristian s, for higher synch or when there s no multicast Symmetric Pair of machines exchanged msgs with timing info All over UDP Primary servers 1 Strata 1 Strata 1

Back in 5 15

Logical clocks We typically assume clock synchronization is related to real time, not necessarily We have seen (Berkeley algorithm) clocks can agree on a current time without this having to be the real time Actually In many situations all that matters is that two nodes agree on the order of events If two nodes do not shared events, i.e. they don t interact, they don t have to be in synch è Logical clocks 16

What s all this for? Causality The causal precedence relation induces a partial order on the events of a distributed computation If clocks were synchronized, you could infer (potential) causality With that knowledge Ensure liveness and fairness in mutual exclusion Maintain consistency in replicas Build a deadlock-detection algorithm Build a consistent state / snapshot 17

Events in a distributed system Physical time p 1 a b m 1 g m m p c d f m p e A collection P of N single-threaded processes (p i ) Communicating through message exchange Each process p i has a state s i (that transforms as it executes) executes a series of actions send, receive, transform state An event the execution of a single action 18

Happened-before relationship p 1 a b a b b c m 1 g m m Physical time p c a c d f m p e The happened-before (or [potential] causal precedence) relation on the set of events in a distributed system: HB1: If a and b are two events in the same process, and a comes before b, then a b HB: If a is the sending of a message, and b is the event of receiving that message, then a b HB: If a b and b c, then a c 19

Happened-before relationship notes This introduces a partial ordering of events in a system with concurrently operating processes If x and y happen in two processes that do not exchange messages, then neither x y nor y x x and y are concurrent, x y So, for any two events x and y, x y, y x or x y What happen with communication through other channels? e.g., phone If x y, does it mean x cause y?

Lamport clock How to maintain a global view on system s behavior that is consistent with the happened before relation? Attach a timestamp C(e) to each event e, so that: 1. If a and b are events in the same process, if a b, then C(a) < C(b). If a corresponds to sending a msg m, and b to receiving it, then C(a) < C(b) a b C(a) < C(b) Monotonicity property clock consistency condition How to attach a timestamp to an event when there s no global clock maintain a consistent set of logical clocks, one per process 1

Lamport clock Each process p i maintains a local counter C i and adjusts this counter according to the following rules: 1. For any two successive events that take place within p i, C i is incremented by d (let s say d = 1). When p i sends a message m i, it includes a timestamp ts(m) = C i. Whenever p j receives m, p j adjusts its local counter C j to max(c j, ts(m)); then executes step 1 before passing m to the application Property 1 is satisfied by (1) Property by () and () Note: From partial to total ordering, attach process ID Since they are not causally related you can order them using any criteria without impacting

Lamport timestamps an example p 1 1 8 9 Physical time p 1 5 1 11 p 1 5 6 7

From Lamport to vector clocks With Lamport s clocks if x y, C(x) < C(y), but if C(x) < C(y), we can t infer x y No strongly consistent Why? Local and global clocks are all squashed into one, loosing all causal dependency info among events at different processes C(g) < C(d) but does g d? p 1 1 g 8 9 Physical time p 1 d 5 1 11 p 1 5 6 7 When p receives m 1, it forgets the timestamp of the latest event at p 1 on which d depends ()

Vector clocks Vector clock for a system with N processes An array of N integers Processes piggyback vector timestamps on each message Rules for updating clocks Just before p i sends a message m, 1. It adds 1 to V i [i], and. Sends V i along with m as vector timestamp vt(m) When a p j receives a message m with vector timestamp ts(m), it 1. updates each V j [k] to max{v j [k], ts(m)[k]} for k = 1 N. increments V j [j] by 1 5

Vector clocks an example 6 p 1 p p Physical time 1 1 1 5 5 5 5 6 g d

Vector clocks For process p i with vector V i [1..n], V i [i] number of events that have taken place at process p i V i [j] number of events that p i knows have taken place at process p j (i.e., that have potentially affected p i ) Comparing vector timestamps V = V iff V[j] = V [j] for j = 1.. N V V iff V[j] V [j] for j = 1.. N If not (V < V ) and not (V > V ) (i.e., sometimes V[j] > V [j] and sometimes smaller) then V V If events x and y occurred at p i and p j with vectors V and V x y ó V[i] < V [i] Otherwise x y 7

1 Vector clocks an example 8 a i, so V a V i (1,,) (,,) g d, since V g V d nor V d V g [,,] [,,] p 1 p p Physical time 1 1 5 5 5 5 6 g d a i

More on logical clocks The topic doesn t end there Matrix times, everybody knows what everyone else knew when they sent a message Useful, for instance, to discard obsolete info in replicated DB How to efficiently implement logical clocks? Example send only updates, but have to keep an additional vector with what you knew in the last exchange 9

Summary Synchronization is about doing the right thing at the right time What s the right time? An issue when you don t share clocks