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

Similar documents
Time Synchronization and Logical Clocks

Time Synchronization and Logical Clocks

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

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

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

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

Time in Distributed Systems

Distributed Systems COMP 212. Lecture 17 Othon Michail

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

Clock-Synchronisation

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

Distributed Coordination 1/39

Chapter 6 Synchronization (1)

Lecture 10: Clocks and Time

Distributed Systems. Clock Synchronization: Physical Clocks. Paul Krzyzanowski

CSE 5306 Distributed Systems

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

Lecture 12: Time Distributed Systems

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

殷亚凤. Synchronization. Distributed Systems [6]

PRIMARY-BACKUP REPLICATION

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

Chapter 6 Synchronization

EECS 498 Introduction to Distributed Systems

Synchronization. Distributed Systems IT332

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

Synchronization. Clock Synchronization

CSE 5306 Distributed Systems. Synchronization

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

Last Class: Naming. DNS Implementation

Verteilte Systeme (Distributed Systems)

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

Time in Distributed Systems

Lecture 7: Logical Time

TWO-PHASE COMMIT ATTRIBUTION 5/11/2018. George Porter May 9 and 11, 2018

ICT 6544 Distributed Systems Lecture 7

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

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

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

Primary/Backup. CS6450: Distributed Systems Lecture 3/4. Ryan Stutsman

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

2017 Paul Krzyzanowski 1


INTERNATIONAL JOURNAL OF ENGINEERING SCIENCES & RESEARCH TECHNOLOGY

REPLICATED STATE MACHINES

CSE 124: REPLICATED STATE MACHINES. George Porter November 8 and 10, 2017

DISTRIBUTED REAL-TIME SYSTEMS

Causal Consistency and Two-Phase Commit

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

Multi-threaded programming in Java

Synchronization. Chapter 5

CONTENT-DISTRIBUTION NETWORKS

DISTRIBUTED MUTEX. EE324 Lecture 11

CSE 124: CONTENT-DISTRIBUTION NETWORKS. George Porter December 4, 2017

Middleware and Distributed Systems. Time. Martin v. Löwis. Mittwoch, 22. Februar 12

Proseminar Distributed Systems Summer Semester Paxos algorithm. Stefan Resmerita

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

Distributed Systems. Time, clocks, and Ordering of events. Rik Sarkar. University of Edinburgh Fall 2014

Distributed Systems Fault Tolerance

Frequently asked questions from the previous class survey

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

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

Distributed Operating Systems. Distributed Synchronization

Distributed Systems Principles and Paradigms. Chapter 08: Fault Tolerance

Primary-Backup Replication

CS6450: Distributed Systems Lecture 11. Ryan Stutsman

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

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

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

Implementing NTPv4 in IPv6

CS6450: Distributed Systems Lecture 13. Ryan Stutsman

Process groups and message ordering

CSE 124: QUANTIFYING PERFORMANCE AT SCALE AND COURSE REVIEW. George Porter December 6, 2017

Wireless Communication Bluetooth, Timing

Distributed Systems Principles and Paradigms

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

Wireless Sensor Networks: Clustering, Routing, Localization, Time Synchronization

Byzantine Fault Tolerance

SWITCHING, FORWARDING, AND ROUTING

Chapter 8 Fault Tolerance

Causal Consistency. CS 240: Computing Systems and Concurrency Lecture 16. Marco Canini

Distributed Systems COMP 212. Revision 2 Othon Michail

Implementing NTP. Support was added for IPv6 addresses, VRFs, multicast-based associations, and burst and iburst modes for poll-based associations.

Lecture 6: Logical Time

Data Replication CS 188 Distributed Systems February 3, 2015

PEER-TO-PEER NETWORKS, DHTS, AND CHORD

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

THE DATACENTER AS A COMPUTER AND COURSE REVIEW

Last Class: Clock Synchronization. Today: More Canonical Problems

Distributed Systems. 09. State Machine Replication & Virtual Synchrony. Paul Krzyzanowski. Rutgers University. Fall Paul Krzyzanowski

Distributed Systems Principles and Paradigms

SETTING UP AN NTP SERVER AT THE ROYAL OBSERVATORY OF BELGIUM

Introduction to Distributed Systems

Beyond TrueTime: Using AugmentedTime for Improving Spanner

Implementing NTP. Release 3.8.0

TAIL LATENCY AND PERFORMANCE AT SCALE

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

CSE 5306 Distributed Systems. Consistency and Replication

Distributed Systems. coordination Johan Montelius ID2201. Distributed Systems ID2201

CSE 124: TAIL LATENCY AND PERFORMANCE AT SCALE. George Porter November 27, 2017

Transcription:

TIME George Porter Nov 6 and 8, 2018 ATTRIBUTION These slides are released under an Attribution-NonCommercial-ShareAlike 3.0 Unported (CC BY-NC-SA 3.0) Creative Commons license These slides incorporate material from: Kyle Jamieson, Princeton University (also under a CC BY-NC-SA 3.0 Creative Commons license) 1

ANNOUNCEMENTS Reading: van Steen 6.1 through 6.4 Outline 1. Time synchronization Cristian s algorithm Berkeley algorithm NTP 2. Lamport clocks 3. Vector clocks 2

A DISTRIBUTED EDIT-COMPILE WORKFLOW Physical time 2143 < 2144 make doesn t call compiler Lack of time synchronization result a possible object file mismatch WHAT MAKES TIME SYNCHRONIZATION HARD? 1. Quartz oscillator sensitive to temperature, age, vibration, radiation Accuracy one part per million (one second of clock drift over 12 days) 2. The internet is: Asynchronous: arbitrary message delays Best-effort: messages don t always arrive 3

JUST USE COORDINATED UNIVERSAL TIME? UTC is broadcast from radio stations on land and satellite (e.g., the Global Positioning System) Computers with receivers can synchronize their clocks with these timing signals Signals from land-based stations are accurate to about 0.1 10 milliseconds Signals from GPS are accurate to about one microsecond Why can t we put GPS receivers on all our computers? Outline 1. Time synchronization Cristian s algorithm Berkeley algorithm NTP 2. Lamport clocks 3. Vector clocks 4

SYNCHRONIZATION TO A TIME SERVER Suppose a server with an accurate clock (e.g., GPSdisciplined crystal oscillator) Could simply issue an RPC to obtain the time: Client Server Time But this doesn t account for network latency Message delays will have outdated server s answer CRISTIAN S ALGORITHM: OUTLINE 1. Client sends a request packet, timestamped with its local clock T 1 Client Server 2. Server timestamps its receipt of the request T 2 with its local clock 3. Server sends a response packet with its local clock T 3 and T 2 4. Client locally timestamps its receipt of the server s response T 4 How the client can use these timestamps to synchronize its local clock to the server s local clock? T 1 T 4 T 2 T 3 Time 5

CRISTIAN S ALGORITHM: OFFSET SAMPLE CALCULATION Client Server Goal: Client sets clock T 3 + δ resp Client samples round trip time δ = δ req + δ resp = (T 4 T 1 ) (T 3 T 2 ) But client knows δ, not δ resp T 1 δ req T 2 Assume: δ req δ resp δ resp T 4 T 3 Client sets clock T 3 + ½δ Time Outline 1. Time synchronization Cristian s algorithm Berkeley algorithm NTP 2. Lamport clocks 3. Vector clocks 6

BERKELEY ALGORITHM A single time server can fail, blocking timekeeping The Berkeley algorithm is a distributed algorithm for timekeeping Assumes all machines have equally-accurate local clocks Obtains average from participating computers and synchronizes clocks to that average BERKELEY ALGORITHM Master machine: polls L other machines using Cristian s algorithm { θ i } (i = 1 L) Master 7

Outline 1. Time synchronization Cristian s algorithm Berkeley algorithm NTP 2. Lamport clocks 3. Vector clocks THE NETWORK TIME PROTOCOL (NTP) Enables clients to be accurately synchronized to UTC despite message delays Provides reliable service Survives lengthy losses of connectivity Communicates over redundant network paths Provides an accurate service Unlike the Berkeley algorithm, leverages heterogeneous accuracy in clocks 8

NTP: SYSTEM STRUCTURE Servers and time sources are arranged in layers (strata) Stratum 0: High-precision time sources themselves e.g., atomic clocks, shortwave radio time receivers Stratum 1: NTP servers directly connected to Stratum 0 Stratum 2: NTP servers that synchronize with Stratum 1 Stratum 2 servers are clients of Stratum 1 servers Stratum 3: NTP servers that synchronize with Stratum 2 Stratum 3 servers are clients of Stratum 2 servers Users computers synchronize with Stratum 3 servers NTP OPERATION: SERVER SELECTION Messages between an NTP client and server are exchanged in pairs: request and response Use Cristian s algorithm For i th message exchange with a particular server, calculate: 1. Clock offset θ i from client to server 2. Round trip time δ i between client and server Over last eight exchanges with server k, the client computes its dispersion σ k = max i δ i min i δ i Client uses the server with minimum dispersion Outliers are discarded 9

NTP OPERATION : CLOCK OFFSET CALCULATION Client tracks minimum round trip time and associated offset over the last eight message exchanges (δ 0, θ 0 ) θ 0 is the best estimate of offset: client adjusts its clock by θ 0 to synchronize to server Offset θ θ 0 Each point represents one sample δ 0 Round trip time δ NTP OPERATION: HOW TO CHANGE TIME Can t just change time: Don t want time to run backwards Recall the make example Instead, change the update rate for the clock Changes time in a more gradual fashion Prevents inconsistent local timestamps 10

CLOCK SYNCHRONIZATION: TAKE-AWAY POINTS Clocks on different systems will always behave differently Disagreement between machines can result in undesirable behavior NTP, Berkeley clock synchronization Rely on timestamps to estimate network delays 100s μs ms accuracy Clocks never exactly synchronized Often inadequate for distributed systems Often need to reason about the order of events Might need precision on the order of ns Images used with permission Outline 1. Time synchronization Cristian s algorithm Berkeley algorithm NTP 2. Lamport clocks 3. Vector clocks 11

MOTIVATION: MULTI-SITE DATABASE REPLICATION A New York-based bank wants to make its transaction ledger database resilient to whole-site failures Replicate the database, keep one copy in sf, one in nyc San Francisco New York MOTIVATION: MULTI-SITE DATABASE REPLICATION Replicate the database, keep one copy in sf, one in nyc Client sends query to the nearest copy Client sends update to both copies Deposit $100 $1,000 $1,100 $1,111 Inconsistent replicas! Updates should have been performed in the same order at each copy Pay 1% interest $1,000 $1,010 $1,110 12

IDEA: LOGICAL CLOCKS Landmark 1978 paper by Leslie Lamport Insight: only the events themselves matter Idea: Disregard the precise clock time Instead, capture just a happens before relationship between a pair of events DEFINING HAPPENS-BEFORE Consider three processes:,, and P3 Notation: Event a happens before event b (a b) P3 Physical time 13

DEFINING HAPPENS-BEFORE 1. Can observe event order at a single process a P3 b Physical time DEFINING HAPPENS-BEFORE 1. If same process and a occurs before b, then a b a P3 b Physical time 14

DEFINING HAPPENS-BEFORE 1. If same process and a occurs before b, then a b 2. Can observe ordering when processes communicate a P3 b c Physical time DEFINING HAPPENS-BEFORE 1. If same process and a occurs before b, then a b 2. If c is a message receipt of b, then b c a P3 b c Physical time 15

DEFINING HAPPENS-BEFORE 1. If same process and a occurs before b, then a b 2. If c is a message receipt of b, then b c 3. Can observe ordering transitively a P3 b c Physical time TRANSITIVE HAPPENS-BEFORE 1. If same process and a occurs before b, then a b 2. If c is a message receipt of b, then b c 3. If a b and b c, then a c a P3 b c Physical time 16

CONCURRENT EVENTS We seek a clock time C(a) for every event a Plan: Tag events with clock times; use clock times to make distributed system correct Clock condition: If a b, then C(a) < C(b) THE LAMPORT CLOCK ALGORITHM Each process P i maintains a local clock C i 1. Before executing an event, C i C i + 1 a C 1 =0 C 2 =0 P3 C 3 =0 b c Physical time 17

THE LAMPORT CLOCK ALGORITHM 1. Before executing an event a, C i C i + 1: Set event time C(a) C i a C 1 =1 C(a) = 1 C 2 =1 P3 C 3 =1 b c Physical time THE LAMPORT CLOCK ALGORITHM 1. Before executing an event b, C i C i + 1: Set event time C(b) C i a b C 1 =2 C(a) = 1 C(b) = 2 C 2 =1 c P3 C 3 =1 Physical time 18

THE LAMPORT CLOCK ALGORITHM 1. Before executing an event b, C i C i + 1 2. Send the local clock in the message m a b C 1 =2 C(a) = 1 C(b) = 2 C(m) = 2 C 2 =1 c P3 C 3 =1 Physical time THE LAMPORT CLOCK ALGORITHM 3. On process P j receiving a message m: Set C j and receive event time C(c) 1 + max{ C j, C(m) } a b C 1 =2 C(a) = 1 C(b) = 2 C(m) = 2 C 2 =3 C(c) = 3 c P3 C 3 =1 Physical time 19

ORDERING ALL EVENTS Break ties by appendingthe process number to each event: 1. Process P i timestamps event e with C i (e).i 2. C(a).i < C(b).j when: C(a) < C(b), or C(a) = C(b) and i < j Now, for any two events a and b, C(a) < C(b) or C(b) < C(a) This is called a total ordering of events MAKING CONCURRENT UPDATES CONSISTENT Recall multi-site database replication: San Francisco () deposited $100: $ New York () paid 1% interest: % We reached an inconsistent state Could we design a system that uses Lamport Clock total order to make multi-site updates consistent? 20

TOTALLY-ORDERED MULTICAST Client sends update to one replica Lamporttimestamp C(x) Key idea: Place events into a local queue Sortedby increasing C(x) s local queue: $ 1.1 % 1.2 s local queue: % 1.2 Goal: All sites apply the updates in (the same) Lamport clock order TOTALLY-ORDERED MULTICAST (ALMOST CORRECT) 1. On receiving an event from client, broadcast to others (including yourself) 1. On receiving an event from replica: a) Add it to your local queue b) Broadcast an acknowledgement message to every process (including yourself) 2. On receiving an acknowledgement: Mark corresponding event acknowledgedin your queue 3. Remove and process events everyone has ack ed from head of queue 21

TOTALLY-ORDERED MULTICAST (ALMOST CORRECT) queues $, queues % $ 1.1 % 1.2 % $ 1.1 1.2 queues and ack s % marks % fully ack ed $ 1.1 % 1.2 marks % fully ack ed ack % % processes % (Ack sto self not shown here) TOTALLY-ORDERED MULTICAST (CORRECT VERSION) 1. On receiving an event from client, broadcast to others (including yourself) 2. On receiving or processing an event: a) Add it to your local queue b) Broadcast an acknowledgement message to every process (including yourself) only from head of queue 3. When you receive an acknowledgement: Mark corresponding event acknowledgedin your queue 4. Remove and process events everyone has ack ed from head of queue 22

TOTALLY-ORDERED MULTICAST (CORRECT VERSION) $ 1.1 % 1.2 % $ 1.1 1.2 $ 1.1 % 1.2 $ % ack $ ack % (Ack sto self not shown here) $ % SO, ARE WE DONE? Does totally-ordered multicast solve the problem of multisite replication in general? Not by a long shot! 1. Our protocol assumed: No node failures No message loss No message corruption 2. All to all communication does not scale 3. Waits forever for message delays (performance?) 23

TAKE-AWAY POINTS: LAMPORT CLOCKS Can totally-order events in a distributed system: that s useful! But: while by construction, a b implies C(a) < C(b), The converse is not necessarily true: C(a) < C(b) does not imply a b (possibly, a b) Can t use Lamport clock timestamps to infer causal relationships between events Outline 1. Time synchronization Cristian s algorithm Berkeley algorithm NTP 2. Lamport clocks 3. Vector clocks 24

VECTOR CLOCK (VC) Label each event e with a vector V(e) = [c 1, c 2, c n ] c i is a count of events in process ithat causally precede e Initially, all vectors are [0, 0,, 0] Two update rules: 1. For each local event on process i, increment local entry c i 2. If process j receives message with vector [d 1, d 2,, d n ]: Set each local entry c k = max{c k, d k } Increment local entry c j VECTOR CLOCK: EXAMPLE All counters start at [0, 0, 0] Applying local update rule P3 Applying message rule Local vector clock piggybacks on inter-process messages a b [1,0,0] [2,0,0] c d e [2,1,0] [2,2,0] f [0,0,1] [2,2,2] [2,2,2]: Remember we have event e at P3 with timestamp [0,0,1]. D s message gets timestamp [2,2,0], we take max to get [2,2,1] then increment the local entry to get [2,2,2]. Physical time 25

VECTOR CLOCKS CAN ESTABLISH CAUSALITY Rule for comparing vector clocks: V(a) = V(b) when a k = b k for all k V(a) < V(b) when a k b k for all k and V(a) V(b) a b [1,0,0] [2,0,0] c z [2,1,0] [2,2,0] Concurrency: a b if a i < b i and a j > b j, some i, j V(a) < V(z) when there is a chain of events linked by between a and z Two events a, z Lamport clocks: C(a) < C(z) Conclusion: None Vector clocks: V(a) < V(z) Conclusion: a z Vector clock timestamps tell us about causal event relationships 26

VC APPLICATION: CAUSALLY-ORDERED BULLETIN BOARD SYSTEM Distributed bulletin board application Each post multicast of the post to all other users Want: No user to see a reply before the corresponding original message post Deliver message only after all messages that causally precede it have been delivered Otherwise, the user would see a reply to a message they could not find VC APPLICATION: CAUSALLY-ORDERED BULLETIN BOARD SYSTEM Original post 1 s reply Physical time User 0 posts, user 1 replies to 0 s post; user 2 observes 27

28