Time in Distributed Systems

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

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

CSE 5306 Distributed Systems

Chapter 6 Synchronization (1)

Chapter 6 Synchronization

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

Distributed Coordination 1/39

CSE 5306 Distributed Systems. Synchronization

殷亚凤. Synchronization. Distributed Systems [6]

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)

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

Time Synchronization and Logical Clocks

Time Synchronization and Logical Clocks

Distributed Systems COMP 212. Lecture 17 Othon Michail

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

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

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

Verteilte Systeme (Distributed Systems)

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

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

Synchronization. Clock Synchronization

Clock-Synchronisation

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

Multi-threaded programming in Java

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

Lecture 7: Logical Time

Synchronization. Chapter 5

Last Class: Naming. DNS Implementation

Frequently asked questions from the previous class survey

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

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

Coordination and Agreement

Synchronization. Distributed Systems IT332

Coordination and Agreement

Distributed Synchronization. EECS 591 Farnam Jahanian University of Michigan

Lecture 10: Clocks and Time

Lecture 12: Time Distributed Systems

Distributed Systems Principles and Paradigms

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

Lecture 6: Logical Time

Process groups and message ordering

Distributed Systems (5DV147)

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

CSE 124: TIME SYNCHRONIZATION, CRISTIAN S ALGORITHM, BERKELEY ALGORITHM, NTP. George Porter October 27, 2017

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

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

Distributed Operating Systems. Distributed Synchronization

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

Event Ordering. Greg Bilodeau CS 5204 November 3, 2009

Basic vs. Reliable Multicast

DISTRIBUTED COMPUTER SYSTEMS

DISTRIBUTED MUTEX. EE324 Lecture 11

Consistency & Replication in Distributed Systems

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

Proseminar Distributed Systems Summer Semester Paxos algorithm. Stefan Resmerita

Consistency & Replication

Module 7 - Replication

Three Models. 1. Time Order 2. Distributed Algorithms 3. Nature of Distributed Systems1. DEPT. OF Comp Sc. and Engg., IIT Delhi

Distributed Clock Synchronization Algorithms: A Survey

TIME AND SYNCHRONIZATION. I. Physical Clock Synchronization: Motivation and Challenges

Replication and Consistency

DISTRIBUTED REAL-TIME SYSTEMS


Data-Centric Consistency Models. The general organization of a logical data store, physically distributed and replicated across multiple processes.

Distributed Systems. Clock Synchronization: Physical Clocks. Paul Krzyzanowski

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

Distributed Systems Synchronization

Consistency in Distributed Systems

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

CSE 380 Computer Operating Systems

Distributed Algorithms Reliable Broadcast

MYE017 Distributed Systems. Kostas Magoutis

Last Class: Clock Synchronization. Today: More Canonical Problems

Distributed Systems. Lec 12: Consistency Models Sequential, Causal, and Eventual Consistency. Slide acks: Jinyang Li

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

CSE 486/586 Distributed Systems Reliable Multicast --- 1

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

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

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

Time and distributed systems. Just use time stamps? Correct consistency model? Replication and Consistency

How Bitcoin achieves Decentralization. How Bitcoin achieves Decentralization

System Models 2. Lecture - System Models 2 1. Areas for Discussion. Introduction. Introduction. System Models. The Modelling Process - General

Consistency and Replication. Why replicate?

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

Consistency and Replication. Why replicate?

CSE 5306 Distributed Systems. Consistency and Replication

2017 Paul Krzyzanowski 1

Coordination and Agreement

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

Availability versus consistency. Eventual Consistency: Bayou. Eventual consistency. Bayou: A Weakly Connected Replicated Storage System

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

Clock and ordering. Yang Wang

Ad hoc and Sensor Networks Time Synchronization

Chapter 7 Consistency And Replication

Process Synchroniztion Mutual Exclusion & Election Algorithms

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

Replication in Distributed Systems

PRIMARY-BACKUP REPLICATION

Transcription:

Time Slides are a variant of slides of a set by Tanenbaum & Van Steen, Distributed Systems: Principles and Paradigms, 2e, (c) 2007 Prentice-Hall, Inc. All rights reserved. 0-13- 239227-5

Time in Distributed Systems Related to notions of replication/consistency is notion of time Simplest defn of DS: set of processes that communicate by msg passing and carrying out desired actions over time Components in DS need some sense of time for synchronizing and/or coordinating tasks specs of DSs include terms like when, before, after, simultaneously

Synchronization Allows processes To share resources (e.g., data or printer) in orderly manner To figure out ordering of events (msg1 from P was sent before msg2 from Q) Outline of lecture Synchronization based on actual time Synchronization where only relative ordering matters

Clock synchronization In centralized system, time is unambiguous Time T1: A asks for time, gets back T1 from kernel At time T2>T1, B asks for time, gets back T2 T2 returned to B will always be >= T1 returned to A In a DS, achieving agreement on time is NOT trivial Example of why clock syncing is important: running make on multiple machines

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

Possible to synchronize all clocks in a DS? It s surprisingly complicated Computers suffer from clock skew (aka drift) In system of n computers, very likely each has different time (even if started out same) UTC (Coordinated Universal Time) Time standard by which world regulates clocks & time Based on the use of cesium 133 atomic clocks Shortwave radio stations in several countries broadcast short pulse at start of a UTC second to receivers that need precise time

Clock Synchronization Algorithms Goal one machine is the timekeeper, try to keep the others synchronized to it, OR each machine tracks its own time, try to keep all machines together Model Each machine has timer that causes interrupt H times/sec On interrupt, add 1 to a software clock that tracks number of ticks, C, since some agreed-upon value in the past Ideally, when UTC=t, C = t

Clock Synchronization Algorithms The relation between clock time and UTC when clocks tick at different rates. Tanenbaum & Van Steen, Distributed Systems: Principles and Paradigms, 2e, (c) 2007 Prentice-Hall, Inc. All rights reserved. 0-13-239227-5

Network Time Protocol If B is the time server, A can calculate its offset relative to B as: Offset O = (T2-T1) + (T4 T3) T3 + ------------------------- - T4 2

Network Time Protocol Protocol runs pair-wise between servers, each computes offset o relative to the other and an estimate of propagation delay d Eight (o, d) pairs computed, minimum value of d taken along with associated offset value Servers organized into strata Stratum-1 servers have atomic clocks/receivers A adjusts its time to B only if A in higher stratum-level than B

The Berkeley Algorithm (1) (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.

Clock Synchronization in Wireless Networks (a) The usual critical path in determining network delays. (b) The critical path in the case of RBS.

Lamport s algorithm (1978) Synchronization need not be based on time (real or virtual) For make, what counts is whether input.c is older or newer than input.o, not their absolute creation times Often apps need only agree on the order in which events occur Lamport s algorithm synchronizes logical clocks

Lamport s Logical Clocks (1) 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.

Lamport s Logical Clocks (2) Happens-before is transitive If events x and y happen in different processes that do not exchange messages (not even indirectly via third parties), then x -> y NOT true X and y are concurrent Nothing can be said (or need be said) about when the events happened or which one happened first

Lamport s Logical Clocks (3) For every event a, we can assign it a time value C(a) on which all processes agree. such that: If a->b then C(a) < C(b) Clock time C must always go forward, never decrease Lamport s algorithm assigns logical times to events while respecting these properties

Lamport s Logical Clocks (4) (a) Three processes, each with its own clock. The clocks run at different rates. (b) Lamport s algorithm corrects the clocks.

Lamport s Logical Clocks (5) The positioning of Lamport s logical clocks in distributed systems.

Lamport s Logical Clocks (6) Each process P i maintains a local counter C i 1. Before executing an event (e.g.,send msg over net, deliver msg to app, or some internal 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 executing step 1. 3. Upon the receipt of a message m, process P j adjusts its own local counter as C j max{c j, ts (m)}, then executes step 1, and delivers the message to the application.

Lamport s Logical Clocks (7) We can attach the number of the process in which the event occurs to the event s timestamp E.g., event at time 40 at P i is timestamped with 40.i When we assign C(a) = C i (a), if a happened at process P i at time C i (a), we get a distributed implementation of the global time value of all events

Example: Totally Ordered Multicasting Updating a replicated database and leaving it in an inconsistent state. Bank example: add $100 to account in SF copy while increasing with 1% interest the amount in NY copy Need totally-ordered multicast

Totally-ordered multicast Goal: all msgs delivered in same order to each receiver. Lamport s clocks can be used to implement totally-ordered multicast in a distributed fashion. When process receives msg, puts in local queue, ordered according to timestamp Receiver multicasts ack to other processes (ack has higher timestamp than msg) Eventually all processes will have the same copy of the local queue (provided no msgs are removed) A process delivers a queued msg to app only when msg at head of queue and ack d by all others Thus, all msgs delivered in same order everywhere Aka state machine replication

With Lamport s Clocks All events in a DS are totally ordered with property that If a happened before b, then a will be positioned in that ordering before b (i.e., C(a) < C(b)) However, converse not necessarily true If C(a) < C(b), does not necessarily mean that a indeed happened before b So can t simply compare time values to determine if a happened before b

Vector Clocks (1) Concurrent message transmission using logical clocks. Note: Lamport s clocks do not capture causality. Sending m3 might depend on what was received through m1 BUT, sending of m2 (by P3) has nothing to do with receipt of m1, so even though T rcv (m1) < T snd (m2), can t be sure that m1 was indeed received before m2 was sent

Vector Clocks (2) Causality can be captured by vector clocks 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 [z] = k then P i knows that k events have occurred at P z. It is thus P i s knowledge of the local time at P z. Property 1 attained by incrementing VC i [i] at every new event at process P i.

Vector Clocks (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 z, it sets m s (vector) timestamp ts(m) equal to VC i after having executed the previous step. 3. Upon receipt of a message m, process P z adjusts its own vector by setting for each k, VC z [k] max{vc z [k], ts(m)[k]}, after which it executes the first step and delivers the message to the application.

Vector Clocks (4) If event a has ts(a), then ts(a)[i]-1 = # events processed at P i that causally precede a When P z receives msg from P i with ts(m), it knows # events that have occurred at P i that causally preceded the sending of m AND #events at other processes that took place before P i sent msg m Hence, ts(m) tells P z the # events in other processes that preceded the sending of m and on which m may causally depend

Enforcing causal communication With vector clocks, we can ensure that a msg is delivered only if all messages that causally precede it have also been received Assumptions messages are multicast within a group of processes Clocks are adjusted only when sending/receiving messages Causally-ordered multicasting is weaker than totallyordered multicasting If 2 msgs unrelated, we do not care about the order they are delivered to apps

Enforcing causal communication Suppose P z receives m from P i with (vector) timestamp ts(m) Delivery of message m to the application is delayed until following conditions are met: ts(m)[i] = VC z [i] + 1 [i.e., m is the next message that P z was expecting from process P i ] for all k!= i, ts(m)[k] <= VC z [k] [i.e., P z has seen all the messages that have been seen by P i when it sent message m]

Enforcing Causal Communication Figure 6-13. Enforcing causal communication. 1. At local time (1,0,0) P0 sends m to P1 and P2. 2. After receipt of m, P1 decides to send m* which arrives at P2 before m does. 3. Delivery of m* to app delayed by P2 until m is received and delivered to app.

CATOCS controversy CATOCS toolkits available Should support for causally and totally ordered multicasting be supported in the middleware or should apps handle order? Middleware cannot tell what a message contains, so only potential causality is captured overly restrictive Middleware cannot catch all causality Electronic bulletin board example Bob posts response to Alice s article after having heard over phone about it from Alice Again, some argue application knows best (E2E)