CSE 486/586 Distributed Systems Logical Time

Slides:



Advertisements
Similar presentations
COS 461 Fall 1997 Time and Clocks u uses of time in distributed systems: –time-based algorithms (e.g. in security) –distributed make –gathering event traces.
Advertisements

CSE 486/586, Spring 2012 CSE 486/586 Distributed Systems Consensus Steve Ko Computer Sciences and Engineering University at Buffalo.
CSE 486/586, Spring 2014 CSE 486/586 Distributed Systems Reliable Multicast Steve Ko Computer Sciences and Engineering University at Buffalo.
CSE 486/586, Spring 2014 CSE 486/586 Distributed Systems Consistency Steve Ko Computer Sciences and Engineering University at Buffalo.
Time and synchronization (“There’s never enough time…”)
CSE 486/586, Spring 2013 CSE 486/586 Distributed Systems Time and Synchronization Steve Ko Computer Sciences and Engineering University at Buffalo.
Computer Science 425 Distributed Systems CS 425 / CSE 424 / ECE 428 Fall 2011 August 30, 2011 Lecture 3 Time and Synchronization Reading: Sections
CSE 486/586, Spring 2013 CSE 486/586 Distributed Systems Consistency Steve Ko Computer Sciences and Engineering University at Buffalo.
Distributed Systems Spring 2009
CSE 486/586, Spring 2012 CSE 486/586 Distributed Systems Time and Synchronization Steve Ko Computer Sciences and Engineering University at Buffalo.
Centralized Architectures
Lecture 13 Synchronization (cont). EECE 411: Design of Distributed Software Applications Logistics Last quiz Max: 69 / Median: 52 / Min: 24 In a box outside.
CSE 486/586, Spring 2012 CSE 486/586 Distributed Systems Logical Time Steve Ko Computer Sciences and Engineering University at Buffalo.
EEC-681/781 Distributed Computing Systems Lecture 10 Wenbing Zhao Cleveland State University.
Lecture 12 Synchronization. EECE 411: Design of Distributed Software Applications Summary so far … A distributed system is: a collection of independent.
Computer Science Lecture 10, page 1 CS677: Distributed OS Last Class: Clock Synchronization Physical clocks Clock synchronization algorithms –Cristian’s.
Distributed Systems Foundations Lecture 1. Main Characteristics of Distributed Systems Independent processors, sites, processes Message passing No shared.
Lecture 2-1 CS 425/ECE 428 Distributed Systems Lecture 2 Time & Synchronization Reading: Klara Nahrstedt.
Lecture 3-1 Computer Science 425 Distributed Systems Lecture 3 Logical Clock and Global States/ Snapshots Reading: Chapter 11.4&11.5 Klara Nahrstedt.
CSE 486/586, Spring 2013 CSE 486/586 Distributed Systems Logical Time Steve Ko Computer Sciences and Engineering University at Buffalo.
1 Causal Delivery Advanced Networks PhD. Saúl Pomares Hernández.
Synchronization. Why we need synchronization? It is important that multiple processes do not access shared resources simultaneously. Synchronization in.
CSE 486/586 CSE 486/586 Distributed Systems Logical Time Steve Ko Computer Sciences and Engineering University at Buffalo.
CSE 486/586, Spring 2013 CSE 486/586 Distributed Systems Global States Steve Ko Computer Sciences and Engineering University at Buffalo.
Synchronization Distributed System. Why synchronization? Two sharpshooters in a multiplayer online game kill the same target. Which one gets the points?
Time This powerpoint presentation has been adapted from: 1) sApr20.ppt.
Lecture 5-1 Computer Science 425 Distributed Systems CS 425 / ECE 428 Fall 2013 Indranil Gupta (Indy) September 10, 2013 Lecture 5 Time and Synchronization.
CSE 486/586, Spring 2014 CSE 486/586 Distributed Systems Consistency Steve Ko Computer Sciences and Engineering University at Buffalo.
Feb 15, 2001CSCI {4,6}900: Ubiquitous Computing1 Announcements.
Logical Clocks. Topics r Logical clocks r Totally-Ordered Multicasting.
Event Ordering. CS 5204 – Operating Systems2 Time and Ordering The two critical differences between centralized and distributed systems are: absence of.
Ordering of Events in Distributed Systems UNIVERSITY of WISCONSIN-MADISON Computer Sciences Department CS 739 Distributed Systems Andrea C. Arpaci-Dusseau.
CSE 486/586 CSE 486/586 Distributed Systems Global States Steve Ko Computer Sciences and Engineering University at Buffalo.
CSE 486/586, Spring 2014 CSE 486/586 Distributed Systems Logical Time Steve Ko Computer Sciences and Engineering University at Buffalo.
Indranil Gupta (Indy) Topic: Time and Ordering Lecture A: Introduction and Basics Cloud Computing concepts All slides © IG.
CSE 486/586 CSE 486/586 Distributed Systems Time and Synchronization Steve Ko Computer Sciences and Engineering University at Buffalo.
CSE 486/586, Spring 2013 CSE 486/586 Distributed Systems Consistency Steve Ko Computer Sciences and Engineering University at Buffalo.
Ordering of Events in Distributed Systems UNIVERSITY of WISCONSIN-MADISON Computer Sciences Department CS 739 Distributed Systems Andrea C. Arpaci-Dusseau.
CSE 486/586 Distributed Systems Reliable Multicast --- 1
CSE 486/586 Distributed Systems Leader Election
Distributed Computing
Time and Synchronization
CSE 486/586 Distributed Systems Global States
CSE 486/586 Distributed Systems Time and Synchronization
Time and Synchronization
CSE 486/586 Distributed Systems Logical Time
SYNCHORNIZATION Logical Clocks.
Logical time (Lamport)
湖南大学-信息科学与工程学院-计算机与科学系
Lecture 12: Time and Ordering
湖南大学-信息科学与工程学院-计算机与科学系
CSE 486/586 Distributed Systems Leader Election
Outline Theoretical Foundations
CS 425 / ECE 428  2013, I. Gupta, K. Nahrtstedt, S. Mitra, N. Vaidya, M. T. Harandi, J. Hou.
Chapter 5 (through section 5.4)
Basics of Distributed Systems
CDK: Sections 11.1 – 11.4 TVS: Sections 6.1 – 6.2
Logical time (Lamport)
Logical time (Lamport)
CSE 486/586 Distributed Systems Global States
CSE 486/586 Distributed Systems Consistency --- 2
CSE 486/586 Distributed Systems Reliable Multicast --- 2
CSE 486/586 Distributed Systems Logical Time
CSE 486/586 Distributed Systems Time and Synchronization
Logical time (Lamport)
CSE 542: Operating Systems
CSE 486/586 Distributed Systems Reliable Multicast --- 1
CSE 486/586 Distributed Systems Leader Election
Last Class: Naming Name distribution: use hierarchies DNS
Outline Theoretical Foundations
Presentation transcript:

CSE 486/586 Distributed Systems Logical Time Steve Ko Computer Sciences and Engineering University at Buffalo

Last Time Clock skews do happen Cristian’s algorithm One server Server-side timestamp and one-way delay estimation NTP (Network Time Protocol) Hierarchy of time servers Estimates the actual offset between two clocks Designed for the Internet

Then a Breakthrough… We cannot sync multiple clocks perfectly. Thus, if we want to order events happened at different processes (remember the ticket reservation example?), we cannot rely on physical clocks. Then came logical time. First proposed by Leslie Lamport in the 70’s Based on causality of events Defined relative time, not absolute time Critical observation: time (ordering) only matters if two or more processes interact, i.e., send/receive messages.

Basics: State Machine State: a collection of values of variables Event: an occurrence of an action that changes the state, (i.e., instruction, send, and receive) As a program, We can think of all possible execution paths. At runtime, There’s only one path that the program takes. Equally applicable to A single process A distributed set of processes S0 S1 S2 S3 S4 SF

Ordering Basics Why did we want to synchronize physical clocks? What we need: Ordering of events. Arises in many different contexts…

Abstract View Above is what we will deal with most of the time. Ordering question: what do we ultimately want? Taking two events and determine which one happened before the other one. Physical time

What Ordering? Ideal? Reliably? Perfect physical clock synchronization Events in the same process Send/receive events Physical time Must explain that reliably we can determine the two types of ordering

Lamport Timestamps Physical time

Logical Clocks Lamport algorithm assigns logical timestamps: All processes use a counter (clock) with initial value of zero A process increments its counter when a send or an instruction happens at it. The counter is assigned to the event as its timestamp. A send (message) event carries its timestamp For a receive (message) event the counter is updated by max(local clock, message timestamp) + 1 Define a logical relation happened-before () among events: On the same process: a  b, if time(a) < time(b) If p1 sends m to p2: send(m)  receive(m) (Transitivity) If a  b and b  c then a  c Shows causality of events

CSE 486/586 Administrivia PA2 is out. Two points: Multicast: Just create 5 connections (5 sockets) and send a message 5 times through different connections. ContentProvider: Don’t call it directly. Don’t share anything with the main activity. Consider it an almost separate app only accessible via ContentResolver. Please pay attention to your coding style. Please participate in our survey (not related to class, but still :-) http://goo.gl/forms/nwFgf3niFW We’re designing a new photo storage/programming framework for mobile devices.

Find the Mistake: Lamport Logical Time Physical Time p 1 1 2 4 3 1 4 p 2 3 2 2 3 6 p 3 4 3 5 6 8 4 7 p 4 5 6 7 n Clock Value timestamp Message

Corrected Example: Lamport Logical Time Physical Time p 1 1 2 8 7 1 8 p 2 3 2 2 3 6 p 3 4 3 5 9 10 4 7 p 4 5 6 7 n Clock Value timestamp Message

One Issue p 1 p 2 p 3 p 4 Physical Time Clock Value 8 7 1 8 p 2 3 2 2 3 and 7 are logically concurrent events 3 6 p 3 4 3 5 9 10 4 7 p 4 5 6 7 n Clock Value timestamp Message

Vector Timestamps With Lamport clock Idea? X e “happened-before” f  timestamp(e) < timestamp (f), but timestamp(e) < timestamp (f)  e “happened-before” f Idea? Each process keeps a separate clock & pass them around. Each process learns about what happened in all others. X Physical time

Vector Logical Clocks Vector Logical time addresses the issue: All processes use a vector of counters (logical clocks), ith element is the clock value for process i, initially all zero. Each process i increments the ith element of its vector upon an instruction or send event. Vector value is timestamp of the event. A send(message) event carries its vector timestamp (counter vector) For a receive(message) event, Vreceiver[j] = Max(Vreceiver[j] , Vmessage[j]), if j is not self, Vreceiver[j] + 1, otherwise Key point You update your own clock. For all other clocks, rely on what other processes tell you and get the most up-to-date values.

Find a Mistake: Vector Logical Time Physical Time (1,0,0,0) 1,0,0,0 1,1,0,0 2,0,0,0 2,0,1,0 (2,0,0,0) 4,0,2,2 4,2,4,2 (4,0,2,2) p 1 0,0,0,0 2,0,2,2 3,0,2,2 (2,0,2,2) p 2 1,2,0,0 2,2,3,0 (1,2,0,0) 0,0,0,0 p 3 2,0,2,0 2,0,2,1 (2,0,2,0) 0,0,0,0 2,0,2,3 4,2,5,3 (2,0,2,3) p 4 0,0,0,0 n,m,p,q Vector logical clock (vector timestamp) Message

Comparing Vector Timestamps VT1 = VT2, iff VT1[i] = VT2[i], for all i = 1, … , n VT1 <= VT2, iff VT1[i] <= VT2[i], for all i = 1, … , n VT1 < VT2, iff VT1 <= VT2 &  j (1 <= j <= n & VT1[j] < VT2 [j]) VT1 is concurrent with VT2 iff (not VT1 <= VT2 AND not VT2 <= VT1)

The Use of Logical Clocks Is a design decision NTP error bound Local: a few ms Wide-area: 10’s of ms If your system doesn’t care about this inaccuracy, then NTP should be fine. Logical clocks impose an arbitrary order over concurrent events anyway Breaking ties: process IDs, etc.

Summary Relative order of events enough for practical purposes Lamport’s logical clocks Vector clocks Next: How to take a global snapshot

Acknowledgements These slides contain material developed and copyrighted by Indranil Gupta at UIUC.